Search in sources :

Example 11 with Request

use of jakarta.ws.rs.core.Request in project opentelemetry-java-instrumentation by open-telemetry.

the class JerseySpanName method get.

@Override
@Nullable
public String get(Context context, Request request) {
    ContainerRequest containerRequest = (ContainerRequest) request;
    UriInfo uriInfo = containerRequest.getUriInfo();
    ExtendedUriInfo extendedUriInfo = (ExtendedUriInfo) uriInfo;
    return extendedUriInfo.getMatchedTemplates().stream().map((uriTemplate) -> normalizePath(uriTemplate.getTemplate())).reduce((a, b) -> b + a).map(s -> ServletContextPath.prepend(context, JaxrsContextPath.prepend(context, s))).orElse(null);
}
Also used : Context(io.opentelemetry.context.Context) HttpRouteSource(io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource) JaxrsContextPath(io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath) ServletContextPath(io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath) Request(jakarta.ws.rs.core.Request) UriInfo(jakarta.ws.rs.core.UriInfo) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) JaxrsPathUtil.normalizePath(io.opentelemetry.javaagent.instrumentation.jaxrs.JaxrsPathUtil.normalizePath) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo) HttpRouteHolder(io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder) Nullable(javax.annotation.Nullable) HttpRouteGetter(io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) UriInfo(jakarta.ws.rs.core.UriInfo) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo) Nullable(javax.annotation.Nullable)

Example 12 with Request

use of jakarta.ws.rs.core.Request in project che-server by eclipse-che.

the class EverrestDownloadFileResponseFilter method doFilter.

/**
 * Filter the given container response.
 *
 * @param containerResponse the response to use
 */
public void doFilter(GenericContainerResponse containerResponse) {
    containerResponse.getResponse();
    // Get the request
    ApplicationContext applicationContext = ApplicationContext.getCurrent();
    Request request = applicationContext.getRequest();
    // Apply header if all if correct
    String filename = getFileName(request, containerResponse.getContentType(), applicationContext, containerResponse.getStatus());
    if (filename != null) {
        if (hasCompliantEntity(containerResponse.getEntity())) {
            // it has been changed, so send response with updated header
            Response.ResponseBuilder responseBuilder = Response.fromResponse(containerResponse.getResponse()).header(CONTENT_DISPOSITION, "attachment; filename=" + filename);
            containerResponse.setResponse(responseBuilder.build());
        }
    }
}
Also used : GenericContainerResponse(org.everrest.core.GenericContainerResponse) Response(jakarta.ws.rs.core.Response) ApplicationContext(org.everrest.core.ApplicationContext) Request(jakarta.ws.rs.core.Request)

Example 13 with Request

use of jakarta.ws.rs.core.Request 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)

Example 14 with Request

use of jakarta.ws.rs.core.Request in project resteasy by resteasy.

the class SynchronousDispatcher method invoke.

public void invoke(HttpRequest request, HttpResponse response) {
    RESTEasyTracingLogger.initTracingSupport(providerFactory, request);
    RESTEasyTracingLogger.logStart(request);
    try {
        pushContextObjects(request, response);
        preprocess(request, response, () -> {
            ResourceInvoker invoker = null;
            try {
                try {
                    invoker = getInvoker(request);
                } catch (Exception exception) {
                    // logger.error("getInvoker() failed mapping exception", exception);
                    writeException(request, response, exception, t -> {
                    });
                    return;
                }
                invoke(request, response, invoker);
            } finally {
                // we're probably clearing it twice but still required
                clearContextData();
            }
        });
    } finally {
        clearContextData();
    }
}
Also used : 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) ResourceInvoker(org.jboss.resteasy.spi.ResourceInvoker) 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 15 with Request

use of jakarta.ws.rs.core.Request in project resteasy by resteasy.

the class SynchronousDispatcher method writeResponse.

protected void writeResponse(HttpRequest request, HttpResponse response, Response jaxrsResponse) {
    try {
        ServerResponseWriter.writeNomapResponse((BuiltResponse) jaxrsResponse, request, response, providerFactory, t -> {
            if (t != null) {
                // if we're async we can't trust UnhandledException to be caught
                if (request.getAsyncContext().isSuspended() && !request.getAsyncContext().isOnInitialRequest()) {
                    try {
                        writeException(request, response, t, t2 -> {
                        });
                    } catch (Throwable ex) {
                        unhandledAsynchronousException(response, ex);
                    }
                } else {
                    rethrow(t);
                }
            }
        });
    } catch (Exception e) {
        // logger.error("writeResponse() failed mapping exception", e);
        writeException(request, response, e, t -> {
        });
    } finally {
        RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
        tracingLogger.log("FINISHED", response.getStatus());
        tracingLogger.flush(response.getOutputHeaders());
    }
}
Also used : 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) 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

Request (jakarta.ws.rs.core.Request)16 Response (jakarta.ws.rs.core.Response)11 UriInfo (jakarta.ws.rs.core.UriInfo)9 List (java.util.List)9 HttpHeaders (jakarta.ws.rs.core.HttpHeaders)8 Map (java.util.Map)8 NotFoundException (jakarta.ws.rs.NotFoundException)7 IOException (java.io.IOException)7 ResourceContext (jakarta.ws.rs.container.ResourceContext)6 Providers (jakarta.ws.rs.ext.Providers)6 HashMap (java.util.HashMap)6 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 CompletionException (java.util.concurrent.CompletionException)4 Consumer (java.util.function.Consumer)4 PreMatchContainerRequestContext (org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext)4 Cleanable (org.jboss.resteasy.plugins.server.Cleanable)4