本文整理汇总了Java中javax.servlet.ServletRequest.getDispatcherType方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getDispatcherType方法的具体用法?Java ServletRequest.getDispatcherType怎么用?Java ServletRequest.getDispatcherType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getDispatcherType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletRequest request = servletRequestContext.getServletRequest();
if (request.getDispatcherType() == DispatcherType.REQUEST) {
List<SingleConstraintMatch> constraints = servletRequestContext.getRequiredConstrains();
SecurityContext sc = exchange.getSecurityContext();
if (!authorizationManager.canAccessResource(constraints, sc.getAuthenticatedAccount(), servletRequestContext.getCurrentServlet().getManagedServlet().getServletInfo(), servletRequestContext.getOriginalRequest(), servletRequestContext.getDeployment())) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
}
next.handleRequest(exchange);
}
示例2: service
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
@Override
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException {
if (DispatcherType.ASYNC != req.getDispatcherType()) {
AsyncContext asyncContext;
if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
asyncContext = req.startAsync(
new ServletRequestWrapper(req),
new ServletResponseWrapper(resp));
} else {
asyncContext = req.startAsync();
}
if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
asyncContext.dispatch();
} else {
asyncContext.dispatch("/target");
}
try {
asyncContext.dispatch("/nonExistingServlet");
TestAsyncContextImpl.track("FAIL");
} catch (IllegalStateException e) {
TestAsyncContextImpl.track("OK");
}
} else {
TestAsyncContextImpl.track("DispatchingGenericServletGet-");
}
}
示例3: handleFirstRequest
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
public void handleFirstRequest(final HttpServerExchange exchange, final ServletChain servletChain, final ServletRequestContext servletRequestContext, final ServletRequest request, final ServletResponse response) throws Exception {
ThreadSetupAction.Handle handle = setupAction.setup(exchange);
try {
servletRequestContext.setRunningInsideHandler(true);
try {
listeners.requestInitialized(request);
next.handleRequest(exchange);
//
if(servletRequestContext.getErrorCode() > 0) {
servletRequestContext.getOriginalResponse().doErrorDispatch(servletRequestContext.getErrorCode(), servletRequestContext.getErrorMessage());
}
} catch (Throwable t) {
//by default this will just log the exception
boolean handled = exceptionHandler.handleThrowable(exchange, request, response, t);
if(handled) {
exchange.endExchange();
} else if (request.isAsyncStarted() || request.getDispatcherType() == DispatcherType.ASYNC) {
exchange.unDispatch();
servletRequestContext.getOriginalRequest().getAsyncContextInternal().handleError(t);
} else {
if (!exchange.isResponseStarted()) {
response.reset(); //reset the response
exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.getResponseHeaders().clear();
String location = servletContext.getDeployment().getErrorPages().getErrorLocation(t);
if (location == null) {
location = servletContext.getDeployment().getErrorPages().getErrorLocation(StatusCodes.INTERNAL_SERVER_ERROR);
}
if (location != null) {
RequestDispatcherImpl dispatcher = new RequestDispatcherImpl(location, servletContext);
try {
dispatcher.error(servletRequestContext, request, response, servletChain.getManagedServlet().getServletInfo().getName(), t);
} catch (Exception e) {
UndertowLogger.REQUEST_LOGGER.exceptionGeneratingErrorPage(e, location);
}
} else {
if (servletRequestContext.displayStackTraces()) {
ServletDebugPageHandler.handleRequest(exchange, servletRequestContext, t);
} else {
servletRequestContext.getOriginalResponse().doErrorDispatch(StatusCodes.INTERNAL_SERVER_ERROR, StatusCodes.INTERNAL_SERVER_ERROR_STRING);
}
}
}
}
} finally {
servletRequestContext.setRunningInsideHandler(false);
listeners.requestDestroyed(request);
}
//if it is not dispatched and is not a mock request
if (!exchange.isDispatched() && !(exchange.getConnection() instanceof MockServerConnection)) {
servletRequestContext.getOriginalResponse().responseDone();
servletRequestContext.getOriginalRequest().clearAttributes();
}
if(!exchange.isDispatched()) {
AsyncContextImpl ctx = servletRequestContext.getOriginalRequest().getAsyncContextInternal();
if(ctx != null) {
ctx.complete();
}
}
} finally {
handle.tearDown();
}
}