📄 coyoteadapter.java
字号:
/* * $Header: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteAdapter.java,v 1.13.2.3 2003/03/16 01:56:27 billbarker Exp $ * $Revision: 1.13.2.3 $ * $Date: 2003/03/16 01:56:27 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */package org.apache.coyote.tomcat4;import java.io.BufferedInputStream;import java.io.EOFException;import java.io.InterruptedIOException;import java.io.InputStream;import java.io.IOException;import java.io.OutputStream;import java.net.InetAddress;import java.net.Socket;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import java.util.Locale;import java.util.StringTokenizer;import java.util.TreeMap;import javax.servlet.ServletException;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.tomcat.util.buf.ByteChunk;import org.apache.tomcat.util.buf.HexUtils;import org.apache.tomcat.util.buf.MessageBytes;import org.apache.tomcat.util.http.Cookies;import org.apache.tomcat.util.http.ServerCookie;import org.apache.coyote.ActionCode;import org.apache.coyote.ActionHook;import org.apache.coyote.Adapter;import org.apache.coyote.InputBuffer;import org.apache.coyote.OutputBuffer;import org.apache.coyote.Request;import org.apache.coyote.Response;import org.apache.catalina.Connector;import org.apache.catalina.Container;import org.apache.catalina.Globals;import org.apache.catalina.HttpRequest;import org.apache.catalina.HttpResponse;import org.apache.catalina.Lifecycle;import org.apache.catalina.LifecycleEvent;import org.apache.catalina.LifecycleException;import org.apache.catalina.LifecycleListener;import org.apache.catalina.Logger;import org.apache.catalina.util.LifecycleSupport;import org.apache.catalina.util.RequestUtil;import org.apache.catalina.util.StringManager;import org.apache.catalina.util.StringParser;/** * Implementation of a request processor which delegates the processing to a * Coyote processor. * * @author Craig R. McClanahan * @author Remy Maucherat * @version $Revision: 1.13.2.3 $ $Date: 2003/03/16 01:56:27 $ */final class CoyoteAdapter implements Adapter { // -------------------------------------------------------------- Constants public static final int ADAPTER_NOTES = 1; // ----------------------------------------------------------- Constructors /** * Construct a new CoyoteProcessor associated with the specified connector. * * @param connector CoyoteConnector that owns this processor * @param id Identifier of this CoyoteProcessor (unique per connector) */ public CoyoteAdapter(CoyoteConnector connector) { super(); this.connector = connector; this.debug = connector.getDebug(); } // ----------------------------------------------------- Instance Variables /** * The CoyoteConnector with which this processor is associated. */ private CoyoteConnector connector = null; /** * The debugging detail level for this component. */ private int debug = 0; /** * The match string for identifying a session ID parameter. */ private static final String match = ";" + Globals.SESSION_PARAMETER_NAME + "="; /** * The match string for identifying a session ID parameter. */ private static final char[] SESSION_ID = match.toCharArray(); /** * The string manager for this package. */ protected StringManager sm = StringManager.getManager(Constants.Package); // -------------------------------------------------------- Adapter Methods /** * Service method. */ public void service(Request req, Response res) throws Exception { CoyoteRequest request = (CoyoteRequest) req.getNote(ADAPTER_NOTES); CoyoteResponse response = (CoyoteResponse) res.getNote(ADAPTER_NOTES); if (request == null) { // Create objects request = (CoyoteRequest) connector.createRequest(); request.setCoyoteRequest(req); response = (CoyoteResponse) connector.createResponse(); response.setCoyoteResponse(res); // Link objects request.setResponse(response); response.setRequest(request); // Set as notes req.setNote(ADAPTER_NOTES, request); res.setNote(ADAPTER_NOTES, response); } try { // Parse and set Catalina and configuration specific // request parameters postParseRequest(req, request, res, response); // Calling the container connector.getContainer().invoke(request, response); response.finishResponse(); req.action( ActionCode.ACTION_POST_REQUEST , null); } catch (IOException e) { ; } catch (Throwable t) { log(sm.getString("coyoteAdapter.service"), t); } finally { // Recycle the wrapper request and response request.recycle(); response.recycle(); } } // ------------------------------------------------------ Protected Methods /** * Parse additional request parameters. */ protected void postParseRequest(Request req, CoyoteRequest request, Response res, CoyoteResponse response) throws IOException { // XXX the processor needs to set a correct scheme and port prior to this point, // in ajp13 protocols dont make sense to get the port from the connector.. request.setSecure(req.scheme().equals("https")); request.setAuthorization (req.getHeader(Constants.AUTHORIZATION_HEADER)); // FIXME: the code below doesnt belongs to here, this is only have sense // in Http11, not in ajp13.. // At this point the Host header has been processed. // Override if the proxyPort/proxyHost are set String proxyName = connector.getProxyName(); int proxyPort = connector.getProxyPort(); if (proxyPort != 0) { request.setServerPort(proxyPort); req.setServerPort(proxyPort); } else { request.setServerPort(req.getServerPort()); } if (proxyName != null) { request.setServerName(proxyName); req.serverName().setString(proxyName); } else { request.setServerName(req.serverName().toString()); } // URI decoding req.decodedURI().duplicate(req.requestURI()); req.getURLDecoder().convert(req.decodedURI(), false); req.decodedURI().setEncoding("UTF-8"); // Normalize decoded URI if (!normalize(req.decodedURI())) { res.setStatus(400); res.setMessage("Invalid URI"); throw new IOException("Invalid URI"); } // Parse session Id parseSessionId(req, request); // Additional URI normalization and validation is needed for security // reasons on Tomcat 4.0.x if (connector.getUseURIValidationHack()) { String uri = validate(request.getRequestURI()); if (uri == null) { res.setStatus(400); res.setMessage("Invalid URI"); throw new IOException("Invalid URI"); } else { req.requestURI().setString(uri); // Redoing the URI decoding req.decodedURI().duplicate(req.requestURI()); req.getURLDecoder().convert(req.decodedURI(), true); } } // Parse cookies parseCookies(req, request); // Set the SSL properties if( request.isSecure() ) { res.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, request.getCoyoteRequest()); //Set up for getAttributeNames request.getAttribute(Globals.CERTIFICATES_ATTR); request.getAttribute(Globals.CIPHER_SUITE_ATTR); request.getAttribute(Globals.KEY_SIZE_ATTR); } // Set the remote principal String principal = req.getRemoteUser().toString(); if (principal != null) { request.setUserPrincipal(new CoyotePrincipal(principal)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -