Java Code Examples for org.apache.catalina.connector.Request#setAttribute()
The following examples show how to use
org.apache.catalina.connector.Request#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmRouteBinderValve.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Change Request Session id * @param request current request * @param sessionId * original session id * @param newSessionID * new session id for node migration */ protected void changeRequestSessionID(Request request, String sessionId, String newSessionID) { request.changeSessionId(newSessionID); // set original sessionid at request, to allow application detect the // change if (sessionIdAttribute != null && !"".equals(sessionIdAttribute)) { if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.set.orignalsessionid",sessionIdAttribute,sessionId)); } request.setAttribute(sessionIdAttribute, sessionId); } }
Example 2
Source File: ReplicationValve.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Mark Request that processed at primary node with attribute * primaryIndicatorName * * @param request The Servlet request * @throws IOException IO error finding session */ protected void createPrimaryIndicator(Request request) throws IOException { String id = request.getRequestedSessionId(); if ((id != null) && (id.length() > 0)) { Manager manager = request.getContext().getManager(); Session session = manager.findSession(id); if (session instanceof ClusterSession) { ClusterSession cses = (ClusterSession) session; if (log.isDebugEnabled()) { log.debug(sm.getString( "ReplicationValve.session.indicator", request.getContext().getName(),id, primaryIndicatorName, Boolean.valueOf(cses.isPrimarySession()))); } request.setAttribute(primaryIndicatorName, cses.isPrimarySession()?Boolean.TRUE:Boolean.FALSE); } else { if (log.isDebugEnabled()) { if (session != null) { log.debug(sm.getString( "ReplicationValve.session.found", request.getContext().getName(),id)); } else { log.debug(sm.getString( "ReplicationValve.session.invalid", request.getContext().getName(),id)); } } } } }
Example 3
Source File: JvmRouteBinderValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Change Request Session id * @param request current request * @param sessionId * original session id * @param newSessionID * new session id for node migration */ protected void changeRequestSessionID(Request request, String sessionId, String newSessionID) { request.changeSessionId(newSessionID); // set original sessionid at request, to allow application detect the // change if (sessionIdAttribute != null && !"".equals(sessionIdAttribute)) { if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.set.orignalsessionid",sessionIdAttribute,sessionId)); } request.setAttribute(sessionIdAttribute, sessionId); } }
Example 4
Source File: ReplicationValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Mark Request that processed at primary node with attribute * primaryIndicatorName * * @param request * @throws IOException */ protected void createPrimaryIndicator(Request request) throws IOException { String id = request.getRequestedSessionId(); if ((id != null) && (id.length() > 0)) { Manager manager = request.getContext().getManager(); Session session = manager.findSession(id); if (session instanceof ClusterSession) { ClusterSession cses = (ClusterSession) session; if (log.isDebugEnabled()) log.debug(sm.getString( "ReplicationValve.session.indicator", request.getContext().getName(),id, primaryIndicatorName, Boolean.valueOf(cses.isPrimarySession()))); request.setAttribute(primaryIndicatorName, cses.isPrimarySession()?Boolean.TRUE:Boolean.FALSE); } else { if (log.isDebugEnabled()) { if (session != null) { log.debug(sm.getString( "ReplicationValve.session.found", request.getContext().getName(),id)); } else { log.debug(sm.getString( "ReplicationValve.session.invalid", request.getContext().getName(),id)); } } } } }
Example 5
Source File: StandardContextValve.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Select the appropriate child Wrapper to process this request, * based on the specified request URI. If no matching Wrapper can * be found, return an appropriate HTTP error. * * @param request Request to be processed * @param response Response to be produced * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ @Override public final void invoke(Request request, Response response) throws IOException, ServletException { // Disallow any direct access to resources under WEB-INF or META-INF MessageBytes requestPathMB = request.getRequestPathMB(); if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/META-INF")) || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Select the Wrapper to be used for this Request Wrapper wrapper = request.getWrapper(); if (wrapper == null || wrapper.isUnavailable()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Acknowledge the request try { response.sendAcknowledgement(); } catch (IOException ioe) { container.getLogger().error(sm.getString( "standardContextValve.acknowledgeException"), ioe); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } if (request.isAsyncSupported()) { request.setAsyncSupported(wrapper.getPipeline().isAsyncSupported()); } wrapper.getPipeline().getFirst().invoke(request, response); }
Example 6
Source File: JvmRouteBinderValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Change Request Session id * @param request current request * @param sessionId * original session id * @param newSessionID * new session id for node migration */ protected void changeRequestSessionID(Request request, String sessionId, String newSessionID) { request.changeSessionId(newSessionID); // set original sessionid at request, to allow application detect the // change if (sessionIdAttribute != null && !"".equals(sessionIdAttribute)) { if (log.isDebugEnabled()) { log.debug(sm.getString("jvmRoute.set.orignalsessionid",sessionIdAttribute,sessionId)); } request.setAttribute(sessionIdAttribute, sessionId); } }
Example 7
Source File: ReplicationValve.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Mark Request that processed at primary node with attribute * primaryIndicatorName * * @param request * @throws IOException */ protected void createPrimaryIndicator(Request request) throws IOException { String id = request.getRequestedSessionId(); if ((id != null) && (id.length() > 0)) { Manager manager = request.getContext().getManager(); Session session = manager.findSession(id); if (session instanceof ClusterSession) { ClusterSession cses = (ClusterSession) session; if (log.isDebugEnabled()) log.debug(sm.getString( "ReplicationValve.session.indicator", request.getContext().getName(),id, primaryIndicatorName, Boolean.valueOf(cses.isPrimarySession()))); request.setAttribute(primaryIndicatorName, cses.isPrimarySession()?Boolean.TRUE:Boolean.FALSE); } else { if (log.isDebugEnabled()) { if (session != null) { log.debug(sm.getString( "ReplicationValve.session.found", request.getContext().getName(),id)); } else { log.debug(sm.getString( "ReplicationValve.session.invalid", request.getContext().getName(),id)); } } } } }
Example 8
Source File: BSTAuthenticator.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
private boolean isBSTHeaderExists(Request request) throws IOException, XMLStreamException { String bstHeader = this.getBSTHeader(request); if (bstHeader == null || bstHeader.isEmpty()) { return false; } request.setAttribute("BST", bstHeader); return true; }
Example 9
Source File: StandardContextValve.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Select the appropriate child Wrapper to process this request, * based on the specified request URI. If no matching Wrapper can * be found, return an appropriate HTTP error. * * @param request Request to be processed * @param response Response to be produced * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ @Override public final void invoke(Request request, Response response) throws IOException, ServletException { // Disallow any direct access to resources under WEB-INF or META-INF MessageBytes requestPathMB = request.getRequestPathMB(); if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/META-INF")) || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Select the Wrapper to be used for this Request Wrapper wrapper = request.getWrapper(); if (wrapper == null || wrapper.isUnavailable()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Acknowledge the request try { response.sendAcknowledgement(); } catch (IOException ioe) { container.getLogger().error(sm.getString( "standardContextValve.acknowledgeException"), ioe); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } if (request.isAsyncSupported()) { request.setAsyncSupported(wrapper.getPipeline().isAsyncSupported()); } /** * 委托对应的Wrapper去处理请求。 * {@link StandardWrapperValve#invoke(org.apache.catalina.connector.Request, org.apache.catalina.connector.Response)} */ wrapper.getPipeline().getFirst().invoke(request, response); }
Example 10
Source File: StandardContextValve.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Select the appropriate child Wrapper to process this request, * based on the specified request URI. If no matching Wrapper can * be found, return an appropriate HTTP error. * * @param request Request to be processed * @param response Response to be produced * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ @Override public final void invoke(Request request, Response response) throws IOException, ServletException { // Disallow any direct access to resources under WEB-INF or META-INF MessageBytes requestPathMB = request.getRequestPathMB(); if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/META-INF")) || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Select the Wrapper to be used for this Request Wrapper wrapper = request.getWrapper(); if (wrapper == null || wrapper.isUnavailable()) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } // Acknowledge the request try { response.sendAcknowledgement(); } catch (IOException ioe) { container.getLogger().error(sm.getString( "standardContextValve.acknowledgeException"), ioe); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } if (request.isAsyncSupported()) { request.setAsyncSupported(wrapper.getPipeline().isAsyncSupported()); } // 责任链模式:将请求传递给 Wrapper 管道 // 从请求对象中取出该请求关联的 Wrapper(默认情况下是org.apache.catalina.core.StandardWrapper对象), // StandardWrapper对象 初始化的时候会设置基础阀 StandardWrapperValve wrapper.getPipeline().getFirst().invoke(request, response); }
Example 11
Source File: BaseOpenIDConnectAuthenticator.java From tomcat-oidcauth with Apache License 2.0 | 4 votes |
/** * Add request attributes for the login or the login error page. * * @param request The request. * * @throws IOException If an I/O error happens. */ protected void addLoginConfiguration(final Request request) throws IOException { // generate state value and save it in the session final byte[] stateBytes = new byte[16]; this.rand.nextBytes(stateBytes); final String state = HexUtils.toHexString(stateBytes); request.getSessionInternal(true).setNote(SESS_STATE_NOTE, state); // add OP authorization endpoints to the request for the login page final List<AuthEndpointDesc> authEndpoints = new ArrayList<>(); final StringBuilder buf = new StringBuilder(128); for (int i = 0; i < this.opDescs.size(); i++) { final OPDescriptor opDesc = this.opDescs.get(i); // get the OP configuration final String issuer = opDesc.getIssuer(); final OPConfiguration opConfig = this.ops.getOPConfiguration(issuer); // construct the authorization endpoint URL buf.setLength(0); buf.append(opConfig.getAuthorizationEndpoint()); buf.append("?scope=openid"); final String extraScopes = opDesc.getAdditionalScopes(); if (extraScopes != null) buf.append(URLEncoder.encode(" " + extraScopes, UTF8.name())); buf.append("&response_type=code"); buf.append("&client_id=").append(URLEncoder.encode( opDesc.getClientId(), UTF8.name())); buf.append("&redirect_uri=").append(URLEncoder.encode( this.getBaseURL(request) + Constants.FORM_ACTION, UTF8.name())); buf.append("&state=").append(i).append('Z').append(state); final String addlParams = opDesc.getExtraAuthEndpointParams(); if (addlParams != null) buf.append('&').append(addlParams); // add the URL to the map authEndpoints.add(new AuthEndpointDesc( opDesc.getName(), issuer, buf.toString())); } request.setAttribute(AUTHEPS_ATT, authEndpoints); // add no form flag to the request request.setAttribute(NOFORM_ATT, Boolean.valueOf(this.noForm)); }