FileDocCategorySizeDatePackage
Request.javaAPI DocGlassfish v2 API14934Tue Jun 05 14:49:24 BST 2007org.apache.coyote

Request

public final class Request extends Object
This is a low-level, efficient representation of a server request. Most fields are GC-free, expensive operations are delayed until the user code needs the information. Processing is delegated to modules, using a hook mechanism. This class is not intended for user code - it is used internally by tomcat for processing the request in the most efficient way. Users ( servlets ) can access the information using a facade, which provides the high-level view of the request. For lazy evaluation, the request uses the getInfo() hook. The following ids are defined:
  • req.encoding - returns the request encoding
  • req.attribute - returns a module-specific attribute ( like SSL keys, etc ).
Tomcat defines a number of attributes:
  • "org.apache.tomcat.request" - allows access to the low-level request object in trusted applications
author
James Duncan Davidson [duncan@eng.sun.com]
author
James Todd [gonzo@eng.sun.com]
author
Jason Hunter [jch@eng.sun.com]
author
Harish Prabandham
author
Alex Cruikshank [alex@epitonic.com]
author
Hans Bergsten [hans@gefionsoftware.com]
author
Costin Manolache
author
Remy Maucherat

Fields Summary
private int
serverPort
private org.apache.tomcat.util.buf.MessageBytes
serverNameMB
private String
localHost
private int
remotePort
private int
localPort
private org.apache.tomcat.util.buf.MessageBytes
schemeMB
private org.apache.tomcat.util.buf.MessageBytes
methodMB
private org.apache.tomcat.util.buf.MessageBytes
unparsedURIMB
private org.apache.tomcat.util.buf.MessageBytes
uriMB
private org.apache.tomcat.util.buf.MessageBytes
decodedUriMB
private org.apache.tomcat.util.buf.MessageBytes
queryMB
private org.apache.tomcat.util.buf.MessageBytes
protoMB
private org.apache.tomcat.util.buf.MessageBytes
remoteAddrMB
private org.apache.tomcat.util.buf.MessageBytes
localNameMB
private org.apache.tomcat.util.buf.MessageBytes
remoteHostMB
private org.apache.tomcat.util.buf.MessageBytes
localAddrMB
private org.apache.tomcat.util.http.MimeHeaders
headers
private org.apache.tomcat.util.buf.MessageBytes
instanceId
private NotesManagerImpl
notesManager
Notes.
private InputBuffer
inputBuffer
Associated input buffer.
private org.apache.tomcat.util.buf.UDecoder
urlDecoder
URL decoder.
private long
contentLength
HTTP specific fields. (remove them ?)
private org.apache.tomcat.util.buf.MessageBytes
contentTypeMB
private String
charEncoding
private boolean
charEncodingParsed
private org.apache.tomcat.util.http.Cookies
cookies
private org.apache.tomcat.util.http.Parameters
parameters
private org.apache.tomcat.util.buf.MessageBytes
remoteUser
private org.apache.tomcat.util.buf.MessageBytes
authType
private HashMap
attributes
private Response
response
private ActionHook
hook
private int
bytesRead
private long
startTime
private RequestInfo
reqProcessorMX
Constructors Summary
public Request()


        parameters.setQuery(queryMB);
        parameters.setURLDecoder(urlDecoder);
        parameters.setHeaders(headers);

        schemeMB.setString("http");
        methodMB.setString("GET");
        /* SJSWS 6376484
        uriMB.setString("/");
        */
        queryMB.setString("");
        protoMB.setString("HTTP/1.0");

    
Methods Summary
public voidaction(ActionCode actionCode, java.lang.Object param)

        if( hook==null && response!=null )
            hook=response.getHook();
        
        if (hook != null) {
            if( param==null ) 
                hook.action(actionCode, this);
            else
                hook.action(actionCode, param);
        }
    
public org.apache.tomcat.util.buf.MessageBytescontentType()

        if (contentTypeMB == null)
            contentTypeMB = headers.getValue("content-type");
        return contentTypeMB;
    
public org.apache.tomcat.util.buf.MessageBytesdecodedURI()

        return decodedUriMB;
    
public intdoRead(org.apache.tomcat.util.buf.ByteChunk chunk)
Read data from the input buffer and put it into a byte chunk. The buffer is owned by the protocol implementation - it will be reused on the next read. The Adapter must either process the data in place or copy it to a separate buffer if it needs to hold it. In most cases this is done during byte->char conversions or via InputStream. Unlike InputStream, this interface allows the app to process data in place, without copy.

        int n = inputBuffer.doRead(chunk, this);
        if (n > 0) {
            bytesRead+=n;
        }
        return n;
    
public java.lang.ObjectgetAttribute(java.lang.String name)

        return attributes.get(name);
    
public java.util.HashMapgetAttributes()

        return attributes;
    
public org.apache.tomcat.util.buf.MessageBytesgetAuthType()

        return authType;
    
public intgetBytesRead()

        return bytesRead;
    
public java.lang.StringgetCharacterEncoding()
Get the character encoding used for this request.


        if (charEncoding != null || charEncodingParsed) {
            return charEncoding;
        }

        charEncoding = ContentType.getCharsetFromContentType(getContentType());
        charEncodingParsed = true;

        return charEncoding;
    
public intgetContentLength()

        long length = getContentLengthLong();
        
        if (length < Integer.MAX_VALUE) {
            return (int) length;
        }
        return -1;
    
public longgetContentLengthLong()

        if( contentLength > -1 ) return contentLength;

        MessageBytes clB = headers.getUniqueValue("content-length");
        contentLength = (clB == null || clB.isNull()) ? -1 : clB.getLong();

        return contentLength;
    
