当前位置: 首页>>代码示例>>Java>>正文


Java ServletRequestContext类代码示例

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


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


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