关于request获取请求参数

Servlet其实在doPost,doGet之前已经解析完毕http协议的请求行和请求头。 
并且request.getParameter(),request.getInputStream(),request.getReader()这三种方法是有冲突的,因为流只能读取一次。

 

HttpServletRequest.getParameter(); 
debug看到HttpServletRequest这个类的实例其实是RequestFacade。

RequestFacade.getParameter(String name),该方法调用了Request的方法

https://blog.csdn.net/zxcc1314/article/details/82154361

 

debug视图:HttpServletRequest以及过滤器中用到的HttpServletRequest的装饰类,实例最终都是RequestFacade实例及其下Request的实例

https://blog.csdn.net/songjianc/article/details/41852009

关于request获取请求参数

 

 RequestFacade只有两个自有属性:

 protected Request request = null;(同包下)
 protected static final StringManager sm = StringManager.getManager("org.apache.catalina.connector");

package org.apache.catalina.connector

public class RequestFacade                                        
  implements HttpServletRequest
{
  private final class GetAttributePrivilegedAction
    implements PrivilegedAction<Enumeration<String>>
  {
    private GetAttributePrivilegedAction() {}
    
    public Enumeration<String> run()
    {
      return RequestFacade.this.request.getAttributeNames();
    }
  }
  
  private final class GetParameterMapPrivilegedAction
    implements PrivilegedAction<Map<String, String[]>>
  {
    private GetParameterMapPrivilegedAction() {}
    
    public Map<String, String[]> run()
    {
      return RequestFacade.this.request.getParameterMap();
    }
  }
  
  private final class GetRequestDispatcherPrivilegedAction
    implements PrivilegedAction<RequestDispatcher>
  {
    private final String path;
    
    public GetRequestDispatcherPrivilegedAction(String path)
    {
      this.path = path;
    }
    
    public RequestDispatcher run()
    {
      return RequestFacade.this.request.getRequestDispatcher(this.path);
    }
  }
  
  private final class GetParameterPrivilegedAction
    implements PrivilegedAction<String>
  {
    public String name;
    
    public GetParameterPrivilegedAction(String name)
    {
      this.name = name;
    }
    
    public String run()
    {
      return RequestFacade.this.request.getParameter(this.name);
    }
  }
  
  private final class GetParameterNamesPrivilegedAction
    implements PrivilegedAction<Enumeration<String>>
  {
    private GetParameterNamesPrivilegedAction() {}
    
    public Enumeration<String> run()
    {
      return RequestFacade.this.request.getParameterNames();
    }
  }
  
  private final class GetParameterValuePrivilegedAction
    implements PrivilegedAction<String[]>
  {
    public String name;
    
    public GetParameterValuePrivilegedAction(String name)
    {
      this.name = name;
    }
    
    public String[] run()
    {
      return RequestFacade.this.request.getParameterValues(this.name);
    }
  }
  
  private final class GetCookiesPrivilegedAction
    implements PrivilegedAction<Cookie[]>
  {
    private GetCookiesPrivilegedAction() {}
    
    public Cookie[] run()
    {
      return RequestFacade.this.request.getCookies();
    }
  }
  
  private final class GetCharacterEncodingPrivilegedAction
    implements PrivilegedAction<String>
  {
    private GetCharacterEncodingPrivilegedAction() {}
    
    public String run()
    {
      return RequestFacade.this.request.getCharacterEncoding();
    }
  }
  
  private final class GetHeadersPrivilegedAction
    implements PrivilegedAction<Enumeration<String>>
  {
    private final String name;
    
    public GetHeadersPrivilegedAction(String name)
    {
      this.name = name;
    }
    
    public Enumeration<String> run()
    {
      return RequestFacade.this.request.getHeaders(this.name);
    }
  }
  
  private final class GetHeaderNamesPrivilegedAction
    implements PrivilegedAction<Enumeration<String>>
  {
    private GetHeaderNamesPrivilegedAction() {}
    
    public Enumeration<String> run()
    {
      return RequestFacade.this.request.getHeaderNames();
    }
  }
  
  private final class GetLocalePrivilegedAction
    implements PrivilegedAction<Locale>
  {
    private GetLocalePrivilegedAction() {}
    
    public Locale run()
    {
      return RequestFacade.this.request.getLocale();
    }
  }
  
  private final class GetLocalesPrivilegedAction
    implements PrivilegedAction<Enumeration<Locale>>
  {
    private GetLocalesPrivilegedAction() {}
    
    public Enumeration<Locale> run()
    {
      return RequestFacade.this.request.getLocales();
    }
  }
  
  private final class GetSessionPrivilegedAction
    implements PrivilegedAction<HttpSession>
  {
    private final boolean create;
    
    public GetSessionPrivilegedAction(boolean create)
    {
      this.create = create;
    }
    
    public HttpSession run()
    {
      return RequestFacade.this.request.getSession(this.create);
    }
  }
  
  public RequestFacade(Request request)
  {
    this.request = request;
  }
  
  protected Request request = null;
  protected static final StringManager sm = StringManager.getManager("org.apache.catalina.connector");
  
  public void clear()
  {
    this.request = null;
  }
  
  protected Object clone()
    throws CloneNotSupportedException
  {
    throw new CloneNotSupportedException();
  }
  
  public Object getAttribute(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getAttribute(name);
  }
  
  public Enumeration<String> getAttributeNames()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Enumeration)AccessController.doPrivileged(new GetAttributePrivilegedAction(null));
    }
    return this.request.getAttributeNames();
  }
  
  public String getCharacterEncoding()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (String)AccessController.doPrivileged(new GetCharacterEncodingPrivilegedAction(null));
    }
    return this.request.getCharacterEncoding();
  }
  
  public void setCharacterEncoding(String env)
    throws UnsupportedEncodingException
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    this.request.setCharacterEncoding(env);
  }
  
  public int getContentLength()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getContentLength();
  }
  
  public String getContentType()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getContentType();
  }
  
  public ServletInputStream getInputStream()
    throws IOException
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getInputStream();
  }
  
  public String getParameter(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (String)AccessController.doPrivileged(new GetParameterPrivilegedAction(name));
    }
    return this.request.getParameter(name);
  }
  
  public Enumeration<String> getParameterNames()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Enumeration)AccessController.doPrivileged(new GetParameterNamesPrivilegedAction(null));
    }
    return this.request.getParameterNames();
  }
  
  public String[] getParameterValues(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    String[] ret = null;
    if (SecurityUtil.isPackageProtectionEnabled())
    {
      ret = (String[])AccessController.doPrivileged(new GetParameterValuePrivilegedAction(name));
      if (ret != null) {
        ret = (String[])ret.clone();
      }
    }
    else
    {
      ret = this.request.getParameterValues(name);
    }
    return ret;
  }
  
  public Map<String, String[]> getParameterMap()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Map)AccessController.doPrivileged(new GetParameterMapPrivilegedAction(null));
    }
    return this.request.getParameterMap();
  }
  
  public String getProtocol()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getProtocol();
  }
  
  public String getScheme()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getScheme();
  }
  
  public String getServerName()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getServerName();
  }
  
  public int getServerPort()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getServerPort();
  }
  
  public BufferedReader getReader()
    throws IOException
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getReader();
  }
  
  public String getRemoteAddr()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRemoteAddr();
  }
  
  public String getRemoteHost()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRemoteHost();
  }
  
  public void setAttribute(String name, Object o)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    this.request.setAttribute(name, o);
  }
  
  public void removeAttribute(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    this.request.removeAttribute(name);
  }
  
  public Locale getLocale()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Locale)AccessController.doPrivileged(new GetLocalePrivilegedAction(null));
    }
    return this.request.getLocale();
  }
  
  public Enumeration<Locale> getLocales()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Enumeration)AccessController.doPrivileged(new GetLocalesPrivilegedAction(null));
    }
    return this.request.getLocales();
  }
  
  public boolean isSecure()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isSecure();
  }
  
  public RequestDispatcher getRequestDispatcher(String path)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (RequestDispatcher)AccessController.doPrivileged(new GetRequestDispatcherPrivilegedAction(path));
    }
    return this.request.getRequestDispatcher(path);
  }
  
  public String getRealPath(String path)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRealPath(path);
  }
  
  public String getAuthType()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getAuthType();
  }
  
  public Cookie[] getCookies()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    Cookie[] ret = null;
    if (SecurityUtil.isPackageProtectionEnabled())
    {
      ret = (Cookie[])AccessController.doPrivileged(new GetCookiesPrivilegedAction(null));
      if (ret != null) {
        ret = (Cookie[])ret.clone();
      }
    }
    else
    {
      ret = this.request.getCookies();
    }
    return ret;
  }
  
  public long getDateHeader(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getDateHeader(name);
  }
  
  public String getHeader(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getHeader(name);
  }
  
  public Enumeration<String> getHeaders(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Enumeration)AccessController.doPrivileged(new GetHeadersPrivilegedAction(name));
    }
    return this.request.getHeaders(name);
  }
  
  public Enumeration<String> getHeaderNames()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (Globals.IS_SECURITY_ENABLED) {
      return (Enumeration)AccessController.doPrivileged(new GetHeaderNamesPrivilegedAction(null));
    }
    return this.request.getHeaderNames();
  }
  
  public int getIntHeader(String name)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getIntHeader(name);
  }
  
  public String getMethod()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getMethod();
  }
  
  public String getPathInfo()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getPathInfo();
  }
  
  public String getPathTranslated()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getPathTranslated();
  }
  
  public String getContextPath()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getContextPath();
  }
  
  public String getQueryString()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getQueryString();
  }
  
  public String getRemoteUser()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRemoteUser();
  }
  
  public boolean isUserInRole(String role)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isUserInRole(role);
  }
  
  public Principal getUserPrincipal()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getUserPrincipal();
  }
  
  public String getRequestedSessionId()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRequestedSessionId();
  }
  
  public String getRequestURI()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRequestURI();
  }
  
  public StringBuffer getRequestURL()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRequestURL();
  }
  
  public String getServletPath()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getServletPath();
  }
  
  public HttpSession getSession(boolean create)
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    if (SecurityUtil.isPackageProtectionEnabled()) {
      return (HttpSession)AccessController.doPrivileged(new GetSessionPrivilegedAction(create));
    }
    return this.request.getSession(create);
  }
  
  public HttpSession getSession()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return getSession(true);
  }
  
  public boolean isRequestedSessionIdValid()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isRequestedSessionIdValid();
  }
  
  public boolean isRequestedSessionIdFromCookie()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isRequestedSessionIdFromCookie();
  }
  
  public boolean isRequestedSessionIdFromURL()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isRequestedSessionIdFromURL();
  }
  
  public boolean isRequestedSessionIdFromUrl()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.isRequestedSessionIdFromURL();
  }
  
  public String getLocalAddr()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getLocalAddr();
  }
  
  public String getLocalName()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getLocalName();
  }
  
  public int getLocalPort()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getLocalPort();
  }
  
  public int getRemotePort()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getRemotePort();
  }
  
  public ServletContext getServletContext()
  {
    if (this.request == null) {
      throw new IllegalStateException(sm.getString("requestFacade.nullRequest"));
    }
    return this.request.getServletContext();
  }
  
  public AsyncContext startAsync()
    throws IllegalStateException
  {
    return this.request.startAsync();
  }
  
  public AsyncContext startAsync(ServletRequest request, ServletResponse response)
    throws IllegalStateException
  {
    return this.request.startAsync(request, response);
  }
  
  public boolean isAsyncStarted()
  {
    return this.request.isAsyncStarted();
  }
  
  public boolean isAsyncSupported()
  {
    return this.request.isAsyncSupported();
  }
  
  public AsyncContext getAsyncContext()
  {
    return this.request.getAsyncContext();
  }
  
  public DispatcherType getDispatcherType()
  {
    return this.request.getDispatcherType();
  }
  
  public boolean authenticate(HttpServletResponse response)
    throws IOException, ServletException
  {
    return this.request.authenticate(response);
  }
  
  public void login(String username, String password)
    throws ServletException
  {
    this.request.login(username, password);
  }
  
  public void logout()
    throws ServletException
  {
    this.request.logout();
  }
  
  public Collection<Part> getParts()
    throws IllegalStateException, IOException, ServletException
  {
    return this.request.getParts();
  }
  
  public Part getPart(String name)
    throws IllegalStateException, IOException, ServletException
  {
    return this.request.getPart(name);
  }
  
  public boolean getAllowTrace()
  {
    return this.request.getConnector().getAllowTrace();
  }
  
  public void doUpgrade(UpgradeInbound inbound)
    throws IOException
  {
    this.request.doUpgrade(inbound);
  }
}
 

 

 

 

 

 

 

 

 

 

 

 

 

