use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletSingleSignOnAuthenticationMechanism method getSession.
@Override
protected Session getSession(HttpServerExchange exchange) {
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
final HttpSessionImpl session = servletRequestContext.getCurrentServletContext().getSession(exchange, true);
if (System.getSecurityManager() == null) {
return session.getSession();
} else {
return AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class RequestDispatcherImpl method forwardImplSetup.
private void forwardImplSetup(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
final ServletRequestContext servletRequestContext = SecurityActions.currentServletRequestContext();
if (servletRequestContext == null) {
UndertowLogger.REQUEST_LOGGER.debugf("No servlet request context for %s, dispatching mock request", request);
mock(request, response);
return;
}
ThreadSetupAction.Handle handle = null;
ServletContextImpl oldServletContext = null;
HttpSessionImpl oldSession = null;
if (servletRequestContext.getCurrentServletContext() != this.servletContext) {
try {
//cross context request, we need to run the thread setup actions
oldServletContext = servletRequestContext.getCurrentServletContext();
oldSession = servletRequestContext.getSession();
servletRequestContext.setSession(null);
servletRequestContext.setCurrentServletContext(this.servletContext);
this.servletContext.invokeAction(servletRequestContext.getExchange(), new ThreadSetupHandler.Action<Void, Object>() {
@Override
public Void call(HttpServerExchange exchange, Object context) throws Exception {
forwardImpl(request, response, servletRequestContext);
return null;
}
});
} finally {
servletRequestContext.setSession(oldSession);
servletRequestContext.setCurrentServletContext(oldServletContext);
}
} else {
forwardImpl(request, response, servletRequestContext);
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class HttpServletRequestImpl method startAsync.
@Override
public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (!servletContext.getDeployment().getDeploymentInfo().isAllowNonStandardWrappers()) {
if (servletRequestContext.getOriginalRequest() != servletRequest) {
if (!(servletRequest instanceof ServletRequestWrapper)) {
throw UndertowServletMessages.MESSAGES.requestWasNotOriginalOrWrapper(servletRequest);
}
}
if (servletRequestContext.getOriginalResponse() != servletResponse) {
if (!(servletResponse instanceof ServletResponseWrapper)) {
throw UndertowServletMessages.MESSAGES.responseWasNotOriginalOrWrapper(servletResponse);
}
}
}
if (!isAsyncSupported()) {
throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
} else if (asyncStarted) {
throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
}
asyncStarted = true;
return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext);
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class HttpServletRequestImpl method getMapping.
@Override
public Mapping getMapping() {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletPathMatch match = src.getOriginalServletPathMatch();
String matchValue;
switch(match.getMappingMatch()) {
case EXACT:
matchValue = getServletPath();
break;
case DEFAULT:
matchValue = "/";
break;
case CONTEXT_ROOT:
matchValue = "";
break;
case PATH:
matchValue = match.getRemaining();
break;
case EXTENSION:
matchValue = match.getMatched().substring(0, match.getMatched().length() - match.getMatchString().length() + 1);
break;
default:
matchValue = match.getRemaining();
}
return new MappingImpl(matchValue, match.getMatchString(), match.getMappingMatch());
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class HttpServletResponseImpl method doErrorDispatch.
public void doErrorDispatch(int sc, String error) throws IOException {
writer = null;
responseState = ResponseState.NONE;
resetBuffer();
treatAsCommitted = false;
final String location = servletContext.getDeployment().getErrorPages().getErrorLocation(sc);
if (location != null) {
RequestDispatcherImpl requestDispatcher = new RequestDispatcherImpl(location, servletContext);
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
try {
requestDispatcher.error(servletRequestContext, servletRequestContext.getServletRequest(), servletRequestContext.getServletResponse(), exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getCurrentServlet().getManagedServlet().getServletInfo().getName(), error);
} catch (ServletException e) {
throw new RuntimeException(e);
}
} else if (error != null) {
setContentType("text/html");
setCharacterEncoding("UTF-8");
if (servletContext.getDeployment().getDeploymentInfo().isEscapeErrorMessage()) {
getWriter().write("<html><head><title>Error</title></head><body>" + escapeHtml(error) + "</body></html>");
} else {
getWriter().write("<html><head><title>Error</title></head><body>" + error + "</body></html>");
}
getWriter().close();
}
responseDone();
}
Aggregations