use of org.jboss.resteasy.spi.HttpRequestPreprocessor in project resteasy by resteasy.
the class SynchronousDispatcher method preprocess.
/*
* TODO: refactor this method
* This only used by org.jboss.restesy.springmvc.ResteasyHandlerMapping
* And most of the code is same with the other preprocess method.
* We should consider to refactor this method to reuse part of the code with
* another one.
*/
public Response preprocess(HttpRequest request) {
RESTEasyTracingLogger.initTracingSupport(providerFactory, request);
Response aborted = null;
RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
try {
final long totalTimestamp = tracingLogger.timestamp("PRE_MATCH_SUMMARY");
for (HttpRequestPreprocessor preprocessor : this.requestPreprocessors) {
final long timestamp = tracingLogger.timestamp("PRE_MATCH");
preprocessor.preProcess(request);
tracingLogger.logDuration("PRE_MATCH", timestamp, preprocessor.getClass().toString());
}
tracingLogger.logDuration("PRE_MATCH_SUMMARY", totalTimestamp, this.requestPreprocessors.size());
ContainerRequestFilter[] requestFilters = providerFactory.getContainerRequestFilterRegistry().preMatch();
// FIXME: support async
PreMatchContainerRequestContext requestContext = new PreMatchContainerRequestContext(request, requestFilters, null);
aborted = requestContext.filter();
} catch (Exception e) {
// logger.error("Failed in preprocess, mapping exception", e);
aborted = new ExceptionHandler(providerFactory, unwrappedExceptions).handleException(request, e);
}
return aborted;
}
use of org.jboss.resteasy.spi.HttpRequestPreprocessor in project resteasy by resteasy.
the class SynchronousDispatcher method preprocess.
/**
* Call pre-process ContainerRequestFilters.
*
* @param request http request
* @param response http response
* @param continuation runnable
*/
protected void preprocess(HttpRequest request, HttpResponse response, Runnable continuation) {
Response aborted = null;
PreMatchContainerRequestContext requestContext = null;
RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
try {
final long totalTimestamp = tracingLogger.timestamp("PRE_MATCH_SUMMARY");
for (HttpRequestPreprocessor preprocessor : this.requestPreprocessors) {
final long timestamp = tracingLogger.timestamp("PRE_MATCH");
preprocessor.preProcess(request);
tracingLogger.logDuration("PRE_MATCH", timestamp, preprocessor.getClass().toString());
}
tracingLogger.logDuration("PRE_MATCH_SUMMARY", totalTimestamp, this.requestPreprocessors.size());
ContainerRequestFilter[] requestFilters = providerFactory.getContainerRequestFilterRegistry().preMatch();
requestContext = new PreMatchContainerRequestContext(request, requestFilters, () -> {
continuation.run();
return null;
});
aborted = requestContext.filter();
} catch (Exception e) {
// we only want to catch exceptions happening in the filters, not in the continuation
if (requestContext == null || !requestContext.startedContinuation()) {
writeException(request, response, e, t -> {
});
return;
} else {
rethrow(e);
}
}
if (aborted != null) {
tracingLogger.log("FINISHED", response.getStatus());
tracingLogger.flush(response.getOutputHeaders());
writeResponse(request, response, aborted);
return;
}
}
Aggregations