Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Licensed to the Apache Software Foundation (ASF) under one or more
   *  contributor license agreements.  See the NOTICE file distributed with
   *  this work for additional information regarding copyright ownership.
   *  The ASF licenses this file to You 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.
  */

Description: Base http request object. * Author: Keving Seguin [seguin@apache.org] * Version: $Revision: 1273 $ * /
 
 
 package org.apache.tomcat.util.http;
 
 
 
A general-purpose object for representing an HTTP request.
 
 public class BaseRequest {
 
     // scheme constants
     public static final String SCHEME_HTTP = "http";
     public static final String SCHEME_HTTPS = "https";
 
     // request attributes
     MessageBytes method = MessageBytes.newInstance();
     MessageBytes protocol = MessageBytes.newInstance();
     MessageBytes requestURI = MessageBytes.newInstance();
     MessageBytes remoteAddr = MessageBytes.newInstance();
     MessageBytes remoteHost = MessageBytes.newInstance();
     MessageBytes serverName = MessageBytes.newInstance();
     int serverPort = 80;
     MessageBytes remoteUser = MessageBytes.newInstance();
     MessageBytes authType = MessageBytes.newInstance();
     MessageBytes queryString = MessageBytes.newInstance();
     MessageBytes authorization = MessageBytes.newInstance();
     String scheme = ;
     boolean secure = false;
     int contentLength = 0;
     MessageBytes contentType = MessageBytes.newInstance();
     MimeHeaders headers = new MimeHeaders();
     Cookies cookies = new Cookies();
     HashMap attributes = new HashMap();
 
     MessageBytes tomcatInstanceId = MessageBytes.newInstance();
    
    
Recycles this object and readies it further use.
 
     public void recycle() {
         .recycle();
         .recycle();
         .recycle();
         .recycle();
         .recycle();
         .recycle();
          = 80;
         .recycle();
         .recycle();
         .recycle();
         .recycle();
          = ;
          = false;
          = 0;
         .recycle();
         .recycle();
         .recycle();
         .clear();
         .recycle();
     }

    
Get the method.

Returns:
the method
 
     public MessageBytes method() {
         return ;
     }

    
Get the protocol

Returns:
the protocol
    public MessageBytes protocol() {
        return ;
    }

    
Get the request uri

Returns:
the request uri
    public MessageBytes requestURI() {
        return ;
    }

    
Get the remote address

Returns:
the remote address
    public MessageBytes remoteAddr() {
        return ;
    }

    
Get the remote host

Returns:
the remote host
    public MessageBytes remoteHost() {
        return ;
    }

    
Get the server name

Returns:
the server name
    public MessageBytes serverName() {
        return ;
    }

    
Get the server port

Returns:
the server port
    public int getServerPort() {
        return ;
    }

    
Set the server port

Parameters:
i the server port
    public void setServerPort(int i) {
         = i;
    }

    
Get the remote user

Returns:
the remote user
    public MessageBytes remoteUser() {
        return ;
    }

    
Get the auth type

Returns:
the auth type
    public MessageBytes authType() {
        return ;
    }

    
Get the query string

Returns:
the query string
    public MessageBytes queryString() {
        return ;
    }

    
Get the authorization credentials

Returns:
the authorization credentials
    public MessageBytes authorization() {
        return ;
    }

    
Get the scheme

Returns:
the scheme
    public String getScheme() {
        return ;
    }

    
Set the scheme.

Parameters:
s the scheme
    public void setScheme(String s) {
         = s;
    }

    
Get whether the request is secure or not.

Returns:
true if the request is secure.
    public boolean getSecure() {
        return ;
    }

    
Set whether the request is secure or not.

Parameters:
b true if the request is secure.
    public void setSecure(boolean b) {
         = b;
    }

    
Get the content length

Returns:
the content length
    public int getContentLength() {
        return ;
    }

    
Set the content length

Parameters:
i the content length
    public void setContentLength(int i) {
         = i;
    }

    
Get the content type

Returns:
the content type
    public MessageBytes contentType() {
        return ;
    }

    
Get this request's headers

Returns:
request headers
    public MimeHeaders headers() {
        return ;
    }

    
Get cookies.

Returns:
request cookies.
    public Cookies cookies() {
        return ;
    }

    
Set an attribute on the request

Parameters:
name attribute name
value attribute value
    public void setAttribute(String nameObject value) {
        if (name == null || value == null) {
            return;
        }
        .put(namevalue);
    }

    
Get an attribute on the request

Parameters:
name attribute name
Returns:
attribute value
    public Object getAttribute(String name) {
        if (name == null) {
            return null;
        }
        return .get(name);
    }

    
Get iterator over attribute names

Returns:
iterator over attribute names
    public Iterator getAttributeNames() {
        return .keySet().iterator();
    }

    
Get the host id ( or jvmRoute )

Returns:
the jvm route
    public MessageBytes instanceId() {
        return ;
    }
    // backward compat - jvmRoute is the id of this tomcat instance,
    // used by a load balancer on the server side to implement sticky
    // sessions, and on the tomcat side to format the session ids.
    public MessageBytes jvmRoute() {
        return ;
    }
    private Object notes[]=new Object[16];
    
    public final Object getNote(int id) {
        return [id];
    }
    public final void setNote(int idObject cr) {
        [id]=cr;
    }
    
    
** SLOW ** for debugging only!
    public String toString() {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        pw.println("=== BaseRequest ===");
        pw.println("method          = " + .toString());
        pw.println("protocol        = " + .toString());
        pw.println("requestURI      = " + .toString());
        pw.println("remoteAddr      = " + .toString());
        pw.println("remoteHost      = " + .toString());
        pw.println("serverName      = " + .toString());
        pw.println("serverPort      = " + );
        pw.println("remoteUser      = " + .toString());
        pw.println("authType        = " + .toString());
        pw.println("queryString     = " + .toString());
        pw.println("scheme          = " + .toString());
        pw.println("secure          = " + );
        pw.println("contentLength   = " + );
        pw.println("contentType     = " + );
        pw.println("attributes      = " + .toString());
        pw.println("headers         = " + .toString());
        pw.println("cookies         = " + .toString());
        pw.println("jvmRoute        = " + .toString());
        return sw.toString();
    }
    
New to GrepCode? Check out our FAQ X