Request*属性比较多(还包含另外一个包下的Request实例coyoteRequest)

package org.apache.catalina.connector;

public class Request
  implements HttpServletRequest
{
  private static final Log log = LogFactory.getLog(Request.class);
  protected org.apache.coyote.Request coyoteRequest;
  
  public Request()
  {
    this.formats[0].setTimeZone(GMT_ZONE);
    this.formats[1].setTimeZone(GMT_ZONE);
    this.formats[2].setTimeZone(GMT_ZONE);
  }
  
  public void setCoyoteRequest(org.apache.coyote.Request coyoteRequest)
  {
    this.coyoteRequest = coyoteRequest;
    this.inputBuffer.setRequest(coyoteRequest);
  }
  
  public org.apache.coyote.Request getCoyoteRequest()
  {
    return this.coyoteRequest;
  }
  
  protected static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
  protected static final StringManager sm = StringManager.getManager("org.apache.catalina.connector");
  protected Cookie[] cookies = null;
  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) };
  protected static Locale defaultLocale = Locale.getDefault();
  protected HashMap<String, Object> attributes = new HashMap();
  protected boolean sslAttributesParsed = false;
  private final HashMap<String, Object> readOnlyAttributes = new HashMap();
  protected ArrayList<Locale> locales = new ArrayList();
  private transient HashMap<String, Object> notes = new HashMap();
  protected String authType = null;
  protected CometEventImpl event = null;
  protected boolean comet = false;
  protected DispatcherType internalDispatcherType = null;
  protected InputBuffer inputBuffer = new InputBuffer();
  protected CoyoteInputStream inputStream = new CoyoteInputStream(this.inputBuffer);
  protected CoyoteReader reader = new CoyoteReader(this.inputBuffer);
  protected boolean usingInputStream = false;
  protected boolean usingReader = false;
  protected Principal userPrincipal = null;
  @Deprecated
  protected boolean sessionParsed = false;
  protected boolean parametersParsed = false;
  protected boolean cookiesParsed = false;
  protected boolean secure = false;
  protected transient Subject subject = null;
  protected static int CACHED_POST_LEN = 8192;
  protected byte[] postData = null;
  protected ParameterMap<String, String[]> parameterMap = new ParameterMap();
  protected Collection<Part> parts = null;
  protected Exception partsParseException = null;
  protected Session session = null;
  protected Object requestDispatcherPath = null;
  protected boolean requestedSessionCookie = false;
  protected String requestedSessionId = null;
  protected boolean requestedSessionURL = false;
  protected boolean requestedSessionSSL = false;
  protected boolean localesParsed = false;
  private final StringParser parser = new StringParser();
  protected int localPort = -1;
  protected String remoteAddr = null;
  protected String remoteHost = null;
  protected int remotePort = -1;
  protected String localAddr = null;
  protected String localName = null;
  protected volatile AsyncContextImpl asyncContext = null;
  protected Boolean asyncSupported = null;
  protected Map<String, String> pathParameters = new HashMap();
  protected Connector connector;
  
  protected void addPathParameter(String name, String value)
  {
    this.pathParameters.put(name, value);
  }
  
  protected String getPathParameter(String name)
  {
    return (String)this.pathParameters.get(name);
  }
  
  public void setAsyncSupported(boolean asyncSupported)
  {
    this.asyncSupported = Boolean.valueOf(asyncSupported);
  }
  
  public void recycle()
  {
    this.context = null;
    this.wrapper = null;
    
    this.internalDispatcherType = null;
    this.requestDispatcherPath = null;
    
    this.comet = false;
    if (this.event != null)
    {
      this.event.clear();
      this.event = null;
    }
    this.authType = null;
    this.inputBuffer.recycle();
    this.usingInputStream = false;
    this.usingReader = false;
    this.userPrincipal = null;
    this.subject = null;
    this.sessionParsed = false;
    this.parametersParsed = false;
    if (this.parts != null)
    {
      for (Part part : this.parts) {
        try
        {
          part.delete();
        }
        catch (IOException ignored) {}
      }
      this.parts = null;
    }
    this.partsParseException = null;
    this.cookiesParsed = false;
    this.locales.clear();
    this.localesParsed = false;
    this.secure = false;
    this.remoteAddr = null;
    this.remoteHost = null;
    this.remotePort = -1;
    this.localPort = -1;
    this.localAddr = null;
    this.localName = null;
    
    this.attributes.clear();
    this.sslAttributesParsed = false;
    this.notes.clear();
    this.cookies = null;
    if (this.session != null) {
      try
      {
        this.session.endAccess();
      }
      catch (Throwable t)
      {
        ExceptionUtils.handleThrowable(t);
        log.warn(sm.getString("coyoteRequest.sessionEndAccessFail"), t);
      }
    }
    this.session = null;
    this.requestedSessionCookie = false;
    this.requestedSessionId = null;
    this.requestedSessionURL = false;
    if ((Globals.IS_SECURITY_ENABLED) || (Connector.RECYCLE_FACADES))
    {
      this.parameterMap = new ParameterMap();
    }
    else
    {
      this.parameterMap.setLocked(false);
      this.parameterMap.clear();
    }
    this.mappingData.recycle();
    if ((Globals.IS_SECURITY_ENABLED) || (Connector.RECYCLE_FACADES))
    {
      if (this.facade != null)
      {
        this.facade.clear();
        this.facade = null;
      }
      if (this.inputStream != null)
      {
        this.inputStream.clear();
        this.inputStream = null;
      }
      if (this.reader != null)
      {
        this.reader.clear();
        this.reader = null;
      }
    }
    this.asyncSupported = null;
    if (this.asyncContext != null) {
      this.asyncContext.recycle();
    }
    this.asyncContext = null;
    
    this.pathParameters.clear();
  }
  
  @Deprecated
  protected boolean isProcessing()
  {
    return this.coyoteRequest.isProcessing();
  }
  
  public void clearEncoders()
  {
    this.inputBuffer.clearEncoders();
  }
  
  public boolean read()
    throws IOException
  {
    return this.inputBuffer.realReadBytes(null, 0, 0) > 0;
  }
  
  public Connector getConnector()
  {
    return this.connector;
  }
  
  public void setConnector(Connector connector)
  {
    this.connector = connector;
  }
  
  protected Context context = null;
  
  public Context getContext()
  {
    return this.context;
  }
  
  public void setContext(Context context)
  {
    this.context = context;
  }
  
  protected FilterChain filterChain = null;
  protected static final String info = "org.apache.coyote.catalina.CoyoteRequest/1.0";
  
  public FilterChain getFilterChain()
  {
    return this.filterChain;
  }
  
  public void setFilterChain(FilterChain filterChain)
  {
    this.filterChain = filterChain;
  }
  
  public Host getHost()
  {
    return (Host)this.mappingData.host;
  }
  
  @Deprecated
  public void setHost(Host host)
  {
    this.mappingData.host = host;
  }
  
  public String getInfo()
  {
    return "org.apache.coyote.catalina.CoyoteRequest/1.0";
  }
  
  protected MappingData mappingData = new MappingData();
  
  public MappingData getMappingData()
  {
    return this.mappingData;
  }
  
  protected RequestFacade facade = null;
  
  public HttpServletRequest getRequest()
  {
    if (this.facade == null) {
      this.facade = new RequestFacade(this);
    }
    return this.facade;
  }
  
  protected Response response = null;
  
  public Response getResponse()
  {
    return this.response;
  }
  
  public void setResponse(Response response)
  {
    this.response = response;
  }
  
  public InputStream getStream()
  {
    if (this.inputStream == null) {
      this.inputStream = new CoyoteInputStream(this.inputBuffer);
    }
    return this.inputStream;
  }
  
  protected B2CConverter URIConverter = null;
  
  protected B2CConverter getURIConverter()
  {
    return this.URIConverter;
  }
  
  protected void setURIConverter(B2CConverter URIConverter)
  {
    this.URIConverter = URIConverter;
  }
  
  protected Wrapper wrapper = null;
  
  public Wrapper getWrapper()
  {
    return this.wrapper;
  }
  
  public void setWrapper(Wrapper wrapper)
  {
    this.wrapper = wrapper;
  }
  
  public ServletInputStream createInputStream()
    throws IOException
  {
    if (this.inputStream == null) {
      this.inputStream = new CoyoteInputStream(this.inputBuffer);
    }
    return this.inputStream;
  }
  
  public void finishRequest()
    throws IOException
  {
    Context context = getContext();
    if ((context != null) && (this.response.getStatus() == 413) && (!context.getSwallowAbortedUploads())) {
      this.coyoteRequest.action(ActionCode.DISABLE_SWALLOW_INPUT, null);
    }
  }
  
  public Object getNote(String name)
  {
    return this.notes.get(name);
  }
  
  @Deprecated
  public Iterator<String> getNoteNames()
  {
    return this.notes.keySet().iterator();
  }
  
  public void removeNote(String name)
  {
    this.notes.remove(name);
  }
  
  public void setLocalPort(int port)
  {
    this.localPort = port;
  }
  
  public void setNote(String name, Object value)
  {
    this.notes.put(name, value);
  }
  
  public void setRemoteAddr(String remoteAddr)
  {
    this.remoteAddr = remoteAddr;
  }
  
  public void setRemoteHost(String remoteHost)
  {
    this.remoteHost = remoteHost;
  }
  
  public void setSecure(boolean secure)
  {
    this.secure = secure;
  }
  
  @Deprecated
  public void setServerName(String name)
  {
    this.coyoteRequest.serverName().setString(name);
  }
  
  public void setServerPort(int port)
  {
    this.coyoteRequest.setServerPort(port);
  }
  
  public Object getAttribute(String name)
  {
    SpecialAttributeAdapter adapter = (SpecialAttributeAdapter)specialAttributes.get(name);
    if (adapter != null) {
      return adapter.get(this, name);
    }
    Object attr = this.attributes.get(name);
    if (attr != null) {
      return attr;
    }
    attr = this.coyoteRequest.getAttribute(name);
    if (attr != null) {
      return attr;
    }
    if (isSSLAttribute(name))
    {
      this.coyoteRequest.action(ActionCode.REQ_SSL_ATTRIBUTE, this.coyoteRequest);
      
      attr = this.coyoteRequest.getAttribute("javax.servlet.request.X509Certificate");
      if (attr != null) {
        this.attributes.put("javax.servlet.request.X509Certificate", attr);
      }
      attr = this.coyoteRequest.getAttribute("javax.servlet.request.cipher_suite");
      if (attr != null) {
        this.attributes.put("javax.servlet.request.cipher_suite", attr);
      }
      attr = this.coyoteRequest.getAttribute("javax.servlet.request.key_size");
      if (attr != null) {
        this.attributes.put("javax.servlet.request.key_size", attr);
      }
      attr = this.coyoteRequest.getAttribute("javax.servlet.request.ssl_session_id");
      if (attr != null)
      {
        this.attributes.put("javax.servlet.request.ssl_session_id", attr);
        this.attributes.put("javax.servlet.request.ssl_session", attr);
      }
      attr = this.coyoteRequest.getAttribute("javax.servlet.request.ssl_session_mgr");
      if (attr != null) {
        this.attributes.put("javax.servlet.request.ssl_session_mgr", attr);
      }
      attr = this.attributes.get(name);
      this.sslAttributesParsed = true;
    }
    return attr;
  }
  
  static boolean isSSLAttribute(String name)
  {
    return ("javax.servlet.request.X509Certificate".equals(name)) || ("javax.servlet.request.cipher_suite".equals(name)) || ("javax.servlet.request.key_size".equals(name)) || ("javax.servlet.request.ssl_session_id".equals(name)) || ("javax.servlet.request.ssl_session".equals(name)) || ("javax.servlet.request.ssl_session_mgr".equals(name));
  }
  
  public Enumeration<String> getAttributeNames()
  {
    if ((isSecure()) && (!this.sslAttributesParsed)) {
      getAttribute("javax.servlet.request.X509Certificate");
    }
    Set<String> names = new HashSet();
    names.addAll(this.attributes.keySet());
    return Collections.enumeration(names);
  }
  
  public String getCharacterEncoding()
  {
    return this.coyoteRequest.getCharacterEncoding();
  }
  
  public int getContentLength()
  {
    return this.coyoteRequest.getContentLength();
  }
  
  public String getContentType()
  {
    return this.coyoteRequest.getContentType();
  }
  
  public ServletInputStream getInputStream()
    throws IOException
  {
    if (this.usingReader) {
      throw new IllegalStateException(sm.getString("coyoteRequest.getInputStream.ise"));
    }
    this.usingInputStream = true;
    if (this.inputStream == null) {
      this.inputStream = new CoyoteInputStream(this.inputBuffer);
    }
    return this.inputStream;
  }
  
  public Locale getLocale()
  {
    if (!this.localesParsed) {
      parseLocales();
    }
    if (this.locales.size() > 0) {
      return (Locale)this.locales.get(0);
    }
    return defaultLocale;
  }
  
  public Enumeration<Locale> getLocales()
  {
    if (!this.localesParsed) {
      parseLocales();
    }
    if (this.locales.size() > 0) {
      return Collections.enumeration(this.locales);
    }
    ArrayList<Locale> results = new ArrayList();
    results.add(defaultLocale);
    return Collections.enumeration(results);
  }
  
  public String getParameter(String name)
  {
    if (!this.parametersParsed) {
      parseParameters();
    }
    return this.coyoteRequest.getParameters().getParameter(name);
  }
  
  public Map<String, String[]> getParameterMap()
  {
    if (this.parameterMap.isLocked()) {
      return this.parameterMap;
    }
    Enumeration<String> enumeration = getParameterNames();
    while (enumeration.hasMoreElements())
    {
      String name = (String)enumeration.nextElement();
      String[] values = getParameterValues(name);
      this.parameterMap.put(name, values);
    }
    this.parameterMap.setLocked(true);
    
    return this.parameterMap;
  }
  
  public Enumeration<String> getParameterNames()
  {
    if (!this.parametersParsed) {
      parseParameters();
    }
    return this.coyoteRequest.getParameters().getParameterNames();
  }
  
  public String[] getParameterValues(String name)
  {
    if (!this.parametersParsed) {
      parseParameters();
    }
    return this.coyoteRequest.getParameters().getParameterValues(name);
  }
  
  public String getProtocol()
  {
    return this.coyoteRequest.protocol().toString();
  }
  
  public BufferedReader getReader()
    throws IOException
  {
    if (this.usingInputStream) {
      throw new IllegalStateException(sm.getString("coyoteRequest.getReader.ise"));
    }
    this.usingReader = true;
    this.inputBuffer.checkConverter();
    if (this.reader == null) {
      this.reader = new CoyoteReader(this.inputBuffer);
    }
    return this.reader;
  }
  
  @Deprecated
  public String getRealPath(String path)
  {
    if (this.context == null) {
      return null;
    }
    ServletContext servletContext = this.context.getServletContext();
    if (servletContext == null) {
      return null;
    }
    try
    {
      return servletContext.getRealPath(path);
    }
    catch (IllegalArgumentException e) {}
    return null;
  }
  
  public String getRemoteAddr()
  {
    if (this.remoteAddr == null)
    {
      this.coyoteRequest.action(ActionCode.REQ_HOST_ADDR_ATTRIBUTE, this.coyoteRequest);
      
      this.remoteAddr = this.coyoteRequest.remoteAddr().toString();
    }
    return this.remoteAddr;
  }
  
  public String getRemoteHost()
  {
    if (this.remoteHost == null) {
      if (!this.connector.getEnableLookups())
      {
        this.remoteHost = getRemoteAddr();
      }
      else
      {
        this.coyoteRequest.action(ActionCode.REQ_HOST_ATTRIBUTE, this.coyoteRequest);
        
        this.remoteHost = this.coyoteRequest.remoteHost().toString();
      }
    }
    return this.remoteHost;
  }
  
  public int getRemotePort()
  {
    if (this.remotePort == -1)
    {
      this.coyoteRequest.action(ActionCode.REQ_REMOTEPORT_ATTRIBUTE, this.coyoteRequest);
      
      this.remotePort = this.coyoteRequest.getRemotePort();
    }
    return this.remotePort;
  }
  
  public String getLocalName()
  {
    if (this.localName == null)
    {
      this.coyoteRequest.action(ActionCode.REQ_LOCAL_NAME_ATTRIBUTE, this.coyoteRequest);
      
      this.localName = this.coyoteRequest.localName().toString();
    }
    return this.localName;
  }
  
  public String getLocalAddr()
  {
    if (this.localAddr == null)
    {
      this.coyoteRequest.action(ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE, this.coyoteRequest);
      
      this.localAddr = this.coyoteRequest.localAddr().toString();
    }
    return this.localAddr;
  }
  
  public int getLocalPort()
  {
    if (this.localPort == -1)
    {
      this.coyoteRequest.action(ActionCode.REQ_LOCALPORT_ATTRIBUTE, this.coyoteRequest);
      
      this.localPort = this.coyoteRequest.getLocalPort();
    }
    return this.localPort;
  }
  
  public RequestDispatcher getRequestDispatcher(String path)
  {
    if (this.context == null) {
      return null;
    }
    if (path == null) {
      return null;
    }
    if (path.startsWith("/")) {
      return this.context.getServletContext().getRequestDispatcher(path);
    }
    String servletPath = (String)getAttribute("javax.servlet.include.servlet_path");
    if (servletPath == null) {
      servletPath = getServletPath();
    }
    String pathInfo = getPathInfo();
    String requestPath = null;
    if (pathInfo == null) {
      requestPath = servletPath;
    } else {
      requestPath = servletPath + pathInfo;
    }
    int pos = requestPath.lastIndexOf('/');
    String relative = null;
    if (pos >= 0) {
      relative = requestPath.substring(0, pos + 1) + path;
    } else {
      relative = requestPath + path;
    }
    return this.context.getServletContext().getRequestDispatcher(relative);
  }
  
  public String getScheme()
  {
    return this.coyoteRequest.scheme().toString();
  }
  
  public String getServerName()
  {
    return this.coyoteRequest.serverName().toString();
  }
  
  public int getServerPort()
  {
    return this.coyoteRequest.getServerPort();
  }
  
  public boolean isSecure()
  {
    return this.secure;
  }
  
  public void removeAttribute(String name)
  {
    if (this.readOnlyAttributes.containsKey(name)) {
      return;
    }
    if (name.startsWith("org.apache.tomcat.")) {
      this.coyoteRequest.getAttributes().remove(name);
    }
    boolean found = this.attributes.containsKey(name);
    if (found)
    {
      Object value = this.attributes.get(name);
      this.attributes.remove(name);
      

      notifyAttributeRemoved(name, value);
    }
    else {}
  }
  
  public void setAttribute(String name, Object value)
  {
    if (name == null) {
      throw new IllegalArgumentException(sm.getString("coyoteRequest.setAttribute.namenull"));
    }
    if (value == null)
    {
      removeAttribute(name);
      return;
    }
    SpecialAttributeAdapter adapter = (SpecialAttributeAdapter)specialAttributes.get(name);
    if (adapter != null)
    {
      adapter.set(this, name, value);
      return;
    }
    if (this.readOnlyAttributes.containsKey(name)) {
      return;
    }
    if ((Globals.IS_SECURITY_ENABLED) && (name.equals("org.apache.tomcat.sendfile.filename")))
    {
      String canonicalPath;
      try
      {
        canonicalPath = new File(value.toString()).getCanonicalPath();
      }
      catch (IOException e)
      {
        throw new SecurityException(sm.getString("coyoteRequest.sendfileNotCanonical", new Object[] { value }), e);
      }
      System.getSecurityManager().checkRead(canonicalPath);
      
      value = canonicalPath;
    }
    Object oldValue = this.attributes.put(name, value);
    if (name.startsWith("org.apache.tomcat.")) {
      this.coyoteRequest.setAttribute(name, value);
    }
    notifyAttributeAssigned(name, value, oldValue);
  }
  
  private void notifyAttributeAssigned(String name, Object value, Object oldValue)
  {
    Object[] listeners = this.context.getApplicationEventListeners();
    if ((listeners == null) || (listeners.length == 0)) {
      return;
    }
    boolean replaced = oldValue != null;
    ServletRequestAttributeEvent event = null;
    if (replaced) {
      event = new ServletRequestAttributeEvent(this.context.getServletContext(), getRequest(), name, oldValue);
    } else {
      event = new ServletRequestAttributeEvent(this.context.getServletContext(), getRequest(), name, value);
    }
    for (int i = 0; i < listeners.length; i++) {
      if ((listeners[i] instanceof ServletRequestAttributeListener))
      {
        ServletRequestAttributeListener listener = (ServletRequestAttributeListener)listeners[i];
        try
        {
          if (replaced) {
            listener.attributeReplaced(event);
          } else {
            listener.attributeAdded(event);
          }
        }
        catch (Throwable t)
        {
          ExceptionUtils.handleThrowable(t);
          this.context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
          
          this.attributes.put("javax.servlet.error.exception", t);
        }
      }
    }
  }
  
  private void notifyAttributeRemoved(String name, Object value)
  {
    Object[] listeners = this.context.getApplicationEventListeners();
    if ((listeners == null) || (listeners.length == 0)) {
      return;
    }
    ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(this.context.getServletContext(), getRequest(), name, value);
    for (int i = 0; i < listeners.length; i++) {
      if ((listeners[i] instanceof ServletRequestAttributeListener))
      {
        ServletRequestAttributeListener listener = (ServletRequestAttributeListener)listeners[i];
        try
        {
          listener.attributeRemoved(event);
        }
        catch (Throwable t)
        {
          ExceptionUtils.handleThrowable(t);
          this.context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
          
          this.attributes.put("javax.servlet.error.exception", t);
        }
      }
    }
  }
  
  public void setCharacterEncoding(String enc)
    throws UnsupportedEncodingException
  {
    if (this.usingReader) {
      return;
    }
    byte[] buffer = new byte[1];
    buffer[0] = 97;
    

    B2CConverter.getCharset(enc);
    

    this.coyoteRequest.setCharacterEncoding(enc);
  }
  
  public ServletContext getServletContext()
  {
    return this.context.getServletContext();
  }
  
  public AsyncContext startAsync()
  {
    return startAsync(getRequest(), this.response.getResponse());
  }
  
  public AsyncContext startAsync(ServletRequest request, ServletResponse response)
  {
    if (!isAsyncSupported()) {
      throw new IllegalStateException("Not supported.");
    }
    if (this.asyncContext == null) {
      this.asyncContext = new AsyncContextImpl(this);
    }
    this.asyncContext.setStarted(getContext(), request, response, (request == getRequest()) && (response == getResponse().getResponse()));
    
    this.asyncContext.setTimeout(getConnector().getAsyncTimeout());
    
    return this.asyncContext;
  }
  
  public boolean isAsyncStarted()
  {
    if (this.asyncContext == null) {
      return false;
    }
    return this.asyncContext.isStarted();
  }
  
  public boolean isAsyncDispatching()
  {
    if (this.asyncContext == null) {
      return false;
    }
    AtomicBoolean result = new AtomicBoolean(false);
    this.coyoteRequest.action(ActionCode.ASYNC_IS_DISPATCHING, result);
    return result.get();
  }
  
  public boolean isAsync()
  {
    if (this.asyncContext == null) {
      return false;
    }
    AtomicBoolean result = new AtomicBoolean(false);
    this.coyoteRequest.action(ActionCode.ASYNC_IS_ASYNC, result);
    return result.get();
  }
  
  public boolean isAsyncSupported()
  {
    if (this.asyncSupported == null) {
      return true;
    }
    return this.asyncSupported.booleanValue();
  }
  
  public AsyncContext getAsyncContext()
  {
    return this.asyncContext;
  }
  
  public DispatcherType getDispatcherType()
  {
    if (this.internalDispatcherType == null) {
      return DispatcherType.REQUEST;
    }
    return this.internalDispatcherType;
  }
  
  public void addCookie(Cookie cookie)
  {
    if (!this.cookiesParsed) {
      parseCookies();
    }
    int size = 0;
    if (this.cookies != null) {
      size = this.cookies.length;
    }
    Cookie[] newCookies = new Cookie[size + 1];
    for (int i = 0; i < size; i++) {
      newCookies[i] = this.cookies[i];
    }
    newCookies[size] = cookie;
    
    this.cookies = newCookies;
  }
  
  public void addLocale(Locale locale)
  {
    this.locales.add(locale);
  }
  
  @Deprecated
  public void addParameter(String name, String[] values)
  {
    this.coyoteRequest.getParameters().addParameterValues(name, values);
  }
  
  public void clearCookies()
  {
    this.cookiesParsed = true;
    this.cookies = null;
  }
  
  @Deprecated
  public void clearHeaders() {}
  
  public void clearLocales()
  {
    this.locales.clear();
  }
  
  @Deprecated
  public void clearParameters() {}
  
  public void setAuthType(String type)
  {
    this.authType = type;
  }
  
  @Deprecated
  public void setContextPath(String path)
  {
    if (path == null) {
      this.mappingData.contextPath.setString("");
    } else {
      this.mappingData.contextPath.setString(path);
    }
  }
  
  public void setPathInfo(String path)
  {
    this.mappingData.pathInfo.setString(path);
  }
  
  public void setRequestedSessionCookie(boolean flag)
  {
    this.requestedSessionCookie = flag;
  }
  
  public void setRequestedSessionId(String id)
  {
    this.requestedSessionId = id;
  }
  
  public void setRequestedSessionURL(boolean flag)
  {
    this.requestedSessionURL = flag;
  }
  
  public void setRequestedSessionSSL(boolean flag)
  {
    this.requestedSessionSSL = flag;
  }
  
  public String getDecodedRequestURI()
  {
    return this.coyoteRequest.decodedURI().toString();
  }
  
  @Deprecated
  public MessageBytes getDecodedRequestURIMB()
  {
    return this.coyoteRequest.decodedURI();
  }
  
  @Deprecated
  public void setServletPath(String path)
  {
    if (path != null) {
      this.mappingData.wrapperPath.setString(path);
    }
  }
  
  public void setUserPrincipal(Principal principal)
  {
    if (Globals.IS_SECURITY_ENABLED)
    {
      HttpSession session = getSession(false);
      if ((this.subject != null) && (!this.subject.getPrincipals().contains(principal)))
      {
        this.subject.getPrincipals().add(principal);
      }
      else if ((session != null) && (session.getAttribute("javax.security.auth.subject") == null))
      {
        this.subject = new Subject();
        this.subject.getPrincipals().add(principal);
      }
      if (session != null) {
        session.setAttribute("javax.security.auth.subject", this.subject);
      }
    }
    this.userPrincipal = principal;
  }
  
  public String getAuthType()
  {
    return this.authType;
  }
  
  public String getContextPath()
  {
    return this.mappingData.contextPath.toString();
  }
  
  @Deprecated
  public MessageBytes getContextPathMB()
  {
    return this.mappingData.contextPath;
  }
  
  public Cookie[] getCookies()
  {
    if (!this.cookiesParsed) {
      parseCookies();
    }
    return this.cookies;
  }
  
  @Deprecated
  public void setCookies(Cookie[] cookies)
  {
    this.cookies = cookies;
  }
  
  public long getDateHeader(String name)
  {
    String value = getHeader(name);
    if (value == null) {
      return -1L;
    }
    long result = FastHttpDateFormat.parseDate(value, this.formats);
    if (result != -1L) {
      return result;
    }
    throw new IllegalArgumentException(value);
  }
  
  public String getHeader(String name)
  {
    return this.coyoteRequest.getHeader(name);
  }
  
  public Enumeration<String> getHeaders(String name)
  {
    return this.coyoteRequest.getMimeHeaders().values(name);
  }
  
  public Enumeration<String> getHeaderNames()
  {
    return this.coyoteRequest.getMimeHeaders().names();
  }
  
  public int getIntHeader(String name)
  {
    String value = getHeader(name);
    if (value == null) {
      return -1;
    }
    return Integer.parseInt(value);
  }
  
  public String getMethod()
  {
    return this.coyoteRequest.method().toString();
  }
  
  public String getPathInfo()
  {
    return this.mappingData.pathInfo.toString();
  }
  
  @Deprecated
  public MessageBytes getPathInfoMB()
  {
    return this.mappingData.pathInfo;
  }
  
  public String getPathTranslated()
  {
    if (this.context == null) {
      return null;
    }
    if (getPathInfo() == null) {
      return null;
    }
    return this.context.getServletContext().getRealPath(getPathInfo());
  }
  
  public String getQueryString()
  {
    return this.coyoteRequest.queryString().toString();
  }
  
  public String getRemoteUser()
  {
    if (this.userPrincipal == null) {
      return null;
    }
    return this.userPrincipal.getName();
  }
  
  public MessageBytes getRequestPathMB()
  {
    return this.mappingData.requestPath;
  }
  
  public String getRequestedSessionId()
  {
    return this.requestedSessionId;
  }
  
  public String getRequestURI()
  {
    return this.coyoteRequest.requestURI().toString();
  }
  
  public StringBuffer getRequestURL()
  {
    StringBuffer url = new StringBuffer();
    String scheme = getScheme();
    int port = getServerPort();
    if (port < 0) {
      port = 80;
    }
    url.append(scheme);
    url.append("://");
    url.append(getServerName());
    if (((scheme.equals("http")) && (port != 80)) || ((scheme.equals("https")) && (port != 443)))
    {
      url.append(':');
      url.append(port);
    }
    url.append(getRequestURI());
    
    return url;
  }
  
  public String getServletPath()
  {
    return this.mappingData.wrapperPath.toString();
  }
  
  @Deprecated
  public MessageBytes getServletPathMB()
  {
    return this.mappingData.wrapperPath;
  }
  
  public HttpSession getSession()
  {
    Session session = doGetSession(true);
    if (session == null) {
      return null;
    }
    return session.getSession();
  }
  
  public HttpSession getSession(boolean create)
  {
    Session session = doGetSession(create);
    if (session == null) {
      return null;
    }
    return session.getSession();
  }
  
  public boolean isRequestedSessionIdFromCookie()
  {
    if (this.requestedSessionId == null) {
      return false;
    }
    return this.requestedSessionCookie;
  }
  
  public boolean isRequestedSessionIdFromURL()
  {
    if (this.requestedSessionId == null) {
      return false;
    }
    return this.requestedSessionURL;
  }
  
  @Deprecated
  public boolean isRequestedSessionIdFromUrl()
  {
    return isRequestedSessionIdFromURL();
  }
  
  public boolean isRequestedSessionIdValid()
  {
    if (this.requestedSessionId == null) {
      return false;
    }
    if (this.context == null) {
      return false;
    }
    Manager manager = this.context.getManager();
    if (manager == null) {
      return false;
    }
    Session session = null;
    try
    {
      session = manager.findSession(this.requestedSessionId);
    }
    catch (IOException e) {}
    if ((session == null) || (!session.isValid()))
    {
      if (getMappingData().contexts == null) {
        return false;
      }
      for (int i = getMappingData().contexts.length; i > 0; i--)
      {
        Context ctxt = (Context)getMappingData().contexts[(i - 1)];
        try
        {
          if (ctxt.getManager().findSession(this.requestedSessionId) != null) {
            return true;
          }
        }
        catch (IOException e) {}
      }
      return false;
    }
    return true;
  }
  
  public boolean isUserInRole(String role)
  {
    if (this.userPrincipal == null) {
      return false;
    }
    if (this.context == null) {
      return false;
    }
    Realm realm = this.context.getRealm();
    if (realm == null) {
      return false;
    }
    return realm.hasRole(this.wrapper, this.userPrincipal, role);
  }
  
  public Principal getPrincipal()
  {
    return this.userPrincipal;
  }
  
  public Principal getUserPrincipal()
  {
    if ((this.userPrincipal instanceof GenericPrincipal)) {
      return ((GenericPrincipal)this.userPrincipal).getUserPrincipal();
    }
    return this.userPrincipal;
  }
  
  public Session getSessionInternal()
  {
    return doGetSession(true);
  }
  
  public void changeSessionId(String newSessionId)
  {
    if ((this.requestedSessionId != null) && (this.requestedSessionId.length() > 0)) {
      this.requestedSessionId = newSessionId;
    }
    if ((this.context != null) && (!this.context.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE))) {
      return;
    }
    if (this.response != null)
    {
      Cookie newCookie = ApplicationSessionCookieConfig.createSessionCookie(this.context, newSessionId, this.secure);
      

      this.response.addSessionCookieInternal(newCookie);
    }
  }
  
  public Session getSessionInternal(boolean create)
  {
    return doGetSession(create);
  }
  
  public CometEventImpl getEvent()
  {
    if (this.event == null) {
      this.event = new CometEventImpl(this, this.response);
    }
    return this.event;
  }
  
  public boolean isComet()
  {
    return this.comet;
  }
  
  public void setComet(boolean comet)
  {
    this.comet = comet;
  }
  
  public boolean isParametersParsed()
  {
    return this.parametersParsed;
  }
  
  public boolean getAvailable()
  {
    return this.inputBuffer.available() > 0;
  }
  
  protected void checkSwallowInput()
  {
    Context context = getContext();
    if ((context != null) && (!context.getSwallowAbortedUploads())) {
      this.coyoteRequest.action(ActionCode.DISABLE_SWALLOW_INPUT, null);
    }
  }
  
  public void cometClose()
  {
    this.coyoteRequest.action(ActionCode.COMET_CLOSE, getEvent());
    setComet(false);
  }
  
  public void setCometTimeout(long timeout)
  {
    this.coyoteRequest.action(ActionCode.COMET_SETTIMEOUT, Long.valueOf(timeout));
  }
  
  @Deprecated
  public boolean isRequestedSessionIdFromSSL()
  {
    return this.requestedSessionSSL;
  }
  
  public boolean authenticate(HttpServletResponse response)
    throws IOException, ServletException
  {
    if (response.isCommitted()) {
      throw new IllegalStateException(sm.getString("coyoteRequest.authenticate.ise"));
    }
    return this.context.getAuthenticator().authenticate(this, response);
  }
  
  public void login(String username, String password)
    throws ServletException
  {
    if ((getAuthType() != null) || (getRemoteUser() != null) || (getUserPrincipal() != null)) {
      throw new ServletException(sm.getString("coyoteRequest.alreadyAuthenticated"));
    }
    if (this.context.getAuthenticator() == null) {
      throw new ServletException("no authenticator");
    }
    this.context.getAuthenticator().login(username, password, this);
  }
  
  public void logout()
    throws ServletException
  {
    this.context.getAuthenticator().logout(this);
  }
  
  public Collection<Part> getParts()
    throws IOException, IllegalStateException, ServletException
  {
    parseParts();
    if (this.partsParseException != null)
    {
      if ((this.partsParseException instanceof IOException)) {
        throw ((IOException)this.partsParseException);
      }
      if ((this.partsParseException instanceof IllegalStateException)) {
        throw ((IllegalStateException)this.partsParseException);
      }
      if ((this.partsParseException instanceof ServletException)) {
        throw ((ServletException)this.partsParseException);
      }
    }
    return this.parts;
  }
  
  private void parseParts()
  {
    if ((this.parts != null) || (this.partsParseException != null)) {
      return;
    }
    MultipartConfigElement mce = getWrapper().getMultipartConfigElement();
    if (mce == null) {
      if (getContext().getAllowCasualMultipartParsing())
      {
        mce = new MultipartConfigElement(null, this.connector.getMaxPostSize(), this.connector.getMaxPostSize(), this.connector.getMaxPostSize());
      }
      else
      {
        this.parts = Collections.emptyList();
        return;
      }
    }
    Parameters parameters = this.coyoteRequest.getParameters();
    parameters.setLimit(getConnector().getMaxParameterCount());
    
    boolean success = false;
    try
    {
      String locationStr = mce.getLocation();
      File location;
      File location;
      if ((locationStr == null) || (locationStr.length() == 0))
      {
        location = (File)this.context.getServletContext().getAttribute("javax.servlet.context.tempdir");
      }
      else
      {
        location = new File(locationStr);
        if (!location.isAbsolute()) {
          location = new File((File)this.context.getServletContext().getAttribute("javax.servlet.context.tempdir"), locationStr).getAbsoluteFile();
        }
      }
      if (!location.isDirectory())
      {
        this.partsParseException = new IOException(sm.getString("coyoteRequest.uploadLocationInvalid", new Object[] { location }));
      }
      else
      {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        try
        {
          factory.setRepository(location.getCanonicalFile());
        }
        catch (IOException ioe)
        {
          this.partsParseException = ioe;
          if ((this.partsParseException != null) || (!success)) {
            parameters.setParseFailed(true);
          }
          return;
        }
        factory.setSizeThreshold(mce.getFileSizeThreshold());
        
        ServletFileUpload upload = new ServletFileUpload();
        upload.setFileItemFactory(factory);
        upload.setFileSizeMax(mce.getMaxFileSize());
        upload.setSizeMax(mce.getMaxRequestSize());
        
        this.parts = new ArrayList();
        try
        {
          List<FileItem> items = upload.parseRequest(this);
          int maxPostSize = getConnector().getMaxPostSize();
          int postSize = 0;
          String enc = getCharacterEncoding();
          Charset charset = null;
          if (enc != null) {
            try
            {
              charset = B2CConverter.getCharset(enc);
            }
            catch (UnsupportedEncodingException e) {}
          }
          for (FileItem item : items)
          {
            ApplicationPart part = new ApplicationPart(item, mce);
            this.parts.add(part);
            if (part.getFilename() == null)
            {
              String name = part.getName();
              String value = null;
              try
              {
                String encoding = parameters.getEncoding();
                if (encoding == null) {
                  encoding = "ISO-8859-1";
                }
                value = part.getString(encoding);
              }
              catch (UnsupportedEncodingException uee)
              {
                try
                {
                  value = part.getString("ISO-8859-1");
                }
                catch (UnsupportedEncodingException e) {}
              }
              if (maxPostSize > 0)
              {
                if (charset == null) {
                  postSize += name.getBytes().length;
                } else {
                  postSize += name.getBytes(charset).length;
                }
                if (value != null)
                {
                  postSize++;
                  
                  postSize = (int)(postSize + part.getSize());
                }
                postSize++;
                if (postSize > maxPostSize) {
                  throw new IllegalStateException(sm.getString("coyoteRequest.maxPostSizeExceeded"));
                }
              }
              parameters.addParameter(name, value);
            }
          }
          success = true;
        }
        catch (FileUploadBase.InvalidContentTypeException e)
        {
          this.partsParseException = new ServletException(e);
        }
        catch (FileUploadBase.SizeException e)
        {
          checkSwallowInput();
          this.partsParseException = new IllegalStateException(e);
        }
        catch (FileUploadException e)
        {
          this.partsParseException = new IOException(e);
        }
        catch (IllegalStateException e)
        {
          checkSwallowInput();
          this.partsParseException = e;
        }
      }
    }
    finally
    {
      if ((this.partsParseException != null) || (!success)) {
        parameters.setParseFailed(true);
      }
    }
  }
  
  public Part getPart(String name)
    throws IOException, IllegalStateException, ServletException
  {
    Collection<Part> c = getParts();
    Iterator<Part> iterator = c.iterator();
    while (iterator.hasNext())
    {
      Part part = (Part)iterator.next();
      if (name.equals(part.getName())) {
        return part;
      }
    }
    return null;
  }
  
  public void doUpgrade(UpgradeInbound inbound)
    throws IOException
  {
    this.coyoteRequest.action(ActionCode.UPGRADE, inbound);
    


    this.response.setStatus(101);
    this.response.flushBuffer();
  }
  
  protected Session doGetSession(boolean create)
  {
    if (this.context == null) {
      return null;
    }
    if ((this.session != null) && (!this.session.isValid())) {
      this.session = null;
    }
    if (this.session != null) {
      return this.session;
    }
    Manager manager = null;
    if (this.context != null) {
      manager = this.context.getManager();
    }
    if (manager == null) {
      return null;
    }
    if (this.requestedSessionId != null)
    {
      try
      {
        this.session = manager.findSession(this.requestedSessionId);
      }
      catch (IOException e)
      {
        this.session = null;
      }
      if ((this.session != null) && (!this.session.isValid())) {
        this.session = null;
      }
      if (this.session != null)
      {
        this.session.access();
        return this.session;
      }
    }
    if (!create) {
      return null;
    }
    if ((this.context != null) && (this.response != null) && (this.context.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE)) && (this.response.getResponse().isCommitted())) {
      throw new IllegalStateException(sm.getString("coyoteRequest.sessionCreateCommitted"));
    }
    if ((("/".equals(this.context.getSessionCookiePath())) && (isRequestedSessionIdFromCookie())) || (this.requestedSessionSSL)) {
      this.session = manager.createSession(getRequestedSessionId());
    } else {
      this.session = manager.createSession(null);
    }
    if ((this.session != null) && (getContext() != null) && (getContext().getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE)))
    {
      Cookie cookie = ApplicationSessionCookieConfig.createSessionCookie(this.context, this.session.getIdInternal(), isSecure());
      


      this.response.addSessionCookieInternal(cookie);
    }
    if (this.session == null) {
      return null;
    }
    this.session.access();
    return this.session;
  }
  
  protected String unescape(String s)
  {
    if (s == null) {
      return null;
    }
    if (s.indexOf('\\') == -1) {
      return s;
    }
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < s.length(); i++)
    {
      char c = s.charAt(i);
      if (c != '\\')
      {
        buf.append(c);
      }
      else
      {
        i++;
        if (i >= s.length()) {
          throw new IllegalArgumentException();
        }
        c = s.charAt(i);
        buf.append(c);
      }
    }
    return buf.toString();
  }
  
  protected void parseCookies()
  {
    this.cookiesParsed = true;
    
    Cookies serverCookies = this.coyoteRequest.getCookies();
    int count = serverCookies.getCookieCount();
    if (count <= 0) {
      return;
    }
    this.cookies = new Cookie[count];
    
    int idx = 0;
    for (int i = 0; i < count; i++)
    {
      ServerCookie scookie = serverCookies.getCookie(i);
      try
      {
        Cookie cookie = new Cookie(scookie.getName().toString(), null);
        int version = scookie.getVersion();
        cookie.setVersion(version);
        cookie.setValue(unescape(scookie.getValue().toString()));
        cookie.setPath(unescape(scookie.getPath().toString()));
        String domain = scookie.getDomain().toString();
        if (domain != null) {
          cookie.setDomain(unescape(domain));
        }
        String comment = scookie.getComment().toString();
        cookie.setComment(version == 1 ? unescape(comment) : null);
        this.cookies[(idx++)] = cookie;
      }
      catch (IllegalArgumentException e) {}
    }
    if (idx < count)
    {
      Cookie[] ncookies = new Cookie[idx];
      System.arraycopy(this.cookies, 0, ncookies, 0, idx);
      this.cookies = ncookies;
    }
  }
  
  protected void parseParameters()
  {
    this.parametersParsed = true;
    
    Parameters parameters = this.coyoteRequest.getParameters();
    boolean success = false;
    try
    {
      parameters.setLimit(getConnector().getMaxParameterCount());
      


      String enc = getCharacterEncoding();
      
      boolean useBodyEncodingForURI = this.connector.getUseBodyEncodingForURI();
      if (enc != null)
      {
        parameters.setEncoding(enc);
        if (useBodyEncodingForURI) {
          parameters.setQueryStringEncoding(enc);
        }
      }
      else
      {
        parameters.setEncoding("ISO-8859-1");
        if (useBodyEncodingForURI) {
          parameters.setQueryStringEncoding("ISO-8859-1");
        }
      }
      parameters.handleQueryParameters();
      if ((this.usingInputStream) || (this.usingReader))
      {
        success = true;
      }
      else if (!getConnector().isParseBodyMethod(getMethod()))
      {
        success = true;
      }
      else
      {
        String contentType = getContentType();
        if (contentType == null) {
          contentType = "";
        }
        int semicolon = contentType.indexOf(';');
        if (semicolon >= 0) {
          contentType = contentType.substring(0, semicolon).trim();
        } else {
          contentType = contentType.trim();
        }
        if ("multipart/form-data".equals(contentType))
        {
          parseParts();
          success = true;
        }
        else if (!"application/x-www-form-urlencoded".equals(contentType))
        {
          success = true;
        }
        else
        {
          int len = getContentLength();
          if (len > 0)
          {
            int maxPostSize = this.connector.getMaxPostSize();
            if ((maxPostSize > 0) && (len > maxPostSize))
            {
              if (this.context.getLogger().isDebugEnabled()) {
                this.context.getLogger().debug(sm.getString("coyoteRequest.postTooLarge"));
              }
              checkSwallowInput(); return;
            }
            byte[] formData = null;
            if (len < CACHED_POST_LEN)
            {
              if (this.postData == null) {
                this.postData = new byte[CACHED_POST_LEN];
              }
              formData = this.postData;
            }
            else
            {
              formData = new byte[len];
            }
            try
            {
              if (readPostBody(formData, len) != len) {
                return;
              }
            }
            catch (IOException e)
            {
              if (this.context.getLogger().isDebugEnabled()) {
                this.context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e);
              }
              return;
            }
            parameters.processParameters(formData, 0, len);
          }
          else if ("chunked".equalsIgnoreCase(this.coyoteRequest.getHeader("transfer-encoding")))
          {
            byte[] formData = null;
            try
            {
              formData = readChunkedPostBody();
            }
            catch (IOException e)
            {
              if (this.context.getLogger().isDebugEnabled()) {
                this.context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e);
              }
              return;
            }
            if (formData != null) {
              parameters.processParameters(formData, 0, formData.length);
            }
          }
          success = true;
        }
      }
    }
    finally
    {
      if (!success) {
        parameters.setParseFailed(true);
      }
    }
  }
  
  protected int readPostBody(byte[] body, int len)
    throws IOException
  {
    int offset = 0;
    do
    {
      int inputLen = getStream().read(body, offset, len - offset);
      if (inputLen <= 0) {
        return offset;
      }
      offset += inputLen;
    } while (len - offset > 0);
    return len;
  }
  
  protected byte[] readChunkedPostBody()
    throws IOException
  {
    ByteChunk body = new ByteChunk();
    
    byte[] buffer = new byte[CACHED_POST_LEN];
    
    int len = 0;
    while (len > -1)
    {
      len = getStream().read(buffer, 0, CACHED_POST_LEN);
      if ((this.connector.getMaxPostSize() > 0) && (body.getLength() + len > this.connector.getMaxPostSize()))
      {
        checkSwallowInput();
        throw new IOException(sm.getString("coyoteRequest.chunkedPostTooLarge"));
      }
      if (len > 0) {
        body.append(buffer, 0, len);
      }
    }
    if (body.getLength() == 0) {
      return null;
    }
    if (body.getLength() < body.getBuffer().length)
    {
      int length = body.getLength();
      byte[] result = new byte[length];
      System.arraycopy(body.getBuffer(), 0, result, 0, length);
      return result;
    }
    return body.getBuffer();
  }
  
  protected void parseLocales()
  {
    this.localesParsed = true;
    
    Enumeration<String> values = getHeaders("accept-language");
    while (values.hasMoreElements())
    {
      String value = (String)values.nextElement();
      parseLocalesHeader(value);
    }
  }
  
  protected void parseLocalesHeader(String value)
  {
    TreeMap<Double, ArrayList<Locale>> locales = new TreeMap();
    

    int white = value.indexOf(' ');
    if (white < 0) {
      white = value.indexOf('\t');
    }
    if (white >= 0)
    {
      StringBuilder sb = new StringBuilder();
      int len = value.length();
      for (int i = 0; i < len; i++)
      {
        char ch = value.charAt(i);
        if ((ch != ' ') && (ch != '\t')) {
          sb.append(ch);
        }
      }
      this.parser.setString(sb.toString());
    }
    else
    {
      this.parser.setString(value);
    }
    int length = this.parser.getLength();
    for (;;)
    {
      int start = this.parser.getIndex();
      if (start >= length) {
        break;
      }
      int end = this.parser.findChar(',');
      String entry = this.parser.extract(start, end).trim();
      this.parser.advance();
      

      double quality = 1.0D;
      int semi = entry.indexOf(";q=");
      if (semi >= 0)
      {
        try
        {
          String strQuality = entry.substring(semi + 3);
          if (strQuality.length() <= 5) {
            quality = Double.parseDouble(strQuality);
          } else {
            quality = 0.0D;
          }
        }
        catch (NumberFormatException e)
        {
          quality = 0.0D;
        }
        entry = entry.substring(0, semi);
      }
      if ((quality >= 5.E-005D) && 
      


        (!"*".equals(entry)))
      {
        String language = null;
        String country = null;
        String variant = null;
        int dash = entry.indexOf('-');
        if (dash < 0)
        {
          language = entry;
          country = "";
          variant = "";
        }
        else
        {
          language = entry.substring(0, dash);
          country = entry.substring(dash + 1);
          int vDash = country.indexOf('-');
          if (vDash > 0)
          {
            String cTemp = country.substring(0, vDash);
            variant = country.substring(vDash + 1);
            country = cTemp;
          }
          else
          {
            variant = "";
          }
        }
        if ((isAlpha(language)) && (isAlpha(country)) && (isAlpha(variant)))
        {
          Locale locale = new Locale(language, country, variant);
          Double key = new Double(-quality);
          ArrayList<Locale> values = (ArrayList)locales.get(key);
          if (values == null)
          {
            values = new ArrayList();
            locales.put(key, values);
          }
          values.add(locale);
        }
      }
    }
    for (ArrayList<Locale> list : locales.values()) {
      for (Locale locale : list) {
        addLocale(locale);
      }
    }
  }
  
  protected static final boolean isAlpha(String value)
  {
    for (int i = 0; i < value.length(); i++)
    {
      char c = value.charAt(i);
      if (((c < 'a') || (c > 'z')) && ((c < 'A') || (c > 'Z'))) {
        return false;
      }
    }
    return true;
  }
  
  private static final Map<String, SpecialAttributeAdapter> specialAttributes = new HashMap();
  
  static
  {
    specialAttributes.put("org.apache.catalina.core.DISPATCHER_TYPE", new SpecialAttributeAdapter()
    {
      public Object get(Request request, String name)
      {
        return request.internalDispatcherType == null ? DispatcherType.REQUEST : request.internalDispatcherType;
      }
      
      public void set(Request request, String name, Object value)
      {
        request.internalDispatcherType = ((DispatcherType)value);
      }
    });
    specialAttributes.put("org.apache.catalina.core.DISPATCHER_REQUEST_PATH", new SpecialAttributeAdapter()
    {
      public Object get(Request request, String name)
      {
        return request.requestDispatcherPath == null ? request.getRequestPathMB().toString() : request.requestDispatcherPath.toString();
      }
      
      public void set(Request request, String name, Object value)
      {
        request.requestDispatcherPath = value;
      }
    });
    specialAttributes.put("org.apache.catalina.ASYNC_SUPPORTED", new SpecialAttributeAdapter()
    {
      public Object get(Request request, String name)
      {
        return request.asyncSupported;
      }
      
      public void set(Request request, String name, Object value)
      {
        Boolean oldValue = request.asyncSupported;
        request.asyncSupported = ((Boolean)value);
        request.notifyAttributeAssigned(name, value, oldValue);
      }
    });
    specialAttributes.put("org.apache.catalina.realm.GSS_CREDENTIAL", new SpecialAttributeAdapter()
    {
      public Object get(Request request, String name)
      {
        if ((request.userPrincipal instanceof GenericPrincipal)) {
          return ((GenericPrincipal)request.userPrincipal).getGssCredential();
        }
        return null;
      }
      
      public void set(Request request, String name, Object value) {}
    });
    specialAttributes.put("org.apache.catalina.parameter_parse_failed", new SpecialAttributeAdapter()
    {
      public Object get(Request request, String name)
      {
        if (request.getCoyoteRequest().getParameters().isParseFailed()) {
          return Boolean.TRUE;
        }
        return null;
      }
      
      public void set(Request request, String name, Object value) {}
    });
  }
  
  private static abstract interface SpecialAttributeAdapter
  {
    public abstract Object get(Request paramRequest, String paramString);
    
    public abstract void set(Request paramRequest, String paramString, Object paramObject);
  }
}
 

 

 

 

 

 

 

 

 

 

另一个内层属性Request:

package org.apache.coyote;

package org.apache.coyote;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.ReadListener;
import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.buf.UDecoder;
import org.apache.tomcat.util.http.MimeHeaders;
import org.apache.tomcat.util.http.Parameters;
import org.apache.tomcat.util.http.ServerCookies;
import org.apache.tomcat.util.net.ApplicationBufferHandler;
import org.apache.tomcat.util.res.StringManager;

public final class Request
{
  private static final StringManager sm = StringManager.getManager(Request.class);
  private static final int INITIAL_COOKIE_SIZE = 4;
  
  public Request()
  {
    this.parameters.setQuery(this.queryMB);
    this.parameters.setURLDecoder(this.urlDecoder);
  }
  
  private int serverPort = -1;
  private final MessageBytes serverNameMB = MessageBytes.newInstance();
  private int remotePort;
  private int localPort;
  private final MessageBytes schemeMB = MessageBytes.newInstance();
  private final MessageBytes methodMB = MessageBytes.newInstance();
  private final MessageBytes uriMB = MessageBytes.newInstance();
  private final MessageBytes decodedUriMB = MessageBytes.newInstance();
  private final MessageBytes queryMB = MessageBytes.newInstance();
  private final MessageBytes protoMB = MessageBytes.newInstance();
  private final MessageBytes remoteAddrMB = MessageBytes.newInstance();
  private final MessageBytes localNameMB = MessageBytes.newInstance();
  private final MessageBytes remoteHostMB = MessageBytes.newInstance();
  private final MessageBytes localAddrMB = MessageBytes.newInstance();
  private final MimeHeaders headers = new MimeHeaders();
  private final Map<String, String> trailerFields = new HashMap();
  private final Map<String, String> pathParameters = new HashMap();
  private final Object[] notes = new Object[32];
  private InputBuffer inputBuffer = null;
  private final UDecoder urlDecoder = new UDecoder();
  private long contentLength = -1L;
  private MessageBytes contentTypeMB = null;
  private Charset charset = null;
  private String characterEncoding = null;
  private boolean expectation = false;
  private final ServerCookies serverCookies = new ServerCookies(4);
  private final Parameters parameters = new Parameters();
  private final MessageBytes remoteUser = MessageBytes.newInstance();
  private boolean remoteUserNeedsAuthorization = false;
  private final MessageBytes authType = MessageBytes.newInstance();
  private final HashMap<String, Object> attributes = new HashMap();
  private Response response;
  private volatile ActionHook hook;
  private long bytesRead = 0L;
  private long startTime = -1L;
  private int available = 0;
  private final RequestInfo reqProcessorMX = new RequestInfo(this);
  private boolean sendfile = true;
  volatile ReadListener listener;
  
