use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class TraceSupportTest method configure.
@Override
protected Application configure() {
ResourceConfig config = new ResourceConfig(TracingResource.class);
config.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH_PROGRAMMATIC);
resourceBuilder.addMethod(TRACE.NAME).handledBy(new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(ContainerRequestContext request) {
if (request == null) {
return Response.noContent().build();
} else {
return Response.ok(stringify((ContainerRequest) request), MediaType.TEXT_PLAIN).build();
}
}
});
return config.registerResources(resourceBuilder.build());
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class GrizzlyHttpContainer method service.
@Override
public void service(final Request request, final Response response) {
final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
try {
logger.debugLog("GrizzlyHttpContainer.service(...) started");
URI baseUri = getBaseUri(request);
URI requestUri = getRequestUri(request);
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod().getMethodString(), getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request));
requestContext.setEntityStream(request.getInputStream());
for (final String headerName : request.getHeaderNames()) {
requestContext.headers(headerName, request.getHeaders(headerName));
}
requestContext.setWriter(responseWriter);
requestContext.setRequestScopedInitializer(injectionManager -> {
injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request);
injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response);
});
appHandler.handle(requestContext);
} finally {
logger.debugLog("GrizzlyHttpContainer.service(...) finished");
}
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class JettyHttpContainer method handle.
@Override
public void handle(final String target, final Request request, final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) throws IOException, ServletException {
final Response response = Response.getResponse(httpServletResponse);
final ResponseWriter responseWriter = new ResponseWriter(request, response, configSetStatusOverSendError);
final URI baseUri = getBaseUri(request);
final URI requestUri = getRequestUri(request, baseUri);
try {
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate());
requestContext.setEntityStream(request.getInputStream());
final Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
final String headerName = headerNames.nextElement();
String headerValue = request.getHeader(headerName);
requestContext.headers(headerName, headerValue == null ? "" : headerValue);
}
requestContext.setWriter(responseWriter);
requestContext.setRequestScopedInitializer(injectionManager -> {
injectionManager.<Ref<Request>>getInstance(REQUEST_TYPE).set(request);
injectionManager.<Ref<Response>>getInstance(RESPONSE_TYPE).set(response);
});
// Mark the request as handled before generating the body of the response
request.setHandled(true);
appHandler.handle(requestContext);
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class SimpleContainer method handle.
@Override
public void handle(final Request request, final Response response) {
final ResponseWriter responseWriter = new ResponseWriter(response, scheduler);
final URI baseUri = getBaseUri(request);
final URI requestUri = getRequestUri(request, baseUri);
try {
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate());
requestContext.setEntityStream(request.getInputStream());
for (final String headerName : request.getNames()) {
requestContext.headers(headerName, request.getValue(headerName));
}
requestContext.setWriter(responseWriter);
requestContext.setRequestScopedInitializer(injectionManager -> {
injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request);
injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response);
});
appHandler.handle(requestContext);
} catch (final Exception ex) {
throw new RuntimeException(ex);
} finally {
if (!responseWriter.isSuspended()) {
close(response);
}
}
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class WebComponent method serviceImpl.
/**
* Dispatch client requests to a resource class.
*
* @param baseUri the base URI of the request.
* @param requestUri the URI of the request.
* @param servletRequest the {@link javax.servlet.http.HttpServletRequest} object that
* contains the request the client made to
* the Web component.
* @param servletResponse the {@link javax.servlet.http.HttpServletResponse} object that
* contains the response the Web component returns
* to the client.
* @return returns {@link ResponseWriter}, Servlet's {@link org.glassfish.jersey.server.spi.ContainerResponseWriter}
* implementation, into which processed request response was written to.
* @throws java.io.IOException if an input or output error occurs
* while the Web component is handling the
* HTTP request.
* @throws javax.servlet.ServletException if the HTTP request cannot be handled.
*/
/* package */
ResponseWriter serviceImpl(final URI baseUri, final URI requestUri, final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) throws ServletException, IOException {
final ResponseWriter responseWriter = new ResponseWriter(forwardOn404, configSetStatusOverSendError, servletResponse, asyncExtensionDelegate.createDelegate(servletRequest, servletResponse), backgroundTaskScheduler);
try {
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, servletRequest.getMethod(), getSecurityContext(servletRequest), new ServletPropertiesDelegate(servletRequest));
initContainerRequest(requestContext, servletRequest, servletResponse, responseWriter);
appHandler.handle(requestContext);
} catch (final HeaderValueException hve) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, LocalizationMessages.HEADER_VALUE_READ_FAILED(), hve);
}
final Response.Status status = Response.Status.BAD_REQUEST;
if (configSetStatusOverSendError) {
servletResponse.reset();
//noinspection deprecation
servletResponse.setStatus(status.getStatusCode(), status.getReasonPhrase());
} else {
servletResponse.sendError(status.getStatusCode(), status.getReasonPhrase());
}
} catch (final Exception e) {
throw new ServletException(e);
}
return responseWriter;
}
Aggregations