• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ServletRequestContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.undertow.servlet.handlers.ServletRequestContext的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestContext类的具体用法?Java ServletRequestContext怎么用?Java ServletRequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ServletRequestContext类属于io.undertow.servlet.handlers包,在下文中一共展示了ServletRequestContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readAttribute

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
    ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (context != null) {
        ServletRequest req = context.getServletRequest();
        if (req instanceof HttpServletRequest) {
            HttpSession session = ((HttpServletRequest) req).getSession(false);
            if (session != null) {
                Object result = session.getAttribute(attributeName);
                if (result != null) {
                    return result.toString();
                }
            }
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletSessionAttribute.java


示例2: handleRequest

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
/**
 * Only allow the request through if successfully authenticated or if authentication is not required.
 *
 * @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
 */
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if(exchange.isInIoThread()) {
        exchange.dispatch(this);
        return;
    }
    SecurityContext context = exchange.getSecurityContext();
    if (context.authenticate()) {
        if(!exchange.isComplete()) {
           next.handleRequest(exchange);
        }
    } else {
        if(exchange.getResponseCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
            ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
            src.getOriginalResponse().sendError(exchange.getResponseCode());
        } else {
            exchange.endExchange();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ServletAuthenticationCallHandler.java


示例3: 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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ServletSecurityRoleHandler.java


示例4: readAttribute

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
    ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if(src == null) {
        return RequestURLAttribute.INSTANCE.readAttribute(exchange);
    }
    String path = (String) src.getServletRequest().getAttribute(RequestDispatcher.FORWARD_PATH_INFO);
    String sp = (String) src.getServletRequest().getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
    if(path == null && sp == null) {
        return RequestURLAttribute.INSTANCE.readAttribute(exchange);
    }
    if(sp == null) {
        return path;
    } else if(path == null) {
        return sp;
    } else {
        return sp + path;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:ServletRelativePathAttribute.java


示例5: setCharacterEncoding

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public void setCharacterEncoding(final String env) throws UnsupportedEncodingException {
    if (readStarted) {
        return;
    }
    try {
        characterEncoding = Charset.forName(env);

        final ManagedServlet originalServlet = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getOriginalServletPathMatch().getServletChain().getManagedServlet();
        final FormDataParser parser = originalServlet.getFormParserFactory().createParser(exchange);
        if (parser != null) {
            parser.setCharacterEncoding(env);
        }
    } catch (UnsupportedCharsetException e) {
        throw new UnsupportedEncodingException();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpServletRequestImpl.java


示例6: parseFormData

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
private FormData parseFormData() {
    if (parsedFormData == null) {
        if (readStarted) {
            return null;
        }
        final ManagedServlet originalServlet = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getCurrentServlet().getManagedServlet();
        final FormDataParser parser = originalServlet.getFormParserFactory().createParser(exchange);
        if (parser == null) {
            return null;
        }
        readStarted = true;
        try {
            return parsedFormData = parser.parseBlocking();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return parsedFormData;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HttpServletRequestImpl.java


示例7: startAsync

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HttpServletRequestImpl.java


示例8: forSession

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
public static HttpSessionImpl forSession(final Session session, final ServletContext servletContext, final boolean newSession) {
    // forSession is called by privileged actions only so no need to do it again
    ServletRequestContext current = ServletRequestContext.current();
    if (current == null) {
        return new HttpSessionImpl(session, servletContext, newSession, null);
    } else {
        HttpSessionImpl httpSession = current.getSession();
        if (httpSession == null) {
            httpSession = new HttpSessionImpl(session, servletContext, newSession, current);
            current.setSession(httpSession);
        } else {
            if(httpSession.session != session) {
                //in some rare cases it may be that there are two different service contexts involved in the one request
                //in this case we just return a new session rather than using the thread local version
                httpSession = new HttpSessionImpl(session, servletContext, newSession, current);
            }
        }
        return httpSession;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:HttpSessionImpl.java


示例9: AsyncContextImpl

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
public AsyncContextImpl(final HttpServerExchange exchange, final ServletRequest servletRequest, final ServletResponse servletResponse, final ServletRequestContext servletRequestContext, boolean requestSupplied, final AsyncContextImpl previousAsyncContext) {
    this.exchange = exchange;
    this.servletRequest = servletRequest;
    this.servletResponse = servletResponse;
    this.servletRequestContext = servletRequestContext;
    this.requestSupplied = requestSupplied;
    this.previousAsyncContext = previousAsyncContext;
    initiatingThread = Thread.currentThread();
    exchange.dispatch(SameThreadExecutor.INSTANCE, new Runnable() {
        @Override
        public void run() {
            exchange.setDispatchExecutor(null);
            initialRequestDone();
        }
    });
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AsyncContextImpl.java


示例10: sendError

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public void sendError(final int sc, final String msg) throws IOException {
    if(insideInclude) {
        //not 100% sure this is the correct action
        return;
    }
    if (responseStarted()) {
        throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
    }
    writer = null;
    responseState = ResponseState.NONE;
    exchange.setResponseCode(sc);
    ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if(src.isRunningInsideHandler()) {
        //all we do is set the error on the context, we handle it when the request is returned
        treatAsCommitted = true;
        src.setError(sc, msg);
    } else {
        //if the src is null there is no outer handler, as we are in an asnc request
        doErrorDispatch(sc, msg);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:HttpServletResponseImpl.java


示例11: doErrorDispatch

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
public void doErrorDispatch(int sc, String error) throws IOException {
    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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HttpServletResponseImpl.java


示例12: isAuthenticationRequired

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
protected boolean isAuthenticationRequired(final HttpServerExchange exchange) {
    List<SingleConstraintMatch> constraints = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getRequiredConstrains();

    /*
     * Even once this is set to true the reason we allow the loop to continue is in case an empty role with a semantic of
     * deny is found as that will override everything.
     */
    boolean authenticationRequired = false;
    for (SingleConstraintMatch constraint : constraints) {
        if (constraint.getRequiredRoles().isEmpty()) {
            if (constraint.getEmptyRoleSemantic() == EmptyRoleSemantic.DENY) {
                /*
                 * For this case we return false as we know it can never be satisfied.
                 */
                return false;
            } else if (constraint.getEmptyRoleSemantic() == EmptyRoleSemantic.AUTHENTICATE) {
                authenticationRequired = true;
            }
        } else {
            authenticationRequired = true;
        }
    }

    return authenticationRequired;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:ServletAuthenticationConstraintHandler.java


示例13: handleRequest

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    ServletRequest request = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getServletRequest();
    SSLSessionInfo ssl = exchange.getConnection().getSslSessionInfo();
    if (ssl != null) {
        request.setAttribute("javax.servlet.request.cipher_suite", ssl.getCipherSuite());
        request.setAttribute("javax.servlet.request.key_size", getKeyLength(ssl.getCipherSuite()));
        request.setAttribute("javax.servlet.request.ssl_session_id", ssl.getSessionId());
        X509Certificate[] certs = getCerts(ssl);
        if (certs != null) {
            request.setAttribute("javax.servlet.request.X509Certificate", certs);
        }

    }
    next.handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SSLInformationAssociationHandler.java


示例14: 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);
            }
        }
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:ServletFormAuthenticationMechanism.java


示例15: handleRequest

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    final String path = exchange.getRelativePath();
    SecurityPathMatch securityMatch = securityPathMatches.getSecurityInfo(path, exchange.getRequestMethod().toString());
    final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    List<SingleConstraintMatch> list = servletRequestContext.getRequiredConstrains();
    if (list == null) {
        servletRequestContext.setRequiredConstrains(list = new ArrayList<>());
    }
    list.add(securityMatch.getMergedConstraint());
    TransportGuaranteeType type = servletRequestContext.getTransportGuarenteeType();
    if (type == null || type.ordinal() < securityMatch.getTransportGuaranteeType().ordinal()) {
        servletRequestContext.setTransportGuarenteeType(securityMatch.getTransportGuaranteeType());
    }
    next.handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ServletSecurityConstraintHandler.java


示例16: getSender

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public Sender getSender() {
    try {
        return new BlockingSenderImpl(exchange, getOutputStream());
    } catch (IllegalStateException e) {
        ServletResponse response = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getServletResponse();
        try {
            return new BlockingWriterSenderImpl(exchange, response.getWriter(), response.getCharacterEncoding());
        } catch (IOException e1) {
            throw new RuntimeException(e1);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ServletBlockingHttpExchange.java


示例17: 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;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:SsoHandler.java


示例18: requireCurrentServletRequestContext

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
static ServletRequestContext requireCurrentServletRequestContext() {
    if (System.getSecurityManager() == null) {
        return ServletRequestContext.requireCurrent();
    } else {
        return AccessController.doPrivileged(new PrivilegedAction<ServletRequestContext>() {
            @Override
            public ServletRequestContext run() {
                return ServletRequestContext.requireCurrent();
            }
        });
    }
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:13,代码来源:JbootResourceServlet.java


示例19: writeAttribute

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
    ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (context != null) {
        ServletRequest req = context.getServletRequest();
        if (req instanceof HttpServletRequest) {
            HttpSession session = ((HttpServletRequest) req).getSession(false);
            if (session != null) {
                session.setAttribute(attributeName, newValue);
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ServletSessionAttribute.java


示例20: readAttribute

import io.undertow.servlet.handlers.ServletRequestContext; //导入依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
    ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    if (context != null) {
        ServletRequest req = context.getServletRequest();
        if (req instanceof HttpServletRequest) {
            HttpSession session = ((HttpServletRequest) req).getSession(false);
            if (session != null) {
                return session.getId();
            }
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ServletSessionIdAttribute.java



注:本文中的io.undertow.servlet.handlers.ServletRequestContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SubmittedReportInfo类代码示例发布时间:2022-05-22
下一篇:
Java NoSuchStatementException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap