Interceptors
The HAPI FHIR Server Interceptor Framework is a mechanism for modifying the behavior of the server in a variety of ways.
As described in the documentation, special classes called Interceptors can be used to:
In the interceptor framework, a Pointcut is a specific spot in the processing pipeline where custom logic can be added via an interceptor. The custom logic (i.e. code) itself is called a Hook. See the HAPI FHIR Interceptor Documentation for more information on the terminology used here.
Most HAPI FHIR interceptors are supported in the appropriate Smile CDR modules for the given Pointcut type. In addition to supporting HAPI FHIR interceptor Pointcuts, a set of Smile CDR specific pointcuts are available as well.
HAPI FHIR interceptors use the @Hook annotation and Pointcut enum. For example:
@Hook(Pointcut.SERVER_OUTGOING_WRITER_CREATED)
public Writer capture(RequestDetails theRequestDetails, Writer theWriter) {
CountingWriter retVal = new CountingWriter(theWriter);
theRequestDetails.getUserData().put(COUNTING_WRITER_KEY, retVal);
return retVal;
}
Smile CDR interceptors use an equivalent pair of classes: The @CdrHook annotation and the CdrPointcut enum. For example:
@CdrHook(CdrPointcut.FHIRGW_SEARCH_TARGET_PREINVOKE)
public void preInvoke(SearchRequest theRequest) {
theRequest.removeParameters("_id");
theRequest.addParameter("_id", "101");
}
The following table outlines the various module types, and the various types of Pointcuts that may be intercepted by an interceptor registered against that module.
Module Types | Allowable Pointcuts | |
---|---|---|
FHIR Endpoint |
|
Examples |
Hybrid Providers |
|
Examples |
FHIR Gateway |
|
Examples |
FHIR Storage |
|
Examples |
Subscription |
|
Interceptor classes should be packaged as a simple JAR file containing only the classes defined by the interceptor (i.e. library dependencies such as Spring or Commons-Lang should not be included in your JAR). The JAR file should be placed in the smilecdr/customerlib
folder.
The interceptor class (or classes) that you have defined should then be set on the interceptor_bean_types
property within the appropriate module configuration. Smile CDR must be restarted for changes to take effect.
For example, the following property sets a custom interceptor from within the configuration property file:
module.persistence.config.interceptor_bean_types=ExampleAttributeEnhancingInterceptor
Interceptor classes have access to any of the standard libraries available within Smile CDR. This includes Spring Framework, Apache HTTPClient, Gson, Jackson, Woodstox, and others.