@Override public AsyncContext get() { return reference.get().asyncContext(); } }
private void release(final ContainerResponse responseContext) { try { processingContext.closeableService().close(); // Commit the container response writer if not in chunked mode // responseContext may be null in case the request processing was cancelled. if (responseContext != null && !responseContext.isChunked()) { // responseContext.commitStream(); responseContext.close(); } } catch (final Throwable throwable) { LOGGER.log(Level.WARNING, LocalizationMessages.RELEASING_REQUEST_PROCESSING_RESOURCES_FAILED(), throwable); } finally { runtime.externalRequestScope.close(); processingContext.triggerEvent(RequestEvent.Type.FINISHED); } } }
private ContainerResponse processResponse(ContainerResponse response) { final Stage<ContainerResponse> respondingRoot = processingContext.createRespondingRoot(); if (respondingRoot != null) { response = Stages.process(response, respondingRoot); } writeResponse(response); // no-exception zone // the methods below are guaranteed to not throw any exceptions completionCallbackRunner.onComplete(null); return response; }
@Override public Continuation apply(final RequestProcessingContext context) { final ContainerRequest request = context.request(); if (HttpMethod.HEAD.equals(request.getMethod())) { request.setMethodWithoutException(HttpMethod.GET); context.push( new Function<ContainerResponse, ContainerResponse>() { @Override public ContainerResponse apply(final ContainerResponse responseContext) { responseContext.getRequestContext().setMethodWithoutException(HttpMethod.HEAD); return responseContext; } } ); } return Continuation.of(context, getMethodRouter(context)); } };
@Override public Continuation apply(final RequestProcessingContext context) { final RoutingContext routingContext = context.routingContext(); final Object storedResource = routingContext.peekMatchedResource(); if (storedResource == null || !storedResource.getClass().equals(methodHandler.getHandlerClass())) { Object handlerInstance = methodHandler.getInstance(context.injectionManager()); routingContext.pushMatchedResource(handlerInstance); } return Continuation.of(context, next); } }
@Override public Continuation apply(final RequestProcessingContext processingContext) { final RoutingContext rc = processingContext.routingContext(); rc.pushMatchResult(new SingleMatchResult("/" + processingContext.request().getPath(false))); return Continuation.of(processingContext, rootRouter); } }
final boolean postMatching = responseFilters == null; final ContainerRequest request = context.request(); new RankedComparator<ContainerRequestFilter>(), rankedProviders); context.monitoringEventBuilder().setContainerRequestFilters(sortedRequestFilters); context.triggerEvent(RequestEvent.Type.REQUEST_MATCHED); context.push(new ResponseFilterStage(context, responseFilters, tracingLogger)); sortedRequestFilters = Providers.sortRankedProviders(new RankedComparator<ContainerRequestFilter>(), requestFilters); context.triggerEvent(RequestEvent.Type.REQUEST_FILTERED);
private Object getResource(final RequestProcessingContext context) { final Object resource = context.routingContext().peekMatchedResource(); final Method handlingMethod = locatorModel.getInvocable().getHandlingMethod(); final Object[] parameterValues = ParameterValueHelper.getParameterValues(valueProviders, context.request()); context.triggerEvent(RequestEvent.Type.LOCATOR_MATCHED); final SecurityContext securityContext = context.request().getSecurityContext(); return (securityContext instanceof SubjectSecurityContext) ? ((SubjectSecurityContext) securityContext).doAsSubject(invokeMethodAction) : invokeMethodAction.run();
final RequestProcessingContext context = new RequestProcessingContext(injectionManager, request, routingContext, new AsyncResponderHolder(responder, externalRequestScope, requestScopeInstance, externalRequestScope.open(injectionManager)); context.initAsyncContext(asyncResponderHolder);
private Response invoke(final RequestProcessingContext context, final Object resource) { context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_START); context.push(response -> { jaxrsResponse = dispatcher.dispatch(resource, context.request()); } finally { context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_FINISHED);
@Override @SuppressWarnings("unchecked") public ContainerResponse apply(final RequestProcessingContext processingContext) { final ContainerRequest request = processingContext.request(); final Object resource = processingContext.routingContext().peekMatchedResource(); if (!processingContext.asyncContext().suspend()) { throw new ProcessingException(LocalizationMessages.ERROR_SUSPENDING_ASYNC_REQUEST()); processingContext.asyncContext().invokeManaged(() -> { final Response response = invoke(processingContext, resource); if (method.isSuspendDeclared()) { if (!processingContext.asyncContext().suspend()) { throw new ProcessingException(LocalizationMessages.ERROR_SUSPENDING_ASYNC_REQUEST());
return reference.get().asyncContext(); }; return reference.get().request(); };
final ContainerRequest request = processingContext.request(); processingContext.monitoringEventBuilder().setException(throwable, RequestEvent.ExceptionCause.ORIGINAL); processingContext.triggerEvent(RequestEvent.Type.ON_EXCEPTION); runtime.rfc7231LocationHeaderRelativeUriResolution); processingContext.monitoringEventBuilder().setContainerResponse(response) .setResponseSuccessfullyMapped(true); } finally { processingContext.triggerEvent(RequestEvent.Type.EXCEPTION_MAPPING_FINISHED); } catch (final Throwable respError) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_PROCESSING_RESPONSE_FROM_ALREADY_MAPPED_EXCEPTION()); processingContext.monitoringEventBuilder() .setException(respError, RequestEvent.ExceptionCause.MAPPED_RESPONSE); processingContext.triggerEvent(RequestEvent.Type.ON_EXCEPTION); throw respError;
processingContext.routingContext().setMappedThrowable(throwable); final ExceptionMapper mapper = runtime.exceptionMappers.findMapping(throwable); if (mapper != null) { processingContext.monitoringEventBuilder().setExceptionMapper(mapper); processingContext.triggerEvent(RequestEvent.Type.EXCEPTION_MAPPER_FOUND); try { final Response mappedResponse = mapper.toResponse(throwable); processingContext.routingContext().setMappedThrowable(throwable);
@Override public ContainerResponse apply( final RequestProcessingContext requestContext) { return new ContainerResponse(requestContext.request(), abortResponse); } }));
@Override public Continuation apply(final RequestProcessingContext context) { context.routingContext().pushMatchedRuntimeResource(resource); return Continuation.of(context); } }
@Override public Continuation apply(final RequestProcessingContext processingContext) { Object subResourceInstance = getResource(processingContext); if (subResourceInstance == null) { throw new NotFoundException(); } final RoutingContext routingContext = processingContext.routingContext(); final LocatorRouting routing; if (subResourceInstance instanceof Resource) { // Caching here is disabled by default. It can be enabled by setting // ServerProperties.SUBRESOURCE_LOCATOR_CACHE_JERSEY_RESOURCE_ENABLED to true. routing = runtimeLocatorBuilder.getRouting((Resource) subResourceInstance); } else { Class<?> locatorClass = subResourceInstance.getClass(); if (locatorClass.isAssignableFrom(Class.class)) { // subResourceInstance is class itself locatorClass = (Class<?>) subResourceInstance; if (!runtimeLocatorBuilder.isCached(locatorClass)) { // If we can't create an instance of the class, don't proceed. subResourceInstance = createFunction.apply(locatorClass); } } routingContext.pushMatchedResource(subResourceInstance); resourceContext.bindResourceIfSingleton(subResourceInstance); routing = runtimeLocatorBuilder.getRouting(locatorClass); } routingContext.pushLocatorSubResource(routing.locator.getResources().get(0)); processingContext.triggerEvent(RequestEvent.Type.SUBRESOURCE_LOCATED); return Continuation.of(processingContext, routing.router); }
processingContext.monitoringEventBuilder().setContainerResponseFilters(sortedResponseFilters); processingContext.triggerEvent(RequestEvent.Type.RESP_FILTERS_START); processingContext.triggerEvent(RequestEvent.Type.RESP_FILTERS_FINISHED); tracingLogger.logDuration(ServerTraceEvent.RESPONSE_FILTER_SUMMARY, timestamp, processedCount);
@Override public CloseableService get() { return reference.get().closeableService(); } }
public void process(ContainerResponse response) { processingContext.monitoringEventBuilder().setContainerResponse(response); response = processResponse(response); release(response); }