Allow for improved overriding of RestfulServer#newRequestDetails

This commit is contained in:
James Agnew 2019-10-22 18:09:21 -04:00
parent 371bf2e5cf
commit 9e44049847
1 changed files with 27 additions and 6 deletions

View File

@ -78,7 +78,8 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@SuppressWarnings("WeakerAccess")
public class RestfulServer extends HttpServlet implements IRestfulServer<ServletRequestDetails> {
@ -849,11 +850,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
@SuppressWarnings("WeakerAccess")
protected void handleRequest(RequestTypeEnum theRequestType, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
String fhirServerBase;
ServletRequestDetails requestDetails = newRequestDetails();
requestDetails.setServer(this);
requestDetails.setRequestType(theRequestType);
requestDetails.setServletRequest(theRequest);
requestDetails.setServletResponse(theResponse);
ServletRequestDetails requestDetails = newRequestDetails(theRequestType, theRequest, theResponse);
String requestId = getOrCreateRequestId(theRequest);
requestDetails.setRequestId(requestId);
@ -1096,6 +1093,30 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
}
}
/**
* 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 (<code>super.newRequestDetails</code>)
* and then customize the returned object before returning it.
*
* @param theRequestType The HTTP request verb
* @param theRequest The servlet request
* @param theResponse The servlet response
* @return A ServletRequestDetails instance to be passed to any resource providers, interceptors, etc. that are invoked as a part of serving this request.
*/
@Nonnull
protected ServletRequestDetails newRequestDetails(RequestTypeEnum theRequestType, HttpServletRequest theRequest, HttpServletResponse theResponse) {
ServletRequestDetails requestDetails = newRequestDetails();
requestDetails.setServer(this);
requestDetails.setRequestType(theRequestType);
requestDetails.setServletRequest(theRequest);
requestDetails.setServletResponse(theResponse);
return requestDetails;
}
/**
* @deprecated Deprecated in HAPI FHIR 4.1.0 - Users wishing to override this method should override {@link #newRequestDetails(RequestTypeEnum, HttpServletRequest, HttpServletResponse)} instead
*/
@Deprecated
protected ServletRequestDetails newRequestDetails() {
return new ServletRequestDetails(getInterceptorService());
}