  public ReadListener getReadListener()
  {
    return this.listener;
  }
  
  public void setReadListener(ReadListener listener)
  {
    if (listener == null) {
      throw new NullPointerException(sm.getString("request.nullReadListener"));
    }
    if (getReadListener() != null) {
      throw new IllegalStateException(sm.getString("request.readListenerSet"));
    }
    AtomicBoolean result = new AtomicBoolean(false);
    action(ActionCode.ASYNC_IS_ASYNC, result);
    if (!result.get()) {
      throw new IllegalStateException(sm.getString("request.notAsync"));
    }
    this.listener = listener;
  }
  
  private final AtomicBoolean allDataReadEventSent = new AtomicBoolean(false);
  
  public boolean sendAllDataReadEvent()
  {
    return this.allDataReadEventSent.compareAndSet(false, true);
  }
  
  public MimeHeaders getMimeHeaders()
  {
    return this.headers;
  }
  
  public boolean isTrailerFieldsReady()
  {
    AtomicBoolean result = new AtomicBoolean(false);
    action(ActionCode.IS_TRAILER_FIELDS_READY, result);
    return result.get();
  }
  
  public Map<String, String> getTrailerFields()
  {
    return this.trailerFields;
  }
  
  public UDecoder getURLDecoder()
  {
    return this.urlDecoder;
  }
  