public java.lang.StringgetContentType()

        contentType();
        if ((contentTypeMB == null) || contentTypeMB.isNull()) 
            return null;
        return contentTypeMB.toString();
    
public org.apache.tomcat.util.http.CookiesgetCookies()

	return cookies;
    
public java.lang.StringgetHeader(java.lang.String name)

        return headers.getHeader(name);
    
public InputBuffergetInputBuffer()

        return inputBuffer;
    
public java.lang.StringgetLocalHost()

	return localHost;
    
public intgetLocalPort()

        return localPort;
    
public org.apache.tomcat.util.http.MimeHeadersgetMimeHeaders()

        return headers;
    
public final java.lang.ObjectgetNote(int pos)

	return notesManager.getNote(pos);
    
public NotesManagerImplgetNotesManager()

        return notesManager;
    
public org.apache.tomcat.util.http.ParametersgetParameters()

	return parameters;
    
public intgetRemotePort()

        return remotePort;
    
public org.apache.tomcat.util.buf.MessageBytesgetRemoteUser()

        return remoteUser;
    
public RequestInfogetRequestProcessor()

        return reqProcessorMX;
    
public ResponsegetResponse()

        return response;
    
public intgetServerPort()

        return serverPort;
    
public longgetStartTime()

        return startTime;
    
public org.apache.tomcat.util.buf.UDecodergetURLDecoder()

        return urlDecoder;
    
public org.apache.tomcat.util.buf.MessageBytesinstanceId()
Get the instance id (or JVM route). Curently Ajp is sending it with each request. In future this should be fixed, and sent only once ( or 'negociated' at config time so both tomcat and apache share the same name.

return
the instance id

    // ------------------------------------------------------------- Properties


                                                      
       
        return instanceId;
    
public org.apache.tomcat.util.buf.MessageByteslocalAddr()

	return localAddrMB;
    
public org.apache.tomcat.util.buf.MessageByteslocalName()

	return localNameMB;
    
public org.apache.tomcat.util.buf.MessageBytesmethod()

        return methodMB;
    
public org.apache.tomcat.util.buf.MessageBytesprotocol()

        return protoMB;
    
public org.apache.tomcat.util.buf.MessageBytesquery()

        return queryMB;
    
public org.apache.tomcat.util.buf.MessageBytesqueryString()

        return queryMB;
    
public voidrecycle()

        bytesRead=0;

	contentLength = -1;
        contentTypeMB = null;
        charEncoding = null;
        charEncodingParsed = false;
        headers.recycle();
        serverNameMB.recycle();
        serverPort=-1;
        localPort = -1;
        remotePort = -1;

	cookies.recycle();
        parameters.recycle();

        unparsedURIMB.recycle();
        uriMB.recycle(); 
        decodedUriMB.recycle();
	queryMB.recycle();
	methodMB.recycle();
	protoMB.recycle();
	//remoteAddrMB.recycle();
	//remoteHostMB.recycle();

	// XXX Do we need such defaults ?
        schemeMB.recycle();
	methodMB.setString("GET");
        /* SJSWS 6376484
        uriMB.setString("/");
        */
        queryMB.setString("");
        protoMB.setString("HTTP/1.0");
        //remoteAddrMB.setString("127.0.0.1");
        //remoteHostMB.setString("localhost");

        instanceId.recycle();
        remoteUser.recycle();
        authType.recycle();
        attributes.clear();
    
public org.apache.tomcat.util.buf.MessageBytesremoteAddr()

	return remoteAddrMB;
    
public org.apache.tomcat.util.buf.MessageBytesremoteHost()

	return remoteHostMB;
    
public org.apache.tomcat.util.buf.MessageBytesrequestURI()

        return uriMB;
    
public org.apache.tomcat.util.buf.MessageBytesscheme()

        return schemeMB;
    
public org.apache.tomcat.util.buf.MessageBytesserverName()
Return the buffer holding the server name, if any. Use isNull() to check if there is no value set. This is the "virtual host", derived from the Host: header.

	return serverNameMB;
    
public voidsetAttribute(java.lang.String name, java.lang.Object o)

        attributes.put( name, o );
    
public voidsetBytesRead(int bytesRead)

        this.bytesRead = bytesRead;
    
public voidsetCharacterEncoding(java.lang.String enc)

	this.charEncoding = enc;
    
public voidsetContentLength(int len)

	this.contentLength = len;
    
public voidsetContentType(java.lang.String type)

        contentTypeMB.setString(type);
    
public voidsetContentType(org.apache.tomcat.util.buf.MessageBytes mb)

        contentTypeMB=mb;
    
public voidsetInputBuffer(InputBuffer inputBuffer)

        this.inputBuffer = inputBuffer;
    
public voidsetLocalHost(java.lang.String host)

	this.localHost = host;
    
public voidsetLocalPort(int port)

        this.localPort = port;
    
public final voidsetNote(int pos, java.lang.Object value)

	notesManager.setNote(pos,value);
    
public voidsetNotesManager(NotesManagerImpl notesManager)

        this.notesManager = notesManager;
    
public voidsetRemotePort(int port)

        this.remotePort = port;
    
public voidsetResponse(Response response)

        this.response=response;
        response.setRequest( this );
    
public voidsetServerPort(int serverPort)

	this.serverPort=serverPort;
    
public voidsetStartTime(long startTime)

        this.startTime = startTime;
    
public java.lang.StringtoString()

	return "R( " + requestURI().toString() + ")";
    
public org.apache.tomcat.util.buf.MessageBytesunparsedURI()

        return unparsedURIMB;
    
public voidupdateCounters()

        reqProcessorMX.updateCounters();