Class RestfulServer
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- ca.uhn.fhir.rest.server.RestfulServer
-
- All Implemented Interfaces:
IRestfulServer<ServletRequestDetails>,IRestfulServerDefaults,Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class RestfulServer extends javax.servlet.http.HttpServlet implements IRestfulServer<ServletRequestDetails>
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ETagSupportEnumDEFAULT_ETAG_SUPPORTDefault setting forETag Support:ETagSupportEnum.ENABLEDstatic ca.uhn.fhir.rest.api.PreferReturnEnumDEFAULT_PREFER_RETURNDefault value forsetDefaultPreferReturn(PreferReturnEnum)static StringREQUEST_START_TIMEAll incoming requests will have an attribute added toServletRequest.getAttribute(String)with this key.static StringSERVLET_CONTEXT_ATTRIBUTERequests 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 Summary
Constructors Constructor Description RestfulServer()Constructor.RestfulServer(ca.uhn.fhir.context.FhirContext theCtx)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddHeadersToResponse(javax.servlet.http.HttpServletResponse theHttpResponse)This method is called prior to sending a response to incoming requests.protected voidaddRequestIdToResponse(ServletRequestDetails theRequestDetails, String theRequestId)RestfulServerConfigurationcreateConfiguration()protected List<String>createPoweredByAttributes()protected StringcreatePoweredByHeader()Subclasses may override to provide their own powered by header.protected StringcreatePoweredByHeaderComponentName()Subclasses my overrideprotected StringcreatePoweredByHeaderProductName()Subclasses my overrideprotected StringcreatePoweredByHeaderProductVersion()Subclasses my overridevoiddestroy()BaseMethodBinding<?>determineResourceMethod(RequestDetails requestDetails, String requestPath)Figure out and return whichever method binding is appropriate for the given requestprotected voiddoDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoOptions(javax.servlet.http.HttpServletRequest theReq, javax.servlet.http.HttpServletResponse theResp)protected voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voiddoPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected static intescapedLength(String theServletPath)Count length of URL string, but treating unescaped sequences (e.g.ca.uhn.fhir.context.api.AddProfileTagEnumgetAddProfileTag()Deprecated.As of HAPI FHIR 1.5, this property has been moved toFhirContext.setAddProfileTagWhenEncoding(AddProfileTagEnum)ca.uhn.fhir.context.api.BundleInclusionRulegetBundleInclusionRule()ca.uhn.fhir.rest.api.PreferReturnEnumgetDefaultPreferReturn()By default, server create/update/patch/transaction methods return a copy of the resource as it was stored.ca.uhn.fhir.rest.api.EncodingEnumgetDefaultResponseEncoding()Returns the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the_formatURL parameter, or with anAcceptheader in the request.ElementsSupportEnumgetElementsSupport()ETagSupportEnumgetETagSupport()ca.uhn.fhir.context.FhirContextgetFhirContext()Gets theFhirContextassociated with this server.StringgetImplementationDescription()List<IServerInterceptor>getInterceptors_()Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service.ca.uhn.fhir.interceptor.api.IInterceptorServicegetInterceptorService()Returns the interceptor registry for this service.protected StringgetOrCreateRequestId(javax.servlet.http.HttpServletRequest theRequest)Reads a requet ID from the request headers via theConstants.HEADER_REQUEST_IDheader, or generates one if none is supplied.IPagingProvidergetPagingProvider()Returns the paging provider for this serverCollection<Object>getPlainProviders()Provides the non-resource specific providers which implement method calls on this serverprotected StringgetRequestPath(String requestFullPath, String servletContextPath, String servletPath)Allows users of RestfulServer to override the getRequestPath method to let them build their custom request path implementationCollection<ResourceBinding>getResourceBindings()Collection<IResourceProvider>getResourceProviders()Provides the resource providers for this serverIServerAddressStrategygetServerAddressStrategy()Get the server address strategy, which is used to determine what base URL to provide clients to refer to this server.StringgetServerBaseForRequest(ServletRequestDetails theRequest)Returns the server base URL (with no trailing '/') for a given requestList<BaseMethodBinding<?>>getServerBindings()Returns the method bindings for this server which are not specific to any particular resource type.ObjectgetServerConformanceProvider()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.StringgetServerName()Gets the server's name, as exported in conformance profiles exported by the server.IResourceProvidergetServerProfilesProvider()StringgetServerVersion()Gets the server's version, as exported in conformance profiles exported by the server.protected voidhandleRequest(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse)voidinit()Initializes the server.protected voidinitialize()This method may be overridden by subclasses to do perform initialization that needs to be performed prior to the server being used.booleanisDefaultPrettyPrint()Should the server "pretty print" responses by default (requesting clients can always override this default by supplying anAcceptheader in the request, or a_prettyparameter in the request URL.booleanisIgnoreServerParsedRequestParameters()If set totrue(the default istrue) this server will not use the parsed request parameters (URL parameters and HTTP POST form contents) but will instead parse these values manually from the request URL and request body.booleanisUncompressIncomingContents()Should the server attempt to decompress incoming request contents (default istrue).protected ServletRequestDetailsnewRequestDetails()Deprecated.Deprecated in HAPI FHIR 4.1.0 - Users wishing to override this method should overridenewRequestDetails(RequestTypeEnum, HttpServletRequest, HttpServletResponse)insteadprotected ServletRequestDetailsnewRequestDetails(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse)Subclasses may override this to customize the way that the RequestDetails object is created.protected StringnewRequestId(int theRequestIdLength)Generate a new request ID string.voidpopulateRequestDetailsFromRequestPath(RequestDetails theRequestDetails, String theRequestPath)voidregisterInterceptor(Object theInterceptor)Registers an interceptor.voidregisterProvider(Object provider)Register a single provider.voidregisterProviders(Object... theProviders)Register a group of providers.voidregisterProviders(Collection<?> theProviders)Register a group of theProviders.protected voidregisterProviders(Collection<?> theProviders, boolean inInit)ObjectreturnResponse(ServletRequestDetails theRequest, ParseAction<?> outcome, int operationStatus, boolean allowPrefer, ca.uhn.fhir.rest.api.MethodOutcome response, String resourceName)protected voidservice(javax.servlet.http.HttpServletRequest theReq, javax.servlet.http.HttpServletResponse theResp)voidsetAddProfileTag(ca.uhn.fhir.context.api.AddProfileTagEnum theAddProfileTag)Deprecated.As of HAPI FHIR 1.5, this property has been moved toFhirContext.setAddProfileTagWhenEncoding(AddProfileTagEnum)voidsetBundleInclusionRule(ca.uhn.fhir.context.api.BundleInclusionRule theBundleInclusionRule)Set how bundle factory should decide whether referenced resources should be included in bundlesvoidsetDefaultPreferReturn(ca.uhn.fhir.rest.api.PreferReturnEnum theDefaultPreferReturn)By default, server create/update/patch/transaction methods return a copy of the resource as it was stored.voidsetDefaultPrettyPrint(boolean theDefaultPrettyPrint)Should the server "pretty print" responses by default (requesting clients can always override this default by supplying anAcceptheader in the request, or a_prettyparameter in the request URL.voidsetDefaultResponseEncoding(ca.uhn.fhir.rest.api.EncodingEnum theDefaultResponseEncoding)Sets the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the_formatURL parameter, or with anAcceptheader in the request.voidsetElementsSupport(ElementsSupportEnum theElementsSupport)Sets the elements support mode.voidsetETagSupport(ETagSupportEnum theETagSupport)Sets (enables/disables) the server support for ETags.voidsetFhirContext(ca.uhn.fhir.context.FhirContext theFhirContext)voidsetIgnoreServerParsedRequestParameters(boolean theIgnoreServerParsedRequestParameters)If set totrue(the default istrue) this server will not use the parsed request parameters (URL parameters and HTTP POST form contents) but will instead parse these values manually from the request URL and request body.voidsetImplementationDescription(String theImplementationDescription)voidsetInterceptors(IServerInterceptor... theInterceptors)Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service.voidsetInterceptors(List<?> theList)Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service.voidsetInterceptorService(ca.uhn.fhir.interceptor.api.IInterceptorService theInterceptorService)Sets the interceptor registry for this service.voidsetPagingProvider(IPagingProvider thePagingProvider)Sets the paging provider to use, ornullto use no paging (which is the default)voidsetPlainProviders(Object... theProv)Deprecated.This method causes inconsistent behaviour depending on the order it is called in.voidsetPlainProviders(Collection<Object> theProviders)Deprecated.This method causes inconsistent behaviour depending on the order it is called in.voidsetProviders(Object... theProviders)Sets the non-resource specific providers which implement method calls on this servervoidsetResourceProviders(IResourceProvider... theResourceProviders)Sets the resource providers for this servervoidsetResourceProviders(Collection<IResourceProvider> theProviders)Sets the resource providers for this servervoidsetServerAddressStrategy(IServerAddressStrategy theServerAddressStrategy)Provide a server address strategy, which is used to determine what base URL to provide clients to refer to this server.voidsetServerConformanceProvider(Object theServerConformanceProvider)Returns the server conformance provider, which is the provider that is used to generate the server's conformance (metadata) statement.voidsetServerName(String theServerName)Sets the server's name, as exported in conformance profiles exported by the server.voidsetServerVersion(String theServerVersion)Gets the server's version, as exported in conformance profiles exported by the server.voidsetTenantIdentificationStrategy(ITenantIdentificationStrategy theTenantIdentificationStrategy)If provided (default isnull), the tenant identification strategy provides a mechanism for a multitenant server to identify which tenant a given request corresponds to.voidsetUncompressIncomingContents(boolean theUncompressIncomingContents)Should the server attempt to decompress incoming request contents (default istrue).protected voidthrowUnknownFhirOperationException(RequestDetails requestDetails, String requestPath, ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType)static voidthrowUnknownFhirOperationException(RequestDetails requestDetails, String requestPath, ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, ca.uhn.fhir.context.FhirContext theFhirContext)protected voidthrowUnknownResourceTypeException(String theResourceName)voidunregisterInterceptor(Object theInterceptor)Unregisters an interceptor.voidunregisterProvider(Object provider)Unregister one provider (either a Resource provider or a plain provider)voidunregisterProviders(Collection<?> providers)Unregister aCollectionof providersprotected voidvalidateRequest(ServletRequestDetails theRequestDetails)-
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doTrace, getLastModified, service
-
-
-
-
Field Detail
-
REQUEST_START_TIME
public static final String REQUEST_START_TIME
All incoming requests will have an attribute added toServletRequest.getAttribute(String)with this key. The value will be a JavaDatewith the time that request processing began.
-
DEFAULT_ETAG_SUPPORT
public static final ETagSupportEnum DEFAULT_ETAG_SUPPORT
Default setting forETag Support:ETagSupportEnum.ENABLED
-
SERVLET_CONTEXT_ATTRIBUTE
public static final 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+- See Also:
- Constant Field Values
-
DEFAULT_PREFER_RETURN
public static final ca.uhn.fhir.rest.api.PreferReturnEnum DEFAULT_PREFER_RETURN
Default value forsetDefaultPreferReturn(PreferReturnEnum)
-
-
Constructor Detail
-
RestfulServer
public RestfulServer()
Constructor. Note that if noFhirContextis passed in to the server (either through the constructor, or throughsetFhirContext(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.
-
RestfulServer
public RestfulServer(ca.uhn.fhir.context.FhirContext theCtx)
Constructor
-
-
Method Detail
-
addHeadersToResponse
public void addHeadersToResponse(javax.servlet.http.HttpServletResponse theHttpResponse)
This method is called prior to sending a response to incoming requests. It is used to add custom headers.Use caution if overriding this method: it is recommended to call
super.addHeadersToResponseto avoid inadvertently disabling functionality.
-
createConfiguration
public RestfulServerConfiguration createConfiguration()
-
createPoweredByAttributes
protected List<String> createPoweredByAttributes()
-
createPoweredByHeader
protected String createPoweredByHeader()
Subclasses may override to provide their own powered by header. Note that if you want to be nice and still credit HAPI FHIR you could consider overridingcreatePoweredByAttributes()instead and adding your own fragments to the list.
-
createPoweredByHeaderComponentName
protected String createPoweredByHeaderComponentName()
Subclasses my override- See Also:
createPoweredByHeader()
-
createPoweredByHeaderProductName
protected String createPoweredByHeaderProductName()
Subclasses my override- See Also:
createPoweredByHeader()
-
createPoweredByHeaderProductVersion
protected String createPoweredByHeaderProductVersion()
Subclasses my override- See Also:
createPoweredByHeader()
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Servlet- Overrides:
destroyin classjavax.servlet.GenericServlet
-
determineResourceMethod
public BaseMethodBinding<?> determineResourceMethod(RequestDetails requestDetails, String requestPath)
Figure out and return whichever method binding is appropriate for the given request
-
doDelete
protected void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doDeletein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doGetin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doOptions
protected void doOptions(javax.servlet.http.HttpServletRequest theReq, javax.servlet.http.HttpServletResponse theResp) throws javax.servlet.ServletException, IOException
- Overrides:
doOptionsin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPostin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPut
protected void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPutin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
getAddProfileTag
@Deprecated public ca.uhn.fhir.context.api.AddProfileTagEnum getAddProfileTag()
Deprecated.As of HAPI FHIR 1.5, this property has been moved toFhirContext.setAddProfileTagWhenEncoding(AddProfileTagEnum)- Specified by:
getAddProfileTagin interfaceIRestfulServerDefaults- Returns:
- Returns the setting for automatically adding profile tags
-
setAddProfileTag
@Deprecated public void setAddProfileTag(ca.uhn.fhir.context.api.AddProfileTagEnum theAddProfileTag)
Deprecated.As of HAPI FHIR 1.5, this property has been moved toFhirContext.setAddProfileTagWhenEncoding(AddProfileTagEnum)Sets the profile tagging behaviour for the server. When set to a value other thanAddProfileTagEnum.NEVER(which is the default), the server will automatically add a profile tag based on the class of the resource(s) being returned.- Parameters:
theAddProfileTag- The behaviour enum (must not be null)
-
getBundleInclusionRule
public ca.uhn.fhir.context.api.BundleInclusionRule getBundleInclusionRule()
- Specified by:
getBundleInclusionRulein interfaceIRestfulServer<ServletRequestDetails>
-
setBundleInclusionRule
public void setBundleInclusionRule(ca.uhn.fhir.context.api.BundleInclusionRule theBundleInclusionRule)
Set how bundle factory should decide whether referenced resources should be included in bundles- Parameters:
theBundleInclusionRule- - inclusion rule (@see BundleInclusionRule for behaviors)
-
getDefaultResponseEncoding
public ca.uhn.fhir.rest.api.EncodingEnum getDefaultResponseEncoding()
Returns the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the_formatURL parameter, or with anAcceptheader in the request. The default isEncodingEnum.XML. Will not return null.- Specified by:
getDefaultResponseEncodingin interfaceIRestfulServerDefaults- Returns:
- Returns the default encoding to return (XML/JSON) if an incoming request does not specify a preference
(either with the
_formatURL parameter, or with anAcceptheader in the request. The default isEncodingEnum.XML. Will not return null.
-
setDefaultResponseEncoding
public void setDefaultResponseEncoding(ca.uhn.fhir.rest.api.EncodingEnum theDefaultResponseEncoding)
Sets the default encoding to return (XML/JSON) if an incoming request does not specify a preference (either with the_formatURL parameter, or with anAcceptheader in the request. The default isEncodingEnum.XML.Note when testing this feature: Some browsers will include "application/xml" in their Accept header, which means that the
-
getETagSupport
public ETagSupportEnum getETagSupport()
- Specified by:
getETagSupportin interfaceIRestfulServerDefaults- Returns:
- Returns the server support for ETags (will not be
null). Default isDEFAULT_ETAG_SUPPORT
-
setETagSupport
public void setETagSupport(ETagSupportEnum theETagSupport)
Sets (enables/disables) the server support for ETags. Must not benull. Default isDEFAULT_ETAG_SUPPORT- Parameters:
theETagSupport- The ETag support mode
-
getElementsSupport
public ElementsSupportEnum getElementsSupport()
- Specified by:
getElementsSupportin interfaceIRestfulServerDefaults- Returns:
- Returns the support option for the
_elementsparameter on search and read operations. - See Also:
- Extended Elements Support
-
setElementsSupport
public void setElementsSupport(ElementsSupportEnum theElementsSupport)
Sets the elements support mode.- See Also:
- Extended Elements Support
-
getFhirContext
public ca.uhn.fhir.context.FhirContext getFhirContext()
Gets theFhirContextassociated 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.- Specified by:
getFhirContextin interfaceIRestfulServerDefaults
-
setFhirContext
public void setFhirContext(ca.uhn.fhir.context.FhirContext theFhirContext)
-
getImplementationDescription
public String getImplementationDescription()
-
setImplementationDescription
public void setImplementationDescription(String theImplementationDescription)
-
getInterceptors_
@Deprecated public List<IServerInterceptor> getInterceptors_()
Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service. You can register and unregister interceptors using this service.Returns a list of all registered server interceptors- Specified by:
getInterceptors_in interfaceIRestfulServerDefaults
-
getInterceptorService
public ca.uhn.fhir.interceptor.api.IInterceptorService getInterceptorService()
Returns the interceptor registry for this service. Use this registry to register and unregister- Specified by:
getInterceptorServicein interfaceIRestfulServerDefaults- Since:
- 3.8.0
-
setInterceptorService
public void setInterceptorService(@Nonnull ca.uhn.fhir.interceptor.api.IInterceptorService theInterceptorService)
Sets the interceptor registry for this service. Use this registry to register and unregister- Since:
- 3.8.0
-
setInterceptors
@Deprecated public void setInterceptors(@Nonnull List<?> theList)
Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service. You can register and unregister interceptors using this service.Sets (or clears) the list of interceptors- Parameters:
theList- The list of interceptors (may be null)
-
setInterceptors
@Deprecated public void setInterceptors(IServerInterceptor... theInterceptors)
Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service. You can register and unregister interceptors using this service.Sets (or clears) the list of interceptors- Parameters:
theInterceptors- The list of interceptors (may be null)
-
getPagingProvider
public IPagingProvider getPagingProvider()
Description copied from interface:IRestfulServerDefaultsReturns the paging provider for this server- Specified by:
getPagingProviderin interfaceIRestfulServer<ServletRequestDetails>- Specified by:
getPagingProviderin interfaceIRestfulServerDefaults
-
setPagingProvider
public void setPagingProvider(IPagingProvider thePagingProvider)
Sets the paging provider to use, ornullto use no paging (which is the default)
-
getPlainProviders
public Collection<Object> getPlainProviders()
Provides the non-resource specific providers which implement method calls on this server- See Also:
getResourceProviders()
-
setPlainProviders
@Deprecated public void setPlainProviders(Object... theProv)
Deprecated.This method causes inconsistent behaviour depending on the order it is called in. UseregisterProviders(Object...)instead.Sets the non-resource specific providers which implement method calls on this server.- See Also:
setResourceProviders(Collection)
-
setPlainProviders
@Deprecated public void setPlainProviders(Collection<Object> theProviders)
Deprecated.This method causes inconsistent behaviour depending on the order it is called in. UseregisterProviders(Object...)instead.Sets the non-resource specific providers which implement method calls on this server.- See Also:
setResourceProviders(Collection)
-
getRequestPath
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- Parameters:
requestFullPath- the full request pathservletContextPath- the servelet context pathservletPath- the servelet path- Returns:
- created resource path
-
getResourceBindings
public Collection<ResourceBinding> getResourceBindings()
-
getResourceProviders
public Collection<IResourceProvider> getResourceProviders()
Provides the resource providers for this server
-
setResourceProviders
public void setResourceProviders(IResourceProvider... theResourceProviders)
Sets the resource providers for this server
-
setResourceProviders
public void setResourceProviders(Collection<IResourceProvider> theProviders)
Sets the resource providers for this server
-
getServerAddressStrategy
public IServerAddressStrategy getServerAddressStrategy()
Get the server address strategy, which is used to determine what base URL to provide clients to refer to this server. Defaults to an instance ofIncomingRequestAddressStrategy
-
setServerAddressStrategy
public 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. Defaults to an instance ofIncomingRequestAddressStrategy
-
getServerBaseForRequest
public String getServerBaseForRequest(ServletRequestDetails theRequest)
Returns the server base URL (with no trailing '/') for a given request
-
getServerBindings
public List<BaseMethodBinding<?>> getServerBindings()
Returns the method bindings for this server which are not specific to any particular resource type. This method is internal to HAPI and developers generally do not need to interact with it. Use with caution, as it may change.
-
getServerConformanceProvider
public 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.By default, the ServerConformanceProvider for the declared version of FHIR is used, but this can be changed, or set to
nullto use the appropriate one for the given FHIR version.
-
setServerConformanceProvider
public void setServerConformanceProvider(Object theServerConformanceProvider)
Returns the server conformance provider, which is the provider that is used to generate the server's conformance (metadata) statement.By default, the ServerConformanceProvider implementation for the declared version of FHIR is used, but this can be changed, or set to
Note that this method can only be called before the server is initialized.nullif you do not wish to export a conformance statement.- Throws:
IllegalStateException- Note that this method can only be called prior toinitializationand will throw anIllegalStateExceptionif called after that.
-
getServerName
public String getServerName()
Gets the server's name, as exported in conformance profiles exported by the server. This is informational only, but can be helpful to set with something appropriate.- See Also:
setServerName(String)
-
setServerName
public void setServerName(String theServerName)
Sets the server's name, as exported in conformance profiles exported by the server. This is informational only, but can be helpful to set with something appropriate.
-
getServerProfilesProvider
public IResourceProvider getServerProfilesProvider()
-
getServerVersion
public String getServerVersion()
Gets the server's version, as exported in conformance profiles exported by the server. This is informational only, but can be helpful to set with something appropriate.
-
setServerVersion
public void setServerVersion(String theServerVersion)
Gets the server's version, as exported in conformance profiles exported by the server. This is informational only, but can be helpful to set with something appropriate.
-
handleRequest
protected void handleRequest(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse) throws javax.servlet.ServletException, IOException
- Throws:
javax.servlet.ServletExceptionIOException
-
newRequestDetails
@Nonnull protected ServletRequestDetails newRequestDetails(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse)
Subclasses may override this to customize the way that the RequestDetails object is created. Generally speaking, the right way to do this is to override this method, but call the super-implementation (super.newRequestDetails) and then customize the returned object before returning it.- Parameters:
theRequestType- The HTTP request verbtheRequest- The servlet requesttheResponse- The servlet response- Returns:
- A ServletRequestDetails instance to be passed to any resource providers, interceptors, etc. that are invoked as a part of serving this request.
-
newRequestDetails
@Deprecated protected ServletRequestDetails newRequestDetails()
Deprecated.Deprecated in HAPI FHIR 4.1.0 - Users wishing to override this method should overridenewRequestDetails(RequestTypeEnum, HttpServletRequest, HttpServletResponse)instead
-
addRequestIdToResponse
protected void addRequestIdToResponse(ServletRequestDetails theRequestDetails, String theRequestId)
-
getOrCreateRequestId
protected String getOrCreateRequestId(javax.servlet.http.HttpServletRequest theRequest)
Reads a requet ID from the request headers via theConstants.HEADER_REQUEST_IDheader, or generates one if none is supplied.Note that the generated request ID is a random 64-bit long integer encoded as hexadecimal. It is not generated using any cryptographic algorithms or a secure PRNG, so it should not be used for anything other than troubleshooting purposes.
-
newRequestId
protected String newRequestId(int theRequestIdLength)
Generate a new request ID string. Subclasses may ovrride.
-
validateRequest
protected void validateRequest(ServletRequestDetails theRequestDetails)
-
init
public final void init() throws javax.servlet.ServletException
Initializes the server. Note that this method is final to avoid accidentally introducing bugs in implementations, but subclasses may put initialization code ininitialize(), which is called immediately before beginning initialization of the restful server's internal init.- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException
-
initialize
protected void initialize() throws javax.servlet.ServletException
This method may be overridden by subclasses to do perform initialization that needs to be performed prior to the server being used.- Throws:
javax.servlet.ServletException- If the initialization failed. Note that you should consider throwingUnavailableException(which extendsServletException), as this is a flag to the servlet container that the servlet is not usable.
-
isDefaultPrettyPrint
public boolean isDefaultPrettyPrint()
Should the server "pretty print" responses by default (requesting clients can always override this default by supplying anAcceptheader in the request, or a_prettyparameter in the request URL.The default is
falseNote that this setting is ignored by
ResponseHighlighterInterceptorwhen streaming HTML, although even when that interceptor it used this setting will still be honoured when streaming raw FHIR.- Specified by:
isDefaultPrettyPrintin interfaceIRestfulServerDefaults- Returns:
- Returns the default pretty print setting
-
setDefaultPrettyPrint
public void setDefaultPrettyPrint(boolean theDefaultPrettyPrint)
Should the server "pretty print" responses by default (requesting clients can always override this default by supplying anAcceptheader in the request, or a_prettyparameter in the request URL.The default is
falseNote that this setting is ignored by
ResponseHighlighterInterceptorwhen streaming HTML, although even when that interceptor it used this setting will still be honoured when streaming raw FHIR.- Parameters:
theDefaultPrettyPrint- The default pretty print setting
-
isIgnoreServerParsedRequestParameters
public boolean isIgnoreServerParsedRequestParameters()
If set totrue(the default istrue) this server will not use the parsed request parameters (URL parameters and HTTP POST form contents) but will instead parse these values manually from the request URL and request body.This is useful because many servlet containers (e.g. Tomcat, Glassfish) will use ISO-8859-1 encoding to parse escaped URL characters instead of using UTF-8 as is specified by FHIR.
-
setIgnoreServerParsedRequestParameters
public void setIgnoreServerParsedRequestParameters(boolean theIgnoreServerParsedRequestParameters)
If set totrue(the default istrue) this server will not use the parsed request parameters (URL parameters and HTTP POST form contents) but will instead parse these values manually from the request URL and request body.This is useful because many servlet containers (e.g. Tomcat, Glassfish) will use ISO-8859-1 encoding to parse escaped URL characters instead of using UTF-8 as is specified by FHIR.
-
isUncompressIncomingContents
public boolean isUncompressIncomingContents()
Should the server attempt to decompress incoming request contents (default istrue). Typically this should be set totrueunless the server has other configuration to deal with decompressing request bodies (e.g. a filter applied to the whole server).
-
setUncompressIncomingContents
public void setUncompressIncomingContents(boolean theUncompressIncomingContents)
Should the server attempt to decompress incoming request contents (default istrue). Typically this should be set totrueunless the server has other configuration to deal with decompressing request bodies (e.g. a filter applied to the whole server).
-
populateRequestDetailsFromRequestPath
public void populateRequestDetailsFromRequestPath(RequestDetails theRequestDetails, String theRequestPath)
-
registerInterceptor
public void registerInterceptor(Object theInterceptor)
Registers an interceptor. This method is a convenience method which callsgetInterceptorService().registerInterceptor(theInterceptor);- Parameters:
theInterceptor- The interceptor, must not be null
-
registerProvider
public void registerProvider(Object provider)
Register a single provider. This could be a Resource Provider or a "plain" provider not associated with any resource.
-
registerProviders
public void registerProviders(Object... theProviders)
Register a group of providers. These could be Resource Providers (classes implementingIResourceProvider) or "plain" providers, or a mixture of the two.- Parameters:
theProviders- aCollectionof theProviders. The parameter could be null or an emptyCollection
-
registerProviders
public void registerProviders(Collection<?> theProviders)
Register a group of theProviders. These could be Resource Providers, "plain" theProviders or a mixture of the two.- Parameters:
theProviders- aCollectionof theProviders. The parameter could be null or an emptyCollection
-
registerProviders
protected void registerProviders(Collection<?> theProviders, boolean inInit)
-
returnResponse
public Object returnResponse(ServletRequestDetails theRequest, ParseAction<?> outcome, int operationStatus, boolean allowPrefer, ca.uhn.fhir.rest.api.MethodOutcome response, String resourceName) throws IOException
- Throws:
IOException
-
service
protected void service(javax.servlet.http.HttpServletRequest theReq, javax.servlet.http.HttpServletResponse theResp) throws javax.servlet.ServletException, IOException
- Overrides:
servicein classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
setProviders
public void setProviders(Object... theProviders)
Sets the non-resource specific providers which implement method calls on this server- See Also:
setResourceProviders(Collection)
-
setTenantIdentificationStrategy
public void setTenantIdentificationStrategy(ITenantIdentificationStrategy theTenantIdentificationStrategy)
If provided (default isnull), the tenant identification strategy provides a mechanism for a multitenant server to identify which tenant a given request corresponds to.
-
throwUnknownFhirOperationException
protected void throwUnknownFhirOperationException(RequestDetails requestDetails, String requestPath, ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType)
-
throwUnknownResourceTypeException
protected void throwUnknownResourceTypeException(String theResourceName)
-
unregisterInterceptor
public void unregisterInterceptor(Object theInterceptor)
Unregisters an interceptor. This method is a convenience method which callsgetInterceptorService().unregisterInterceptor(theInterceptor);- Parameters:
theInterceptor- The interceptor, must not be null
-
unregisterProvider
public void unregisterProvider(Object provider)
Unregister one provider (either a Resource provider or a plain provider)
-
unregisterProviders
public void unregisterProviders(Collection<?> providers)
Unregister aCollectionof providers
-
getDefaultPreferReturn
public ca.uhn.fhir.rest.api.PreferReturnEnum getDefaultPreferReturn()
By default, server create/update/patch/transaction methods return a copy of the resource as it was stored. This may be overridden by the client using thePreferheader.This setting changes the default behaviour if no Prefer header is supplied by the client. The default is
PreferReturnEnum.REPRESENTATION- Specified by:
getDefaultPreferReturnin interfaceIRestfulServer<ServletRequestDetails>- See Also:
- HL7 FHIR Specification section on the Prefer header
-
setDefaultPreferReturn
public void setDefaultPreferReturn(ca.uhn.fhir.rest.api.PreferReturnEnum theDefaultPreferReturn)
By default, server create/update/patch/transaction methods return a copy of the resource as it was stored. This may be overridden by the client using thePreferheader.This setting changes the default behaviour if no Prefer header is supplied by the client. The default is
PreferReturnEnum.REPRESENTATION- See Also:
- HL7 FHIR Specification section on the Prefer header
-
escapedLength
protected static int escapedLength(String theServletPath)
Count length of URL string, but treating unescaped sequences (e.g. ' ') as their unescaped equivalent (%20)
-
throwUnknownFhirOperationException
public static void throwUnknownFhirOperationException(RequestDetails requestDetails, String requestPath, ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, ca.uhn.fhir.context.FhirContext theFhirContext)
-
-