Stream: hapi
Topic: hapi fhir interceptor question
Asharaf Kadavath (Aug 26 2019 at 15:10):
From an interceptor I am trying to capture HTTP response code.
Here is my sample code:
//----------
public class MyInterceptor extends InterceptorAdapter{
@Override
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse)
logger.info(theServletResponse.getStatus());
}
//----------
but getStatus() always return 200 instead of the actual response code that is sent to the calling client(201, 500 etc.).
How do I capture the actual HTTP response code using the objects accessible to the interceptor?
James Agnew (Aug 26 2019 at 19:07):
You can probably do this with the new interceptor framework.
Make your class not extend InterceptorAdapter, and annotate your outgoingResponse
with @Hook(Pointcut.SERVER_OUTGOING_RESPONSE)
.
You can then add a parameter of type ca.uhn.fhir.rest.api.server.ResponseDetails
that should know the response code.
Last updated: Apr 12 2022 at 19:14 UTC