  public MessageBytes scheme()
  {
    return this.schemeMB;
  }
  
  public MessageBytes method()
  {
    return this.methodMB;
  }
  
  public MessageBytes requestURI()
  {
    return this.uriMB;
  }
  
  public MessageBytes decodedURI()
  {
    return this.decodedUriMB;
  }
  
  public MessageBytes queryString()
  {
    return this.queryMB;
  }
  
  public MessageBytes protocol()
  {
    return this.protoMB;
  }
  
  public MessageBytes serverName()
  {
    return this.serverNameMB;
  }
  
  public int getServerPort()
  {
    return this.serverPort;
  }
  
  public void setServerPort(int serverPort)
  {
    this.serverPort = serverPort;
  }
  
  public MessageBytes remoteAddr()
  {
    return this.remoteAddrMB;
  }
  
  public MessageBytes remoteHost()
  {
    return this.remoteHostMB;
  }
  
  public MessageBytes localName()
  {
    return this.localNameMB;
  }
  
  public MessageBytes localAddr()
  {
    return this.localAddrMB;
  }
  
  public int getRemotePort()
  {
    return this.remotePort;
  }
  
  public void setRemotePort(int port)
  {
    this.remotePort = port;
  }
  
  public int getLocalPort()
  {
    return this.localPort;
  }
  
