Search in sources :

Example 1 with UriRoutingContext

use of org.glassfish.jersey.server.internal.routing.UriRoutingContext in project jersey by jersey.

the class ServerRuntime method process.

/**
     * Process a container request.
     *
     * @param request container request to be processed.
     */
public void process(final ContainerRequest request) {
    TracingUtils.initTracingSupport(tracingConfig, tracingThreshold, request);
    TracingUtils.logStart(request);
    final UriRoutingContext routingContext = request.getUriRoutingContext();
    RequestEventBuilder monitoringEventBuilder = EmptyRequestEventBuilder.INSTANCE;
    RequestEventListener monitoringEventListener = null;
    if (applicationEventListener != null) {
        monitoringEventBuilder = new RequestEventImpl.Builder().setContainerRequest(request).setExtendedUriInfo(routingContext);
        monitoringEventListener = applicationEventListener.onRequest(monitoringEventBuilder.build(RequestEvent.Type.START));
    }
    request.setProcessingProviders(processingProviders);
    final RequestProcessingContext context = new RequestProcessingContext(injectionManager, request, routingContext, monitoringEventBuilder, monitoringEventListener);
    request.checkState();
    final Responder responder = new Responder(context, ServerRuntime.this);
    final RequestScope.Instance requestScopeInstance = requestScope.createInstance();
    // TODO: Will we need EXTERNAL_REQUEST_SCOPE after the injection task?
    final AsyncResponderHolder asyncResponderHolder = new AsyncResponderHolder(responder, externalRequestScope, requestScopeInstance, externalRequestScope.open(injectionManager));
    context.initAsyncContext(asyncResponderHolder);
    requestScope.runInScope(requestScopeInstance, new Runnable() {

        @Override
        public void run() {
            try {
                // for later resolving of relative location URIs
                if (!disableLocationHeaderRelativeUriResolution) {
                    final URI uriToUse = rfc7231LocationHeaderRelativeUriResolution ? request.getRequestUri() : request.getBaseUri();
                    OutboundJaxrsResponse.Builder.setBaseUri(uriToUse);
                }
                final Ref<Endpoint> endpointRef = Refs.emptyRef();
                final RequestProcessingContext data = Stages.process(context, requestProcessingRoot, endpointRef);
                final Endpoint endpoint = endpointRef.get();
                if (endpoint == null) {
                    // not found
                    throw new NotFoundException();
                }
                final ContainerResponse response = endpoint.apply(data);
                if (!asyncResponderHolder.isAsync()) {
                    responder.process(response);
                } else {
                    externalRequestScope.suspend(asyncResponderHolder.externalContext, injectionManager);
                }
            } catch (final Throwable throwable) {
                responder.process(throwable);
            } finally {
                asyncResponderHolder.release();
                // clear base URI from the thread
                OutboundJaxrsResponse.Builder.clearBaseUri();
            }
        }
    });
}
Also used : UriRoutingContext(org.glassfish.jersey.server.internal.routing.UriRoutingContext) NotFoundException(javax.ws.rs.NotFoundException) MessageBodyProviderNotFoundException(org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException) ExternalRequestScope(org.glassfish.jersey.server.spi.ExternalRequestScope) RequestScope(org.glassfish.jersey.process.internal.RequestScope) URI(java.net.URI) RequestProcessingContext(org.glassfish.jersey.server.internal.process.RequestProcessingContext) Ref(org.glassfish.jersey.internal.util.collection.Ref) RequestEventImpl(org.glassfish.jersey.server.internal.monitoring.RequestEventImpl) Endpoint(org.glassfish.jersey.server.internal.process.Endpoint) RequestEventListener(org.glassfish.jersey.server.monitoring.RequestEventListener) RequestEventBuilder(org.glassfish.jersey.server.internal.monitoring.RequestEventBuilder) EmptyRequestEventBuilder(org.glassfish.jersey.server.internal.monitoring.EmptyRequestEventBuilder)

Aggregations

URI (java.net.URI)1 NotFoundException (javax.ws.rs.NotFoundException)1 Ref (org.glassfish.jersey.internal.util.collection.Ref)1 MessageBodyProviderNotFoundException (org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException)1 RequestScope (org.glassfish.jersey.process.internal.RequestScope)1 EmptyRequestEventBuilder (org.glassfish.jersey.server.internal.monitoring.EmptyRequestEventBuilder)1 RequestEventBuilder (org.glassfish.jersey.server.internal.monitoring.RequestEventBuilder)1 RequestEventImpl (org.glassfish.jersey.server.internal.monitoring.RequestEventImpl)1 Endpoint (org.glassfish.jersey.server.internal.process.Endpoint)1 RequestProcessingContext (org.glassfish.jersey.server.internal.process.RequestProcessingContext)1 UriRoutingContext (org.glassfish.jersey.server.internal.routing.UriRoutingContext)1 RequestEventListener (org.glassfish.jersey.server.monitoring.RequestEventListener)1 ExternalRequestScope (org.glassfish.jersey.server.spi.ExternalRequestScope)1