📄 coyoterequest.java
字号:
/*
* Copyright 1999-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.coyote.tomcat4;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.catalina.Connector;
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
import org.apache.catalina.HttpRequest;
import org.apache.catalina.Manager;
import org.apache.catalina.Realm;
import org.apache.catalina.Session;
import org.apache.catalina.Wrapper;
import org.apache.catalina.util.Enumerator;
import org.apache.catalina.util.ParameterMap;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.util.StringManager;
import org.apache.catalina.util.StringParser;
import org.apache.coyote.ActionCode;
import org.apache.coyote.Request;
import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.http.Parameters;
/**
* Wrapper object for the Coyote request.
*
* @author Remy Maucherat
* @author Craig R. McClanahan
* @version $Revision: 392357 $ $Date: 2006-04-07 14:28:19 -0400 (Fri, 07 Apr 2006) $
*/
public class CoyoteRequest
implements HttpRequest, HttpServletRequest {
// --------------------------------------- PrivilegedGetSession Inner Class
protected class PrivilegedGetSession
implements PrivilegedAction {
private boolean create;
PrivilegedGetSession(boolean create) {
this.create = create;
}
public Object run() {
return doGetSession(create);
}
}
// ------------------------------------------------------------- Properties
/**
* Coyote request.
*/
protected Request coyoteRequest;
/**
* Set the Coyote request.
*
* @param coyoteRequest The Coyote request
*/
public void setCoyoteRequest(Request coyoteRequest) {
this.coyoteRequest = coyoteRequest;
inputStream.setRequest(coyoteRequest);
}
/**
* Get the Coyote request.
*/
public Request getCoyoteRequest() {
return (this.coyoteRequest);
}
// ----------------------------------------------------- Instance Variables
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
/**
* The set of cookies associated with this Request.
*/
protected Cookie[] cookies = null;
/**
* The set of SimpleDateFormat formats to use in getDateHeader().
*/
protected SimpleDateFormat formats[] = {
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
};
/**
* The default Locale if none are specified.
*/
protected static Locale defaultLocale = Locale.getDefault();
/**
* The attributes associated with this Request, keyed by attribute name.
*/
protected HashMap attributes = new HashMap();
/**
* The preferred Locales assocaited with this Request.
*/
protected ArrayList locales = new ArrayList();
/**
* Internal notes associated with this request by Catalina components
* and event listeners.
*/
private transient HashMap notes = new HashMap();
/**
* Authentication type.
*/
protected String authType = null;
/**
* Reader.
* Note: At the moment, no attempt is being made at recycling the reader,
* but this could be implemented in the future, using a design like the one
* used for the output buffer.
*/
protected BufferedReader reader = null;
/**
* ServletInputStream.
*/
protected CoyoteInputStream inputStream = new CoyoteInputStream();
/**
* Using stream flag.
*/
protected boolean usingInputStream = false;
/**
* Using writer flag.
*/
protected boolean usingReader = false;
/**
* Context path.
*/
protected String contextPath = "";
/**
* Path info.
*/
protected String pathInfo = null;
/**
* Servlet path.
*/
protected String servletPath = null;
/**
* User principal.
*/
protected Principal userPrincipal = null;
/**
* Session parsed flag.
*/
protected boolean sessionParsed = false;
/**
* Request parameters parsed flag.
*/
protected boolean requestParametersParsed = false;
/**
* Secure flag.
*/
protected boolean secure = false;
/**
* Post data buffer.
*/
protected static int CACHED_POST_LEN = 8192;
protected byte[] postData = null;
/**
* Hash map used in the getParametersMap method.
*/
protected ParameterMap parameterMap = new ParameterMap();
/**
* The currently active session for this request.
*/
protected Session session = null;
/**
* Was the requested session ID received in a cookie?
*/
protected boolean requestedSessionCookie = false;
/**
* The requested session ID (if any) for this request.
*/
protected String requestedSessionId = null;
/**
* Was the requested session ID received in a URL?
*/
protected boolean requestedSessionURL = false;
/**
* The socket through which this Request was received.
*/
protected Socket socket = null;
/**
* Parse locales.
*/
protected boolean localesParsed = false;
/**
* The string parser we will use for parsing request lines.
*/
private StringParser parser = new StringParser();
/**
* Remote address.
*/
protected String remoteAddr = null;
/**
* Remote host.
*/
protected String remoteHost = null;
// --------------------------------------------------------- Public Methods
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
public void recycle() {
context = null;
wrapper = null;
authorization = null;
authType = null;
usingInputStream = false;
usingReader = false;
contextPath = "";
pathInfo = null;
servletPath = null;
reader = null;
inputStream.recycle();
userPrincipal = null;
sessionParsed = false;
authorization = null;
requestParametersParsed = false;
locales.clear();
localesParsed = false;
secure = false;
remoteAddr = null;
remoteHost = null;
attributes.clear();
notes.clear();
cookies = null;
session = null;
requestedSessionCookie = false;
requestedSessionId = null;
requestedSessionURL = false;
parameterMap.setLocked(false);
parameterMap.clear();
if (facade != null) {
facade.clear();
facade = null;
}
}
// -------------------------------------------------------- Request Methods
/**
* The authorization credentials sent with this Request.
*/
protected String authorization = null;
/**
* Return the authorization credentials sent with this request.
*/
public String getAuthorization() {
return (this.authorization);
}
/**
* Set the authorization credentials sent with this request.
*
* @param authorization The new authorization credentials
*/
public void setAuthorization(String authorization) {
this.authorization = authorization;
}
/**
* Associated Catalina connector.
*/
protected CoyoteConnector connector;
/**
* Return the Connector through which this Request was received.
*/
public Connector getConnector() {
return (this.connector);
}
/**
* Set the Connector through which this Request was received.
*
* @param connector The new connector
*/
public void setConnector(Connector connector) {
this.connector = (CoyoteConnector) connector;
}
/**
* The Context within which this Request is being processed.
*/
protected Context context = null;
/**
* Return the Context within which this Request is being processed.
*/
public Context getContext() {
return (this.context);
}
/**
* Set the Context within which this Request is being processed. This
* must be called as soon as the appropriate Context is identified, because
* it identifies the value to be returned by <code>getContextPath()</code>,
* and thus enables parsing of the request URI.
*
* @param context The newly associated Context
*/
public void setContext(Context context) {
this.context = context;
}
/**
* Descriptive information about this Request implementation.
*/
protected static final String info =
"org.apache.coyote.catalina.CoyoteRequest/1.0";
/**
* Return descriptive information about this Request implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (info);
}
/**
* The facade associated with this request.
*/
protected CoyoteRequestFacade facade = null;
/**
* Return the <code>ServletRequest</code> for which this object
* is the facade. This method must be implemented by a subclass.
*/
public ServletRequest getRequest() {
if (facade == null) {
facade = new CoyoteRequestFacade(this);
}
return (facade);
}
/**
* The response with which this request is associated.
*/
protected org.apache.catalina.Response response = null;
/**
* Return the Response with which this Request is associated.
*/
public org.apache.catalina.Response getResponse() {
return (this.response);
}
/**
* Set the Response with which this Request is associated.
*
* @param response The new associated response
*/
public void setResponse(org.apache.catalina.Response response) {
this.response = response;
}
/**
* Return the Socket (if any) through which this Request was received.
* This should <strong>only</strong> be used to access underlying state
* information about this Socket, such as the SSLSession associated with
* an SSLSocket.
*/
public Socket getSocket() {
return (socket);
}
/**
* Set the Socket (if any) through which this Request was received.
*
* @param socket The socket through which this request was received
*/
public void setSocket(Socket socket) {
this.socket = socket;
remoteHost = null;
remoteAddr = null;
}
/**
* Return the input stream associated with this Request.
*/
public InputStream getStream() {
return inputStream;
}
/**
* Set the input stream associated with this Request.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -