Search in sources :

Example 1 with RESTEasyTracingLogger

use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.

the class ClientInvocation method initTracingSupport.

private void initTracingSupport() {
    final RESTEasyTracingLogger tracingLogger;
    if (RESTEasyTracingLogger.isTracingConfigALL(configuration)) {
        tracingLogger = RESTEasyTracingLogger.create(this.toString(), configuration, this.toString());
    } else {
        tracingLogger = RESTEasyTracingLogger.empty();
    }
    this.tracingLogger = tracingLogger;
}
Also used : RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Example 2 with RESTEasyTracingLogger

use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.

the class ServerResponseWriter method executeFilters.

private static void executeFilters(BuiltResponse jaxrsResponse, HttpRequest request, HttpResponse response, ResteasyProviderFactory providerFactory, ResourceMethodInvoker method, Consumer<Throwable> onComplete, RunnableWithIOException continuation) throws IOException {
    ContainerResponseFilter[] responseFilters = null;
    if (method != null) {
        responseFilters = method.getResponseFilters();
    } else {
        responseFilters = providerFactory.getContainerResponseFilterRegistry().postMatch(null, null);
    }
    if (responseFilters != null) {
        ResponseContainerRequestContext requestContext = new ResponseContainerRequestContext(request);
        ContainerResponseContextImpl responseContext = new ContainerResponseContextImpl(request, response, jaxrsResponse, requestContext, responseFilters, onComplete, continuation);
        RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
        final long timestamp = logger.timestamp("RESPONSE_FILTER_SUMMARY");
        // filter calls the continuation
        responseContext.filter();
        logger.logDuration("RESPONSE_FILTER_SUMMARY", timestamp, responseFilters.length);
    } else {
        try {
            continuation.run(onComplete);
        } catch (Throwable t) {
            onComplete.accept(t);
            SynchronousDispatcher.rethrow(t);
        }
    }
}
Also used : ContainerResponseFilter(jakarta.ws.rs.container.ContainerResponseFilter) ResponseContainerRequestContext(org.jboss.resteasy.core.interception.jaxrs.ResponseContainerRequestContext) ContainerResponseContextImpl(org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger)

Example 3 with RESTEasyTracingLogger

use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.

the class SynchronousDispatcher method invoke.

/**
 * Invoke and write response.
 *
 * @param request http request
 * @param response http response
 * @param invoker resource invoker
 */
public void invoke(HttpRequest request, HttpResponse response, ResourceInvoker invoker) {
    RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
    Response jaxrsResponse = null;
    try {
        request.getAsyncContext().initialRequestStarted();
        jaxrsResponse = invoker.invoke(request, response);
        request.getAsyncContext().initialRequestEnded();
        tracingLogger.log("DISPATCH_RESPONSE", jaxrsResponse);
        if (request.getAsyncContext().isSuspended()) {
            /**
             * Callback by the initial calling thread.  This callback will probably do nothing in an asynchronous environment
             * but will be used to simulate AsynchronousResponse in vanilla Servlet containers that do not support
             * asychronous HTTP.
             */
            request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
            // we're handing response asynchronously
            jaxrsResponse = null;
        }
    } catch (CompletionException e) {
        // logger.error("invoke() failed mapping exception", e);
        writeException(request, response, e.getCause(), t -> {
        });
        return;
    } catch (Exception e) {
        // logger.error("invoke() failed mapping exception", e);
        invoker.getMethodStatisticsLogger().incFailureCnt();
        writeException(request, response, e, t -> {
        });
        return;
    }
    if (jaxrsResponse != null) {
        writeResponse(request, response, jaxrsResponse);
    }
}
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) CompletionException(java.util.concurrent.CompletionException) 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 4 with RESTEasyTracingLogger

use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.

the class SynchronousDispatcher method getInvoker.

public ResourceInvoker getInvoker(HttpRequest request) throws Failure {
    LogMessages.LOGGER.pathInfo(request.getUri().getPath());
    if (!request.isInitial()) {
        throw new InternalServerErrorException(Messages.MESSAGES.isNotInitialRequest(request.getUri().getPath()));
    }
    ResourceInvoker invoker = registry.getResourceInvoker(request);
    if (invoker == null) {
        throw new NotFoundException(Messages.MESSAGES.unableToFindJaxRsResource(request.getUri().getPath()));
    }
    RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
    logger.log("MATCH_RESOURCE", invoker);
    logger.log("MATCH_RESOURCE_METHOD", invoker.getMethod());
    return invoker;
}
Also used : InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) NotFoundException(jakarta.ws.rs.NotFoundException) RESTEasyTracingLogger(org.jboss.resteasy.tracing.RESTEasyTracingLogger) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker)

Example 5 with RESTEasyTracingLogger

use of org.jboss.resteasy.tracing.RESTEasyTracingLogger in project resteasy by resteasy.

the class SynchronousDispatcher method execute.

/**
 * Return a response wither from an invoke or exception handling.
 *
 * @param request http request
 * @param response http response
 * @param invoker resource invoker
 * @return response
 */
public Response execute(HttpRequest request, HttpResponse response, ResourceInvoker invoker) {
    Response jaxrsResponse = null;
    try {
        RESTEasyTracingLogger logger = RESTEasyTracingLogger.getInstance(request);
        logger.log("DISPATCH_RESPONSE", jaxrsResponse);
        request.getAsyncContext().initialRequestStarted();
        jaxrsResponse = invoker.invoke(request, response);
        request.getAsyncContext().initialRequestEnded();
        if (request.getAsyncContext().isSuspended()) {
            /**
             * Callback by the initial calling thread.  This callback will probably do nothing in an asynchronous environment
             * but will be used to simulate AsynchronousResponse in vanilla Servlet containers that do not support
             * asychronous HTTP.
             */
            request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
            // we're handing response asynchronously
            jaxrsResponse = null;
        }
    } catch (CompletionException e) {
        // logger.error("invoke() failed mapping exception", e);
        jaxrsResponse = new ExceptionHandler(providerFactory, unwrappedExceptions).handleException(request, e.getCause());
        if (jaxrsResponse == null)
            throw new UnhandledException(e.getCause());
    } catch (Exception e) {
        // logger.error("invoke() failed mapping exception", e);
        jaxrsResponse = new ExceptionHandler(providerFactory, unwrappedExceptions).handleException(request, e);
        if (jaxrsResponse == null)
            throw new UnhandledException(e);
    }
    return jaxrsResponse;
}
Also used : Response(jakarta.ws.rs.core.Response) HttpResponse(org.jboss.resteasy.spi.HttpResponse) BuiltResponse(org.jboss.resteasy.specimpl.BuiltResponse) UnhandledException(org.jboss.resteasy.spi.UnhandledException) CompletionException(java.util.concurrent.CompletionException) 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

RESTEasyTracingLogger (org.jboss.resteasy.tracing.RESTEasyTracingLogger)19 NotFoundException (jakarta.ws.rs.NotFoundException)9 IOException (java.io.IOException)8 BuiltResponse (org.jboss.resteasy.specimpl.BuiltResponse)8 Response (jakarta.ws.rs.core.Response)7 CompletionException (java.util.concurrent.CompletionException)7 HttpResponse (org.jboss.resteasy.spi.HttpResponse)7 InternalServerErrorException (org.jboss.resteasy.spi.InternalServerErrorException)7 UnhandledException (org.jboss.resteasy.spi.UnhandledException)7 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)5 ArrayList (java.util.ArrayList)5 ResourceInvoker (org.jboss.resteasy.spi.ResourceInvoker)5 List (java.util.List)4 PreMatchContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext)4 Dispatcher (org.jboss.resteasy.spi.Dispatcher)4 Failure (org.jboss.resteasy.spi.Failure)4 ResourceContext (jakarta.ws.rs.container.ResourceContext)3 HttpHeaders (jakarta.ws.rs.core.HttpHeaders)3 Request (jakarta.ws.rs.core.Request)3 UriInfo (jakarta.ws.rs.core.UriInfo)3