use of io.undertow.servlet.spec.HttpServletRequestImpl in project undertow by undertow-io.
the class ServletBlockingHttpExchange method close.
@Override
public void close() throws IOException {
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (!exchange.isComplete()) {
try {
HttpServletRequestImpl request = servletRequestContext.getOriginalRequest();
request.closeAndDrainRequest();
} finally {
HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.closeStreamAndWriter();
}
} else {
try {
HttpServletRequestImpl request = servletRequestContext.getOriginalRequest();
request.freeResources();
} finally {
HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.freeResources();
}
}
}
use of io.undertow.servlet.spec.HttpServletRequestImpl in project undertow by undertow-io.
the class ServletInitialHandler method dispatchMockRequest.
@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
final DefaultByteBufferPool bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
MockServerConnection connection = new MockServerConnection(bufferPool);
HttpServerExchange exchange = new HttpServerExchange(connection);
exchange.setRequestScheme(request.getScheme());
exchange.setRequestMethod(new HttpString(request.getMethod()));
exchange.setProtocol(Protocols.HTTP_1_0);
exchange.setResolvedPath(request.getContextPath());
String relative;
if (request.getPathInfo() == null) {
relative = request.getServletPath();
} else {
relative = request.getServletPath() + request.getPathInfo();
}
exchange.setRelativePath(relative);
final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
servletRequestContext.setServletRequest(request);
servletRequestContext.setServletResponse(response);
//set the max request size if applicable
if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
}
exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);
exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
servletRequestContext.setServletPathMatch(info);
try {
dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new ServletException(e);
}
}
use of io.undertow.servlet.spec.HttpServletRequestImpl in project cxf by apache.
the class UndertowHTTPHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange undertowExchange) throws Exception {
try {
// perform blocking operation on exchange
if (undertowExchange.isInIoThread()) {
undertowExchange.dispatch(this);
return;
}
HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, (ServletContextImpl) servletContext);
HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, (ServletContextImpl) servletContext);
ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl) servletContext).getDeployment(), request, response, null);
undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);
request.setAttribute("HTTP_HANDLER", this);
request.setAttribute("UNDERTOW_DESTINATION", undertowHTTPDestination);
SSLSessionInfo ssl = undertowExchange.getConnection().getSslSessionInfo();
if (ssl != null) {
request.setAttribute(SSL_CIPHER_SUITE_ATTRIBUTE, ssl.getCipherSuite());
try {
request.setAttribute(SSL_PEER_CERT_CHAIN_ATTRIBUTE, ssl.getPeerCertificates());
} catch (Exception e) {
// for some case won't have the peer certification
// do nothing
}
}
undertowHTTPDestination.doService(servletContext, request, response);
} catch (Throwable t) {
t.printStackTrace();
if (undertowExchange.isResponseChannelAvailable()) {
undertowExchange.setStatusCode(500);
final String errorPage = "<html><head><title>Error</title>" + "</head><body>Internal Error 500" + t.getMessage() + "</body></html>";
undertowExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, "" + errorPage.length());
undertowExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html");
Sender sender = undertowExchange.getResponseSender();
sender.send(errorPage);
}
}
}
Aggregations