Search in sources :

Example 1 with HttpRequestPreprocessor

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;
}
Also used : Response(jakarta.ws.rs.core.Response) HttpResponse(org.jboss.resteasy.spi.HttpResponse) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) PreMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext) HttpRequestPreprocessor(org.jboss.resteasy.spi.HttpRequestPreprocessor) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) NotFoundException(jakarta.ws.rs.NotFoundException) UnhandledException(org.jboss.resteasy.spi.UnhandledException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException)

Example 2 with HttpRequestPreprocessor

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;
    }
}
Also used : Response(jakarta.ws.rs.core.Response) HttpResponse(org.jboss.resteasy.spi.HttpResponse) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) Registry(org.jboss.resteasy.spi.Registry) HashMap(java.util.HashMap) ResteasyConfiguration(org.jboss.resteasy.spi.ResteasyConfiguration) ArrayList(java.util.ArrayList) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) HashSet(java.util.HashSet) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Messages(org.jboss.resteasy.resteasy_jaxrs.i18n.Messages) Response(jakarta.ws.rs.core.Response) RequestImpl(org.jboss.resteasy.specimpl.RequestImpl) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) LogMessages(org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter) Dispatcher(org.jboss.resteasy.spi.Dispatcher) Map(java.util.Map) Cleanable(org.jboss.resteasy.plugins.server.Cleanable) Request(jakarta.ws.rs.core.Request) Cleanables(org.jboss.resteasy.plugins.server.Cleanables) NotFoundException(jakarta.ws.rs.NotFoundException) Iterator(java.util.Iterator) UnhandledException(org.jboss.resteasy.spi.UnhandledException) Set(java.util.Set) HttpRequest(org.jboss.resteasy.spi.HttpRequest) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) UriInfo(jakarta.ws.rs.core.UriInfo) HttpRequestPreprocessor(org.jboss.resteasy.spi.HttpRequestPreprocessor) HttpResponse(org.jboss.resteasy.spi.HttpResponse) Consumer(java.util.function.Consumer) ResteasyAsynchronousContext(org.jboss.resteasy.spi.ResteasyAsynchronousContext) List(java.util.List) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) HttpHeaders(jakarta.ws.rs.core.HttpHeaders) ResourceContext(jakarta.ws.rs.container.ResourceContext) Failure(org.jboss.resteasy.spi.Failure) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) Providers(jakarta.ws.rs.ext.Providers) PreMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext) PreMatchContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext) HttpRequestPreprocessor(org.jboss.resteasy.spi.HttpRequestPreprocessor) ContainerRequestFilter(jakarta.ws.rs.container.ContainerRequestFilter) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) NotFoundException(jakarta.ws.rs.NotFoundException) UnhandledException(org.jboss.resteasy.spi.UnhandledException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException)

Aggregations

NotFoundException (jakarta.ws.rs.NotFoundException)2 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)2 Response (jakarta.ws.rs.core.Response)2 IOException (java.io.IOException)2 CompletionException (java.util.concurrent.CompletionException)2 PreMatchContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext)2 BuiltResponse (org.jboss.resteasy.specimpl.BuiltResponse)2 HttpRequestPreprocessor (org.jboss.resteasy.spi.HttpRequestPreprocessor)2 HttpResponse (org.jboss.resteasy.spi.HttpResponse)2 InternalServerErrorException (org.jboss.resteasy.spi.InternalServerErrorException)2 UnhandledException (org.jboss.resteasy.spi.UnhandledException)2 RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)2 ResourceContext (jakarta.ws.rs.container.ResourceContext)1 HttpHeaders (jakarta.ws.rs.core.HttpHeaders)1 Request (jakarta.ws.rs.core.Request)1 UriInfo (jakarta.ws.rs.core.UriInfo)1 Providers (jakarta.ws.rs.ext.Providers)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1