  public void setLocalPort(int port)
  {
    this.localPort = port;
  }
  
  public String getCharacterEncoding()
  {
    if (this.characterEncoding == null) {
      this.characterEncoding = getCharsetFromContentType(getContentType());
    }
    return this.characterEncoding;
  }
  
  public Charset getCharset()
    throws UnsupportedEncodingException
  {
    if (this.charset == null)
    {
      getCharacterEncoding();
      if (this.characterEncoding != null) {
        this.charset = B2CConverter.getCharset(this.characterEncoding);
      }
    }
    return this.charset;
  }
  
  public void setCharset(Charset charset)
  {
    this.charset = charset;
    this.characterEncoding = charset.name();
  }
  
  public void setContentLength(long len)
  {
    this.contentLength = len;
  }
  
  public int getContentLength()
  {
    long length = getContentLengthLong();
    if (length < 2147483647L) {
      return (int)length;
    }
    return -1;
  }
  
  public long getContentLengthLong()
  {
    if (this.contentLength > -1L) {
      return this.contentLength;
    }
    MessageBytes clB = this.headers.getUniqueValue("content-length");
    this.contentLength = ((clB == null) || (clB.isNull()) ? -1L : clB.getLong());
    
    return this.contentLength;
  }
  
  public String getContentType()
  {
    contentType();
    if ((this.contentTypeMB == null) || (this.contentTypeMB.isNull())) {
      return null;
    }
    return this.contentTypeMB.toString();
  }
  
