Class ExceptionHandlingInterceptor
- java.lang.Object
-
- ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter
-
- ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor
-
- All Implemented Interfaces:
IServerInterceptor
public class ExceptionHandlingInterceptor extends InterceptorAdapter
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ca.uhn.fhir.rest.server.interceptor.IServerInterceptor
IServerInterceptor.ActionRequestDetails
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROCESSING
-
Constructor Summary
Constructors Constructor Description ExceptionHandlingInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjecthandleException(RequestDetails theRequestDetails, ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException theException)booleanhandleException(RequestDetails theRequestDetails, ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException theException, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse)This method is called upon any exception being thrown within the server's request processing code.ca.uhn.fhir.rest.server.exceptions.BaseServerResponseExceptionpreProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, javax.servlet.http.HttpServletRequest theServletRequest)This method is called upon any exception being thrown within the server's request processing code.ExceptionHandlingInterceptorsetReturnStackTracesForExceptionTypes(Class<?>... theExceptionTypes)If any server methods throw an exception which extends any of the given exception types, the exception stack trace will be returned to the user.-
Methods inherited from class ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter
incomingRequestPostProcessed, incomingRequestPreHandled, incomingRequestPreProcessed, outgoingResponse, outgoingResponse, outgoingResponse, outgoingResponse, outgoingResponse, outgoingResponse, outgoingResponse, processingCompletedNormally
-
-
-
-
Field Detail
-
PROCESSING
public static final String PROCESSING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExceptionHandlingInterceptor
public ExceptionHandlingInterceptor()
-
-
Method Detail
-
handleException
public boolean handleException(RequestDetails theRequestDetails, ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException theException, javax.servlet.http.HttpServletRequest theRequest, javax.servlet.http.HttpServletResponse theResponse) throws javax.servlet.ServletException, IOException
Description copied from interface:IServerInterceptorThis method is called upon any exception being thrown within the server's request processing code. This includes any exceptions thrown within resource provider methods (e.g.SearchandReadmethods) as well as any runtime exceptions thrown by the server itself. This also includes anyAuthenticationExceptions thrown.Implementations of this method may choose to ignore/log/count/etc exceptions, and return
true. In this case, processing will continue, and the server will automatically generate anOperationOutcome. Implementations may also choose to provide their own response to the client. In this case, they should returnfalse, to indicate that they have handled the request and processing should stop.- Specified by:
handleExceptionin interfaceIServerInterceptor- Overrides:
handleExceptionin classInterceptorAdapter- Parameters:
theRequestDetails- A bean containing details about the request that is about to be processed, including details such as the resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been pulled out of theservlet request. Note that the bean properties are not all guaranteed to be populated, depending on how early during processing the exception occurred.theRequest- The incoming requesttheResponse- The response. Note that interceptors may choose to provide a response (i.e. by callingServletResponse.getWriter()) but in that case it is important to returnfalseto indicate that the server itself should not also provide a response.- Returns:
- Return
trueif processing should continue normally. This is generally the right thing to do. If your interceptor is providing a response rather than letting HAPI handle the response normally, you must returnfalse. In this case, no further processing will occur and no further interceptors will be called. - Throws:
javax.servlet.ServletException- If this exception is thrown, it will be re-thrown up to the container for handling.IOException- If this exception is thrown, it will be re-thrown up to the container for handling.
-
handleException
public Object handleException(RequestDetails theRequestDetails, ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException theException) throws javax.servlet.ServletException, IOException
- Throws:
javax.servlet.ServletExceptionIOException
-
preProcessOutgoingException
public ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, javax.servlet.http.HttpServletRequest theServletRequest) throws javax.servlet.ServletException
Description copied from interface:IServerInterceptorThis method is called upon any exception being thrown within the server's request processing code. This includes any exceptions thrown within resource provider methods (e.g.SearchandReadmethods) as well as any runtime exceptions thrown by the server itself. This method is invoked for each interceptor (until one of them returns a non-nullresponse or the end of the list is reached), after whichIServerInterceptor.handleException(RequestDetails, BaseServerResponseException, HttpServletRequest, HttpServletResponse)is called for each interceptor.This may be used to add an OperationOutcome to a response, or to convert between exception types for any reason.
Implementations of this method may choose to ignore/log/count/etc exceptions, and return
null. In this case, processing will continue, and the server will automatically generate anOperationOutcome. Implementations may also choose to provide their own response to the client. In this case, they should return a non-null, to indicate that they have handled the request and processing should stop.- Specified by:
preProcessOutgoingExceptionin interfaceIServerInterceptor- Overrides:
preProcessOutgoingExceptionin classInterceptorAdapter- Returns:
- Returns the new exception to use for processing, or
nullif this interceptor is not trying to modify the exception. For example, if this interceptor has nothing to do with exception processing, it should always returnnull. If this interceptor adds an OperationOutcome to the exception, it should return an exception. - Throws:
javax.servlet.ServletException
-
setReturnStackTracesForExceptionTypes
public ExceptionHandlingInterceptor setReturnStackTracesForExceptionTypes(Class<?>... theExceptionTypes)
If any server methods throw an exception which extends any of the given exception types, the exception stack trace will be returned to the user. This can be useful for helping to diagnose issues, but may not be desirable for production situations.- Parameters:
theExceptionTypes- The exception types for which to return the stack trace to the user.- Returns:
- Returns an instance of this interceptor, to allow for easy method chaining.
-
-