
Class RestfulServer
- All Implemented Interfaces:
IRestfulServer<ServletRequestDetails>,IRestfulServerDefaults,jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
See HAPI FHIR Plain Server for information on how to use this framework.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ETagSupportEnumDefault setting forETag Support:ETagSupportEnum.ENABLEDstatic final ca.uhn.fhir.rest.api.PreferReturnEnumDefault value forsetDefaultPreferReturn(PreferReturnEnum)static final StringAll incoming requests will have an attribute added toServletRequest.getAttribute(String)with this key.static final StringRequests will have an HttpServletRequest attribute set with this name, containing the servlet context, in order to avoid a dependency on Servlet-API 3.0+Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.RestfulServer(ca.uhn.fhir.context.FhirContext theCtx) ConstructorRestfulServer(ca.uhn.fhir.context.FhirContext theCtx, ca.uhn.fhir.interceptor.api.IInterceptorService theInterceptorService) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHeadersToResponse(jakarta.servlet.http.HttpServletResponse theHttpResponse) This method is called prior to sending a response to incoming requests.protected voidaddRequestIdToResponse(ServletRequestDetails theRequestDetails, String theRequestId) protected StringSubclasses may override to provide their own powered by header.protected StringSubclasses my overrideprotected StringSubclasses my overrideprotected StringSubclasses my overridevoiddestroy()determineResourceMethod(RequestDetails requestDetails, String requestPath) Figure out and return whichever method binding is appropriate for the given requestprotected voiddoDelete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected voiddoOptions(jakarta.servlet.http.HttpServletRequest theReq, jakarta.servlet.http.HttpServletResponse theResp) protected voiddoPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected voiddoPut(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected static intescapedLength(String theServletPath) Count length of URL string, but treating unescaped sequences (e.g. ' ') as their unescaped equivalent (%20)ca.uhn.fhir.context.api.AddProfileTagEnumDeprecated.ca.uhn.fhir.context.api.BundleInclusionRuleorg.hl7.fhir.instance.model.api.IBaseConformancegetCapabilityStatement(ServletRequestDetails theRequestDetails) Create a CapabilityStatement based on the given requestReturns the server copyright (will be added to the CapabilityStatement).Default page size for searches.ca.uhn.fhir.rest.api.PreferReturnEnumBy default, server create/update/patch/transaction methods return a copy of the resource as it was stored.ca.uhn.fhir.rest.api.EncodingEnumReturns 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.ca.uhn.fhir.context.FhirContextGets theFhirContextassociated with this server.Deprecated.As of HAPI FHIR 3.8.0, usegetInterceptorService()to access the interceptor service.ca.uhn.fhir.interceptor.api.IInterceptorServiceReturns the interceptor registry for this service.Maximum page size for searches.protected StringgetOrCreateRequestId(jakarta.servlet.http.HttpServletRequest theRequest) Reads a request ID from the request headers via theConstants.HEADER_REQUEST_IDheader, or generates one if none is supplied.Returns the paging provider for this serverProvides the non-resource specific providers which implement method calls on this servergetProviderMethodBindings(Object theProvider) protected StringgetRequestPath(String requestFullPath, String servletContextPath, String servletPath) Allows users of RestfulServer to override the getRequestPath method to let them build their custom request path implementationProvides the resource providers for this serverGet the server address strategy, which is used to determine what base URL to provide clients to refer to this server.getServerBaseForRequest(ServletRequestDetails theRequest) Returns the server base URL (with no trailing '/') for a given requestReturns the method bindings for this server which are not specific to any particular resource type.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.Gets the server's name, as exported in conformance profiles exported by the server.Gets the server's version, as exported in conformance profiles exported by the server.protected voidhandleRequest(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, jakarta.servlet.http.HttpServletRequest theRequest, jakarta.servlet.http.HttpServletResponse theResponse) final voidinit()Initializes the server.protected voidThis method may be overridden by subclasses to do perform initialization that needs to be performed prior to the server being used.booleanShould 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.booleanIf 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.booleanShould the server attempt to decompress incoming request contents (default istrue).protected ServletRequestDetailsDeprecated.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, jakarta.servlet.http.HttpServletRequest theRequest, jakarta.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) returnResponse(ServletRequestDetails theRequest, BaseParseAction<?> outcome, int operationStatus, boolean allowPrefer, ca.uhn.fhir.rest.api.MethodOutcome response, String resourceName) protected voidservice(jakarta.servlet.http.HttpServletRequest theReq, jakarta.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 bundlesvoidsetCopyright(String theCopyright) Sets the server copyright (will be added to the CapabilityStatement).voidsetDefaultPageSize(Integer thePageSize) Sets the default page size to use, ornullif no default page sizevoidsetDefaultPreferReturn(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.voidsetMaximumPageSize(Integer theMaximumPageSize) Sets the maximum page size to use, ornullif no maximum page sizevoidsetPagingProvider(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) voidUnregisters all plain and resource providers (but not the conformance provider).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 jakarta.servlet.http.HttpServlet
doHead, doTrace, getLastModified, init, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, logMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ca.uhn.fhir.rest.api.server.IRestfulServer
canStoreSearchResults
-
Field Details
-
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
Default setting forETag Support:ETagSupportEnum.ENABLED -
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:
-
DEFAULT_PREFER_RETURN
Default value forsetDefaultPreferReturn(PreferReturnEnum)
-
-
Constructor Details
-
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
Constructor -
RestfulServer
public RestfulServer(ca.uhn.fhir.context.FhirContext theCtx, ca.uhn.fhir.interceptor.api.IInterceptorService theInterceptorService)
-
-
Method Details
-
getServerConformanceMethod
- Since:
- 5.5.0
-
addHeadersToResponse
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
-
createPoweredByAttributes
-
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
Subclasses my override- See Also:
-
createPoweredByHeaderProductName
Subclasses my override- See Also:
-
createPoweredByHeaderProductVersion
Subclasses my override- See Also:
-
destroy
- Specified by:
destroyin interfacejakarta.servlet.Servlet- Overrides:
destroyin classjakarta.servlet.GenericServlet
-
determineResourceMethod
Figure out and return whichever method binding is appropriate for the given request -
doDelete
protected void doDelete(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doDeletein classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doOptions
protected void doOptions(jakarta.servlet.http.HttpServletRequest theReq, jakarta.servlet.http.HttpServletResponse theResp) throws jakarta.servlet.ServletException, IOException - Overrides:
doOptionsin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doPost
protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doPostin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doPut
protected void doPut(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doPutin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
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
- 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
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
- Specified by:
getETagSupportin interfaceIRestfulServerDefaults- Returns:
- Returns the server support for ETags (will not be
null). Default isDEFAULT_ETAG_SUPPORT
-
setETagSupport
Sets (enables/disables) the server support for ETags. Must not benull. Default isDEFAULT_ETAG_SUPPORT- Parameters:
theETagSupport- The ETag support mode
-
getElementsSupport
- Specified by:
getElementsSupportin interfaceIRestfulServerDefaults- Returns:
- Returns the support option for the
_elementsparameter on search and read operations. - See Also:
-
setElementsSupport
Sets the elements support mode.- See Also:
-
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
-
getImplementationDescription
-
setImplementationDescription
-
getCopyright
Returns the server copyright (will be added to the CapabilityStatement). Note that FHIR allows Markdown in this string. -
setCopyright
Sets the server copyright (will be added to the CapabilityStatement). Note that FHIR allows Markdown in this string. -
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
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.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.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
Description copied from interface:IRestfulServerDefaultsReturns the paging provider for this server- Specified by:
getPagingProviderin interfaceIRestfulServer<ServletRequestDetails>- Specified by:
getPagingProviderin interfaceIRestfulServerDefaults
-
setPagingProvider
Sets the paging provider to use, ornullto use no paging (which is the default). This will set defaultPageSize and maximumPageSize from the paging provider. -
getDefaultPageSize
Description copied from interface:IRestfulServerDefaultsDefault page size for searches. Null means no limit (JpaStorageSettings might have size limit however)- Specified by:
getDefaultPageSizein interfaceIRestfulServerDefaults
-
setDefaultPageSize
Sets the default page size to use, ornullif no default page size -
getMaximumPageSize
Description copied from interface:IRestfulServerDefaultsMaximum page size for searches. Null means no upper limit.- Specified by:
getMaximumPageSizein interfaceIRestfulServerDefaults
-
setMaximumPageSize
Sets the maximum page size to use, ornullif no maximum page size -
getPlainProviders
Provides the non-resource specific providers which implement method calls on this server- See Also:
-
setPlainProviders
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:
-
setPlainProviders
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:
-
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
-
getProviderMethodBindings
-
getResourceProviders
Provides the resource providers for this server -
setResourceProviders
Sets the resource providers for this server -
setResourceProviders
Sets the resource providers for this server -
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
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
Returns the server base URL (with no trailing '/') for a given request -
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
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
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
This method should only be called before the server is initialized. Calling it after the server has started is allowed, but you should be very careful in this case that you only call it while no traffic is hitting the server.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
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
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. -
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
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, jakarta.servlet.http.HttpServletRequest theRequest, jakarta.servlet.http.HttpServletResponse theResponse) throws jakarta.servlet.ServletException, IOException - Throws:
jakarta.servlet.ServletExceptionIOException
-
newRequestDetails
@Nonnull protected ServletRequestDetails newRequestDetails(ca.uhn.fhir.rest.api.RequestTypeEnum theRequestType, jakarta.servlet.http.HttpServletRequest theRequest, jakarta.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.Deprecated in HAPI FHIR 4.1.0 - Users wishing to override this method should overridenewRequestDetails(RequestTypeEnum, HttpServletRequest, HttpServletResponse)instead -
addRequestIdToResponse
-
getOrCreateRequestId
Reads a request 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
Generate a new request ID string. Subclasses may ovrride. -
validateRequest
-
init
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 classjakarta.servlet.GenericServlet- Throws:
jakarta.servlet.ServletException
-
initialize
This method may be overridden by subclasses to do perform initialization that needs to be performed prior to the server being used.- Throws:
jakarta.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
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
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
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
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
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
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
Registers an interceptor. This method is a convenience method which callsgetInterceptorService().registerInterceptor(theInterceptor);- Parameters:
theInterceptor- The interceptor, must not be null
-
registerProvider
Register a single provider. This could be a Resource Provider or a "plain" provider not associated with any resource. -
registerProviders
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
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
-
returnResponse
public Object returnResponse(ServletRequestDetails theRequest, BaseParseAction<?> outcome, int operationStatus, boolean allowPrefer, ca.uhn.fhir.rest.api.MethodOutcome response, String resourceName) throws IOException - Throws:
IOException
-
service
protected void service(jakarta.servlet.http.HttpServletRequest theReq, jakarta.servlet.http.HttpServletResponse theResp) throws jakarta.servlet.ServletException, IOException - Overrides:
servicein classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
setProviders
Sets the non-resource specific providers which implement method calls on this server- See Also:
-
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
-
unregisterInterceptor
Unregisters an interceptor. This method is a convenience method which callsgetInterceptorService().unregisterInterceptor(theInterceptor);- Parameters:
theInterceptor- The interceptor, must not be null
-
unregisterProvider
Unregister one provider (either a Resource provider or a plain provider) -
unregisterProviders
Unregister aCollectionof providers -
unregisterAllProviders
Unregisters all plain and resource providers (but not the conformance provider). -
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:
-
setDefaultPreferReturn
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:
-
getCapabilityStatement
public org.hl7.fhir.instance.model.api.IBaseConformance getCapabilityStatement(ServletRequestDetails theRequestDetails) Create a CapabilityStatement based on the given request -
escapedLength
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)
-
FhirContext.setAddProfileTagWhenEncoding(AddProfileTagEnum)