  public void setContentType(String type)
  {
    this.contentTypeMB.setString(type);
  }
  
  public MessageBytes contentType()
  {
    if (this.contentTypeMB == null) {
      this.contentTypeMB = this.headers.getValue("content-type");
    }
    return this.contentTypeMB;
  }
  
  public void setContentType(MessageBytes mb)
  {
    this.contentTypeMB = mb;
  }
  
  public String getHeader(String name)
  {
    return this.headers.getHeader(name);
  }
  
  public void setExpectation(boolean expectation)
  {
    this.expectation = expectation;
  }
  
  public boolean hasExpectation()
  {
    return this.expectation;
  }
  
  public Response getResponse()
  {
    return this.response;
  }
  
  public void setResponse(Response response)
  {
    this.response = response;
    response.setRequest(this);
  }
  
  protected void setHook(ActionHook hook)
  {
    this.hook = hook;
  }
  
  public void action(ActionCode actionCode, Object param)
  {
    if (this.hook != null) {
      if (param == null) {
        this.hook.action(actionCode, this);
      } else {
        this.hook.action(actionCode, param);
      }
    }
  }
  
  public ServerCookies getCookies()
  {
    return this.serverCookies;
  }
  
  public Parameters getParameters()
  {
    return this.parameters;
  }
  
