This page contains example interceptors that can be registered against a FHIR Endpoint module, including:
The following interceptor can be used to replace the built-in automatic CapabilityStatement generation provided by Smile CDR. This is useful if you are implementing a specific implementation guide that requires a static CapabilityStatement.
/**
* This interceptor overrides the built-in automatic CpaabilityStatement generator in
* Smile CDR and instead uses a static resource when a client invokes the
* "capabilities" operation (i.e. /metadata)
*/
@Interceptor
public class OverrideCapabilityStatementInterceptor extends StaticCapabilityStatementInterceptor {
/**
* Constructor
*
* Note that this class does not have any @Hook methods since the actual interceptor
* hook is defined in the superclass. We just use this constructor in our
* implementation to configure the interceptor.
*/
public OverrideCapabilityStatementInterceptor() {
// This interceptor uses a CapabilityStatement resource that is available
// on the classpath. This file can be built into the interceptor project by
// placing it in "src/main/resources/", or it can be placed in the Smile CDR
// installation in the "classes/" directory.
setCapabilityStatementResource("static-capabilitystatement.json");
// Alternately, you can build the CapabilityStatement programatically
/*
CapabilityStatement cs = new CapabilityStatement();
cs.setFhirVersion(Enumerations.FHIRVersion._4_0_1);
setCapabilityStatement(cs);
*/
}
}
The following example shows an interceptor that can be used as a starter Server interceptor, implementing a hook method for each available pointcut.
/**
* Sample Server Interceptor implementing all SERVER_XXX pointcuts.
* It is indented to be used in
* FHIR Endpoint module 'Interceptor Bean Types'
* or Hybrid Providers REST Endpoint module 'Interceptor Bean Types'
* or FHIR Gateway REST Endpoint module 'Interceptor Bean Types'.
* Can be used as a starting point for your server interceptor.
*/
@SuppressWarnings({"unused", "EmptyTryBlock"})
@Interceptor
public class ServerInterceptorTemplate {
private static final Logger ourLog = LoggerFactory.getLogger(ServerInterceptorTemplate.class);
@Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_PROCESSED)
public boolean serverIncomingRequestPreProcessed(
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_PROCESSED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_PROCESSED - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_HANDLER_SELECTED)
public boolean serverIncomingRequestPreHandlerSelected(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_HANDLER_SELECTED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_HANDLER_SELECTED - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_INCOMING_REQUEST_POST_PROCESSED)
public boolean serverIncomingRequestPostProcessed(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_POST_PROCESSED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_POST_PROCESSED - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_HANDLED)
public void serverIncomingRequestPreHandled(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
RestOperationTypeEnum theRestOperationTypeEnum) {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_HANDLED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_INCOMING_REQUEST_PRE_HANDLED - ended, execution took {}", stopWatch);
}
}
@Hook(Pointcut.SERVER_OUTGOING_RESPONSE)
public boolean serverOutgoingResponse(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
IBaseResource theBaseResource,
ResponseDetails theResponseDetails,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_OUTGOING_RESPONSE - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_OUTGOING_RESPONSE - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_OUTGOING_WRITER_CREATED)
public Writer serverOutgoingWriterCreated(
Writer theWriter,
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails) {
ourLog.info("Interceptor SERVER_OUTGOING_WRITER_CREATED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_OUTGOING_WRITER_CREATED - ended, execution took {}", stopWatch);
}
return theWriter;
}
@Hook(Pointcut.SERVER_PROCESSING_COMPLETED_NORMALLY)
public void serverProcessingCompletedNormally(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails) {
ourLog.info("Interceptor SERVER_PROCESSING_COMPLETED_NORMALLY - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_PROCESSING_COMPLETED_NORMALLY - ended, execution took {}", stopWatch);
}
}
@Hook(Pointcut.SERVER_PROCESSING_COMPLETED)
public void serverProcessingCompleted(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails) {
ourLog.info("Interceptor SERVER_PROCESSING_COMPLETED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_PROCESSING_COMPLETED - ended, execution took {}", stopWatch);
}
}
@Hook(Pointcut.SERVER_OUTGOING_GRAPHQL_RESPONSE)
public boolean serverOutgoingGraphqlResponse(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
String theQuery,
String theResponse,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_OUTGOING_GRAPHQL_RESPONSE - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_OUTGOING_GRAPHQL_RESPONSE - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_PRE_PROCESS_OUTGOING_EXCEPTION)
public BaseServerResponseException serverPreProcessOutgoingException(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
Throwable theThrowable,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse) {
ourLog.info("Interceptor SERVER_PRE_PROCESS_OUTGOING_EXCEPTION - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_PRE_PROCESS_OUTGOING_EXCEPTION - ended, execution took {}", stopWatch);
}
return null;
}
@Hook(Pointcut.SERVER_HANDLE_EXCEPTION)
public boolean serverHandleException(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
HttpServletRequest theHttpServletRequest,
HttpServletResponse theHttpServletResponse,
BaseServerResponseException theBaseServerResponseException) {
ourLog.info("Interceptor SERVER_HANDLE_EXCEPTION - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_HANDLE_EXCEPTION - ended, execution took {}", stopWatch);
}
return true;
}
@Hook(Pointcut.SERVER_OUTGOING_FAILURE_OPERATIONOUTCOME)
public void serverOutgoingFailureOperationOutcome(
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails,
IBaseOperationOutcome theBaseOperationOutcome) {
ourLog.info("Interceptor SERVER_OUTGOING_FAILURE_OPERATIONOUTCOME - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_OUTGOING_FAILURE_OPERATIONOUTCOME - ended, execution took {}", stopWatch);
}
}
@Hook(Pointcut.SERVER_CAPABILITY_STATEMENT_GENERATED)
public IBaseConformance serverCapabilityStatementGenerated(
IBaseConformance theBaseConformance,
RequestDetails theRequestDetails,
ServletRequestDetails theServletRequestDetails) {
ourLog.info("Interceptor SERVER_CAPABILITY_STATEMENT_GENERATED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_CAPABILITY_STATEMENT_GENERATED - ended, execution took {}", stopWatch);
}
return theBaseConformance;
}
@Hook(Pointcut.VALIDATION_COMPLETED)
public ValidationResult validationCompleted(
IBaseResource theBaseResource,
String theRawBaseResource,
ValidationResult theValidationResult) {
ourLog.info("Interceptor VALIDATION_COMPLETED - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor VALIDATION_COMPLETED - ended, execution took {}", stopWatch);
}
return null;
}
@CdrHook(CdrPointcut.SERVER_CONFIGURATION_KEYSTORE)
public KeyStore serverConfigurationKeystore(
String theKeyStorePassword) {
ourLog.info("Interceptor SERVER_CONFIGURATION_KEYSTORE - started");
StopWatch stopWatch = new StopWatch();
try {
// your implementation goes here
}
finally {
ourLog.info("Interceptor SERVER_CONFIGURATION_KEYSTORE - ended, execution took {}", stopWatch);
}
// should return a valid KeyStore
return null;
}
}