本文整理汇总了Java中io.undertow.servlet.handlers.ServletRequestContext.getServletResponse方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestContext.getServletResponse方法的具体用法?Java ServletRequestContext.getServletResponse怎么用?Java ServletRequestContext.getServletResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.servlet.handlers.ServletRequestContext
的用法示例。
在下文中一共展示了ServletRequestContext.getServletResponse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的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: handleRedirectBack
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
@Override
protected void handleRedirectBack(final HttpServerExchange exchange) {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpServletResponse resp = (HttpServletResponse) servletRequestContext.getServletResponse();
HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, false);
if (httpSession != null) {
Session session;
if (System.getSecurityManager() == null) {
session = httpSession.getSession();
} else {
session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
}
String path = (String) session.getAttribute(SESSION_KEY);
if (path != null) {
try {
resp.sendRedirect(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
示例3: serveLoginPage
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
/**
* Forward to the login page with a specific error message. Avoids a redirect. Based on the
* ServletFormAuthenticationMechanism method. The location should be relative to the current
* context and start with "/" e.g. /login.jsp
*
* @throws IOException
* @throws ServletException
*/
protected Integer serveLoginPage(final HttpServerExchange exchange, final String location) throws ServletException,
IOException {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpServletRequest request = (HttpServletRequest) context.getServletRequest();
HttpServletResponse response = (HttpServletResponse) context.getServletResponse();
exchange.getResponseHeaders().add(Headers.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
exchange.getResponseHeaders().add(Headers.PRAGMA, "no-cache");
exchange.getResponseHeaders().add(Headers.EXPIRES, "0");
request.getRequestDispatcher(location).forward(request, response);
return null;
}
示例4: startAsync
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
@Override
public AsyncContext startAsync() throws IllegalStateException {
if (!isAsyncSupported()) {
throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
} else if (asyncStarted) {
throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
}
asyncStarted = true;
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
return asyncContext = new AsyncContextImpl(exchange, servletRequestContext.getServletRequest(), servletRequestContext.getServletResponse(), servletRequestContext, false, asyncContext);
}
示例5: handleRequest
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
final AuthorizationManager authorizationManager = servletRequestContext.getDeployment().getDeploymentInfo().getAuthorizationManager();
TransportGuaranteeType connectionGuarantee = servletRequestContext.getOriginalRequest().isSecure() ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE;
TransportGuaranteeType transportGuarantee = authorizationManager.transportGuarantee(connectionGuarantee,
servletRequestContext.getTransportGuarenteeType(), servletRequestContext.getOriginalRequest());
servletRequestContext.setTransportGuarenteeType(transportGuarantee);
if (TransportGuaranteeType.REJECTED == transportGuarantee) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
super.handleRequest(exchange);
}
示例6: extractHttpServletResponse
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
/**
* Extracts the HTTP servlet response from the HTTP server exchange.
*
* @param exchange the HTTP server exchange.
* @return the HTTP servlet response.
*/
private static HttpServletResponse extractHttpServletResponse(HttpServerExchange exchange) {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
return (HttpServletResponse) context.getServletResponse();
}