  public void addPathParameter(String name, String value)
  {
    this.pathParameters.put(name, value);
  }
  
  public String getPathParameter(String name)
  {
    return (String)this.pathParameters.get(name);
  }
  
  public void setAttribute(String name, Object o)
  {
    this.attributes.put(name, o);
  }
  
  public HashMap<String, Object> getAttributes()
  {
    return this.attributes;
  }
  
  public Object getAttribute(String name)
  {
    return this.attributes.get(name);
  }
  
  public MessageBytes getRemoteUser()
  {
    return this.remoteUser;
  }
  
  public boolean getRemoteUserNeedsAuthorization()
  {
    return this.remoteUserNeedsAuthorization;
  }
  
  public void setRemoteUserNeedsAuthorization(boolean remoteUserNeedsAuthorization)
  {
    this.remoteUserNeedsAuthorization = remoteUserNeedsAuthorization;
  }
  
  public MessageBytes getAuthType()
  {
    return this.authType;
  }
  
  public int getAvailable()
  {
    return this.available;
  }
  
  public void setAvailable(int available)
  {
    this.available = available;
  }
  
  public boolean getSendfile()
  {
    return this.sendfile;
  }
  
  public void setSendfile(boolean sendfile)
  {
    this.sendfile = sendfile;
  }
  
  public boolean isFinished()
  {
    AtomicBoolean result = new AtomicBoolean(false);
    action(ActionCode.REQUEST_BODY_FULLY_READ, result);
    return result.get();
  }
  
  public boolean getSupportsRelativeRedirects()
  {
    if ((protocol().equals("")) || (protocol().equals("HTTP/1.0"))) {
      return false;
    }
    return true;
  }
  
  public InputBuffer getInputBuffer()
  {
    return this.inputBuffer;
  }
  
  public void setInputBuffer(InputBuffer inputBuffer)
  {
    this.inputBuffer = inputBuffer;
  }
  
  public int doRead(ApplicationBufferHandler handler)
    throws IOException
  {
    int n = this.inputBuffer.doRead(handler);
    if (n > 0) {
      this.bytesRead += n;
    }
    return n;
  }
  
  public String toString()
  {
    return "R( " + requestURI().toString() + ")";
  }
  
  public long getStartTime()
  {
    return this.startTime;
  }
  
  public void setStartTime(long startTime)
  {
    this.startTime = startTime;
  }
  
  public final void setNote(int pos, Object value)
  {
    this.notes[pos] = value;
  }
  
  public final Object getNote(int pos)
  {
    return this.notes[pos];
  }
  
  public void recycle()
  {
    this.bytesRead = 0L;
    
    this.contentLength = -1L;
    this.contentTypeMB = null;
    this.charset = null;
    this.characterEncoding = null;
    this.expectation = false;
    this.headers.recycle();
    this.trailerFields.clear();
    this.serverNameMB.recycle();
    this.serverPort = -1;
    this.localAddrMB.recycle();
    this.localNameMB.recycle();
    this.localPort = -1;
    this.remoteAddrMB.recycle();
    this.remoteHostMB.recycle();
    this.remotePort = -1;
    this.available = 0;
    this.sendfile = true;
    
    this.serverCookies.recycle();
    this.parameters.recycle();
    this.pathParameters.clear();
    
    this.uriMB.recycle();
    this.decodedUriMB.recycle();
    this.queryMB.recycle();
    this.methodMB.recycle();
    this.protoMB.recycle();
    
    this.schemeMB.recycle();
    
    this.remoteUser.recycle();
    this.remoteUserNeedsAuthorization = false;
    this.authType.recycle();
    this.attributes.clear();
    
    this.listener = null;
    this.allDataReadEventSent.set(false);
    
    this.startTime = -1L;
  }
  
  public void updateCounters()
  {
    this.reqProcessorMX.updateCounters();
  }
  
  public RequestInfo getRequestProcessor()
  {
    return this.reqProcessorMX;
  }
  
  public long getBytesRead()
  {
    return this.bytesRead;
  }
  
  public boolean isProcessing()
  {
    return this.reqProcessorMX.getStage() == 3;
  }
  
  private static String getCharsetFromContentType(String contentType)
  {
    if (contentType == null) {
      return null;
    }
    int start = contentType.indexOf("charset=");
    if (start < 0) {
      return null;
    }
    String encoding = contentType.substring(start + 8);
    int end = encoding.indexOf(';');
    if (end >= 0) {
      encoding = encoding.substring(0, end);
    }
    encoding = encoding.trim();
    if ((encoding.length() > 2) && (encoding.startsWith("\"")) && 
      (encoding.endsWith("\""))) {
      encoding = encoding.substring(1, encoding.length() - 1);
    }
    return encoding.trim();
  }
}
 

 

public Parameters getParameters()
  {
    return this.parameters;
  }