public class RestfulServer extends javax.servlet.http.HttpServlet implements IRestfulServer<ServletRequestDetails>
| Modifier and Type | Field and Description |
|---|---|
static ETagSupportEnum |
DEFAULT_ETAG_SUPPORT
Default setting for
ETag Support: ETagSupportEnum.ENABLED |
static String |
SERVLET_CONTEXT_ATTRIBUTE
Requests will have an HttpServletRequest attribute set with this name, containing the servlet
context, in order to avoid a dependency on Servlet-API 3.0+
|
| Constructor and Description |
|---|
RestfulServer()
Constructor.
|
RestfulServer(FhirContext theCtx)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHeadersToResponse(javax.servlet.http.HttpServletResponse theHttpResponse)
This method is called prior to sending a response to incoming requests.
|
RestulfulServerConfiguration |
createConfiguration() |
void |
destroy() |
BaseMethodBinding<?> |
determineResourceMethod(RequestDetails requestDetails,
String requestPath) |
protected void |
doDelete(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
doOptions(javax.servlet.http.HttpServletRequest theReq,
javax.servlet.http.HttpServletResponse theResp) |
protected void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected void |
doPut(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected int |
escapedLength(String theServletPath)
Count length of URL string, but treating unescaped sequences (e.g.
|
AddProfileTagEnum |
getAddProfileTag() |
BundleInclusionRule |
getBundleInclusionRule() |
EncodingEnum |
getDefaultResponseEncoding()
Returns the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the
_format URL parameter, or with an Accept header
in the request. |
ETagSupportEnum |
getETagSupport() |
FhirContext |
getFhirContext()
Gets the
FhirContext associated with this server. |
String |
getImplementationDescription() |
List<IServerInterceptor> |
getInterceptors()
Returns a ist of all registered server interceptors
|
IPagingProvider |
getPagingProvider() |
Collection<Object> |
getPlainProviders()
Provides the non-resource specific providers which implement method calls on this server
|
protected String |
getRequestPath(String requestFullPath,
String servletContextPath,
String servletPath)
Allows users of RestfulServer to override the getRequestPath method to let them build their custom request path implementation
|
Collection<ResourceBinding> |
getResourceBindings() |
Collection<IResourceProvider> |
getResourceProviders()
Provides the resource providers for this server
|
IServerAddressStrategy |
getServerAddressStrategy()
Get the server address strategy, which is used to determine what base URL to provide clients to refer to this server.
|
String |
getServerBaseForRequest(javax.servlet.http.HttpServletRequest theRequest)
Returns the server base URL (with no trailing '/') for a given request
|
List<BaseMethodBinding<?>> |
getServerBindings()
Returns the method bindings for this server which are not specific to any particular resource type.
|
Object |
getServerConformanceProvider()
Returns the server conformance provider, which is the provider that is used to generate the server's conformance (metadata) statement if one has been explicitly defined.
|
String |
getServerName()
Gets the server's name, as exported in conformance profiles exported by the server.
|
IResourceProvider |
getServerProfilesProvider() |
String |
getServerVersion()
Gets the server's version, as exported in conformance profiles exported by the server.
|
protected void |
handleRequest(RequestTypeEnum theRequestType,
javax.servlet.http.HttpServletRequest theRequest,
javax.servlet.http.HttpServletResponse theResponse) |
void |
init()
Initializes the server.
|
protected void |
initialize()
This method may be overridden by subclasses to do perform initialization that needs to be performed prior to the server being used.
|
boolean |
isDefaultPrettyPrint()
Should the server "pretty print" responses by default (requesting clients can always override this default by supplying an
Accept header in the request, or a _pretty
parameter in the request URL. |
boolean |
isUncompressIncomingContents()
Should the server attempt to decompress incoming request contents (default is
true). |
boolean |
isUseBrowserFriendlyContentTypes()
Deprecated.
This feature did not work well, and will be removed. Use
ResponseHighlighterInterceptor instead as an interceptor on your server and it will provide more useful syntax
highlighting. Deprocated in 1.4 |
void |
populateRequestDetailsFromRequestPath(RequestDetails theRequestDetails,
String theRequestPath) |
void |
registerInterceptor(IServerInterceptor theInterceptor) |
void |
registerProvider(Object provider)
Register a single provider.
|
void |
registerProviders(Collection<? extends Object> providers)
Register a group of providers.
|
protected void |
registerProviders(Collection<? extends Object> providers,
boolean inInit) |
static boolean |
requestIsBrowser(javax.servlet.http.HttpServletRequest theRequest) |
Object |
returnResponse(ServletRequestDetails theRequest,
ParseAction<?> outcome,
int operationStatus,
boolean allowPrefer,
MethodOutcome response,
String resourceName) |
void |
setAddProfileTag(AddProfileTagEnum theAddProfileTag)
Sets the profile tagging behaviour for the server.
|
void |
setBundleInclusionRule(BundleInclusionRule theBundleInclusionRule)
Set how bundle factory should decide whether referenced resources should be included in bundles
|
void |
setDefaultPrettyPrint(boolean theDefaultPrettyPrint)
Should the server "pretty print" responses by default (requesting clients can always override this default by supplying an
Accept header in the request, or a _pretty
parameter in the request URL. |
void |
setDefaultResponseEncoding(EncodingEnum theDefaultResponseEncoding)
Sets the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the
_format URL parameter, or with an Accept header in
the request. |
void |
setETagSupport(ETagSupportEnum theETagSupport)
Sets (enables/disables) the server support for ETags.
|
void |
setFhirContext(FhirContext theFhirContext) |
void |
setImplementationDescription(String theImplementationDescription) |
void |
setInterceptors(IServerInterceptor... theList)
Sets (or clears) the list of interceptors
|
void |
setInterceptors(List<IServerInterceptor> theList)
Sets (or clears) the list of interceptors
|
void |
setPagingProvider(IPagingProvider thePagingProvider)
Sets the paging provider to use, or
null to use no paging (which is the default) |
void |
setPlainProviders(Collection<Object> theProviders)
Sets the non-resource specific providers which implement method calls on this server.
|
void |
setPlainProviders(Object... theProv)
Sets the non-resource specific providers which implement method calls on this server.
|
void |
setProviders(Object... theProviders)
Sets the non-resource specific providers which implement method calls on this server
|
void |
setResourceProviders(Collection<IResourceProvider> theResourceProviders)
Sets the resource providers for this server
|
void |
setResourceProviders(IResourceProvider... theResourceProviders)
Sets the resource providers for this server
|
void |
setServerAddressStrategy(IServerAddressStrategy theServerAddressStrategy)
Provide a server address strategy, which is used to determine what base URL to provide clients to refer to this server.
|
void |
setServerConformanceProvider(Object theServerConformanceProvider)
Returns the server conformance provider, which is the provider that is used to generate the server's conformance (metadata) statement.
|
void |
setServerName(String theServerName)
Sets the server's name, as exported in conformance profiles exported by the server.
|
void |
setServerVersion(String theServerVersion)
Gets the server's version, as exported in conformance profiles exported by the server.
|
void |
setUncompressIncomingContents(boolean theUncompressIncomingContents)
Should the server attempt to decompress incoming request contents (default is
true). |
void |
setUseBrowserFriendlyContentTypes(boolean theUseBrowserFriendlyContentTypes)
Deprecated.
This feature did not work well, and will be removed. Use
ResponseHighlighterInterceptor instead as an interceptor on your server and it will provide more useful syntax
highlighting. Deprocated in 1.4 |
void |
unregisterInterceptor(IServerInterceptor theInterceptor) |
void |
unregisterProvider(Object provider)
Unregister one provider (either a Resource provider or a plain provider)
|
void |
unregisterProviders(Collection<? extends Object> providers)
Unregister a
Collection of providers |
doHead, doTrace, getLastModified, service, servicepublic static final String SERVLET_CONTEXT_ATTRIBUTE
public static final ETagSupportEnum DEFAULT_ETAG_SUPPORT
ETag Support: ETagSupportEnum.ENABLEDpublic RestfulServer()
FhirContext is passed in to the server (either through the constructor, or through setFhirContext(FhirContext)) the server will determine which
version of FHIR to support through classpath scanning. This is brittle, and it is highly recommended to explicitly specify a FHIR version.public RestfulServer(FhirContext theCtx)
public void addHeadersToResponse(javax.servlet.http.HttpServletResponse theHttpResponse)
Use caution if overriding this method: it is recommended to call super.addHeadersToResponse to avoid inadvertantly disabling functionality.
public RestulfulServerConfiguration createConfiguration()
public void destroy()
destroy in interface javax.servlet.Servletdestroy in class javax.servlet.GenericServletpublic BaseMethodBinding<?> determineResourceMethod(RequestDetails requestDetails, String requestPath)
protected void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doDelete in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doGet in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected void doOptions(javax.servlet.http.HttpServletRequest theReq, javax.servlet.http.HttpServletResponse theResp) throws javax.servlet.ServletException, IOException
doOptions in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doPost in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doPut in class javax.servlet.http.HttpServletjavax.servlet.ServletExceptionIOExceptionprotected int escapedLength(String theServletPath)
public AddProfileTagEnum getAddProfileTag()
getAddProfileTag in interface IRestfulServerDefaultspublic BundleInclusionRule getBundleInclusionRule()
getBundleInclusionRule in interface IRestfulServer<ServletRequestDetails>public EncodingEnum getDefaultResponseEncoding()
_format URL parameter, or with an Accept header
in the request. The default is EncodingEnum.XML. Will not return null.getDefaultResponseEncoding in interface IRestfulServerDefaults_format URL parameter, or with an Accept header
in the request. The default is EncodingEnum.XML. Will not return null.public ETagSupportEnum getETagSupport()
getETagSupport in interface IRestfulServerDefaultsnull). Default is DEFAULT_ETAG_SUPPORTpublic FhirContext getFhirContext()
FhirContext associated with this server. For efficient processing, resource providers and plain providers should generally use this context if one is needed, as opposed to
creating their own.getFhirContext in interface IRestfulServerDefaultspublic String getImplementationDescription()
public List<IServerInterceptor> getInterceptors()
getInterceptors in interface IRestfulServer<ServletRequestDetails>public IPagingProvider getPagingProvider()
getPagingProvider in interface IRestfulServer<ServletRequestDetails>public Collection<Object> getPlainProviders()
getResourceProviders()protected String getRequestPath(String requestFullPath, String servletContextPath, String servletPath)
requestFullPath - the full request pathservletContextPath - the servelet context pathservletPath - the servelet pathpublic Collection<ResourceBinding> getResourceBindings()
public Collection<IResourceProvider> getResourceProviders()
public IServerAddressStrategy getServerAddressStrategy()
IncomingRequestAddressStrategypublic String getServerBaseForRequest(javax.servlet.http.HttpServletRequest theRequest)
public List<BaseMethodBinding<?>> getServerBindings()
public Object getServerConformanceProvider()
By default, the ServerConformanceProvider for the declared version of FHIR is used, but this can be changed, or set to null to use the appropriate one for the given FHIR version.
public String getServerName()
setServerName(String)public IResourceProvider getServerProfilesProvider()
public String getServerVersion()
protected void handleRequest(RequestTypeEnum theRequestType, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse) throws javax.servlet.ServletException, IOException
javax.servlet.ServletExceptionIOExceptionpublic final void init() throws javax.servlet.ServletException
initialize(), which is
called immediately before beginning initialization of the restful server's internal init.init in class javax.servlet.GenericServletjavax.servlet.ServletExceptionprotected void initialize() throws javax.servlet.ServletException
javax.servlet.ServletException - If the initialization failed. Note that you should consider throwing UnavailableException (which extends ServletException), as this is a flag to the servlet container
that the servlet is not usable.public boolean isDefaultPrettyPrint()
Accept header in the request, or a _pretty
parameter in the request URL.
The default is false
isDefaultPrettyPrint in interface IRestfulServerDefaultspublic boolean isUncompressIncomingContents()
true). Typically this should be set to true unless the server has other configuration to
deal with decompressing request bodies (e.g. a filter applied to the whole server).@Deprecated public boolean isUseBrowserFriendlyContentTypes()
ResponseHighlighterInterceptor instead as an interceptor on your server and it will provide more useful syntax
highlighting. Deprocated in 1.4isUseBrowserFriendlyContentTypes in interface IRestfulServerDefaultstrue the server will use browser friendly content-types (instead of standard FHIR ones) when it detects that the request is coming from a browser
instead of a FHIRpublic void populateRequestDetailsFromRequestPath(RequestDetails theRequestDetails, String theRequestPath)
public void registerInterceptor(IServerInterceptor theInterceptor)
public void registerProvider(Object provider) throws Exception
provider - Exceptionpublic void registerProviders(Collection<? extends Object> providers) throws Exception
providers - a Collection of providers. The parameter could be null or an empty CollectionExceptionprotected void registerProviders(Collection<? extends Object> providers, boolean inInit) throws Exception
Exceptionpublic Object returnResponse(ServletRequestDetails theRequest, ParseAction<?> outcome, int operationStatus, boolean allowPrefer, MethodOutcome response, String resourceName) throws IOException
IOExceptionpublic void setAddProfileTag(AddProfileTagEnum theAddProfileTag)
AddProfileTagEnum.NEVER (which is the default), the server will automatically add a profile tag based on
the class of the resource(s) being returned.theAddProfileTag - The behaviour enum (must not be null)public void setBundleInclusionRule(BundleInclusionRule theBundleInclusionRule)
theBundleInclusionRule - - inclusion rule (@see BundleInclusionRule for behaviors)public void setDefaultPrettyPrint(boolean theDefaultPrettyPrint)
Accept header in the request, or a _pretty
parameter in the request URL.
The default is false
theDefaultPrettyPrint - The default pretty print settingpublic void setDefaultResponseEncoding(EncodingEnum theDefaultResponseEncoding)
_format URL parameter, or with an Accept header in
the request. The default is EncodingEnum.XML.
Note when testing this feature: Some browsers will include "application/xml" in their Accept header, which means that the
public void setETagSupport(ETagSupportEnum theETagSupport)
null. Default is DEFAULT_ETAG_SUPPORTtheETagSupport - The ETag support modepublic void setFhirContext(FhirContext theFhirContext)
public void setImplementationDescription(String theImplementationDescription)
public void setInterceptors(IServerInterceptor... theList)
theList - The list of interceptors (may be null)public void setInterceptors(List<IServerInterceptor> theList)
theList - The list of interceptors (may be null)public void setPagingProvider(IPagingProvider thePagingProvider)
null to use no paging (which is the default)public void setPlainProviders(Collection<Object> theProviders)
setResourceProviders(Collection)public void setPlainProviders(Object... theProv)
setResourceProviders(Collection)public void setProviders(Object... theProviders)
setResourceProviders(Collection)public void setResourceProviders(Collection<IResourceProvider> theResourceProviders)
public void setResourceProviders(IResourceProvider... theResourceProviders)
public void setServerAddressStrategy(IServerAddressStrategy theServerAddressStrategy)
IncomingRequestAddressStrategypublic void setServerConformanceProvider(Object theServerConformanceProvider)
By default, the ServerConformanceProvider implementation for the declared version of FHIR is used, but this can be changed, or set to null if you do not wish to export a conformance
statement.
IllegalStateException - Note that this method can only be called prior to initialization and will throw an IllegalStateException if called after that.public void setServerName(String theServerName)
public void setServerVersion(String theServerVersion)
public void setUncompressIncomingContents(boolean theUncompressIncomingContents)
true). Typically this should be set to true unless the server has other configuration to
deal with decompressing request bodies (e.g. a filter applied to the whole server).@Deprecated public void setUseBrowserFriendlyContentTypes(boolean theUseBrowserFriendlyContentTypes)
ResponseHighlighterInterceptor instead as an interceptor on your server and it will provide more useful syntax
highlighting. Deprocated in 1.4public void unregisterInterceptor(IServerInterceptor theInterceptor)
public void unregisterProvider(Object provider) throws Exception
provider - Exceptionpublic void unregisterProviders(Collection<? extends Object> providers) throws Exception
Collection of providersproviders - Exceptionpublic static boolean requestIsBrowser(javax.servlet.http.HttpServletRequest theRequest)
Copyright © 2014–2016 University Health Network. All rights reserved.