//we need to redirect in a manner that is indistinguishable from a a direct request
//we can't just use a forward, as these do not have security applied, and
//also the filters that have been applied to the request would be different.
//instead we get the exchange and do a dispatch, and then redirect. This basically acts like
//two seperate servlet requests
final HttpServletRequestImpl requestImpl = ServletRequestContext.requireCurrent().getOriginalRequest();
final HttpServerExchange exchange = requestImpl.getExchange();
if(!exchange.isRequestChannelAvailable()) {
throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
}
exchange.dispatch(SameThreadExecutor.INSTANCE, new Runnable() {
@Override
public void run() {
String path = pathAddition;
if(!exchange.getRelativePath().endsWith("/")) {
path = "/" + path;
}
exchange.getResponseHeaders().clear();
exchange.setResponseCode(200);
exchange.setRelativePath(exchange.getRelativePath() + path);
exchange.setRequestPath(exchange.getRequestPath() + path);
exchange.setRequestURI(exchange.getRequestURI() + path);
HttpHandlers.executeRootHandler(requestImpl.getServletContext().getDeployment().getHandler(), exchange, false);
}
});
}