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.
  */
 
 package org.apache.coyote;
 
 
 
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(s):
James Duncan Davidson [duncan@eng.sun.com]
James Todd [gonzo@eng.sun.com]
Jason Hunter [jch@eng.sun.com]
Harish Prabandham
Alex Cruikshank [alex@epitonic.com]
Hans Bergsten [hans@gefionsoftware.com]
Costin Manolache
Remy Maucherat
 
 public final class Request {
 
 
     // ----------------------------------------------------------- Constructors
 
 
     public Request() {
 
         .setQuery();
 
     }
 
 
     // ----------------------------------------------------- Instance Variables
 
 
     private int serverPort = -1;
     private MessageBytes serverNameMB = MessageBytes.newInstance();
 
     private int remotePort;
     private int localPort;
 
     private MessageBytes schemeMB = MessageBytes.newInstance();
 
     private MessageBytes methodMB = MessageBytes.newInstance();
     private MessageBytes unparsedURIMB = MessageBytes.newInstance();
     private MessageBytes uriMB = MessageBytes.newInstance();
     private MessageBytes decodedUriMB = MessageBytes.newInstance();
     private MessageBytes queryMB = MessageBytes.newInstance();
     private MessageBytes protoMB = MessageBytes.newInstance();
 
     // remote address/host
     private MessageBytes remoteAddrMB = MessageBytes.newInstance();
    private MessageBytes localNameMB = MessageBytes.newInstance();
    private MessageBytes remoteHostMB = MessageBytes.newInstance();
    private MessageBytes localAddrMB = MessageBytes.newInstance();
     
    private MimeHeaders headers = new MimeHeaders();
    private MessageBytes instanceId = MessageBytes.newInstance();

    
Notes.
    private Object notes[] = new Object[.];


    
Associated input buffer.
    private InputBuffer inputBuffer = null;


    
URL decoder.
    private UDecoder urlDecoder = new UDecoder();


    
HTTP specific fields. (remove them ?)
    private long contentLength = -1;
    private MessageBytes contentTypeMB = null;
    private String charEncoding = null;
    private Cookies cookies = new Cookies();
    private Parameters parameters = new Parameters();
    private MessageBytes remoteUser=MessageBytes.newInstance();
    private MessageBytes authType=MessageBytes.newInstance();
    private HashMap attributes=new HashMap();
    private Response response;
    private ActionHook hook;
    private int bytesRead=0;
    // Time of the request - usefull to avoid repeated calls to System.currentTime
    private long startTime = 0L;
    private int available = 0;
    private boolean sendfile = false;
    private RequestInfo reqProcessorMX=new RequestInfo(this);
    // ------------------------------------------------------------- Properties


    
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.

Returns:
the instance id
    public MessageBytes instanceId() {
        return ;
    }
    public MimeHeaders getMimeHeaders() {
        return ;
    }
    public UDecoder getURLDecoder() {
        return ;
    }
    public boolean hasSendfile() {
        return ;
    }
    public void setSendfile(boolean sendfile) {
        this. = sendfile;
    }
    // -------------------- Request data --------------------
    public MessageBytes scheme() {
        return ;
    }
    
    public MessageBytes method() {
        return ;
    }
    
    public MessageBytes unparsedURI() {
        return ;
    }
    public MessageBytes requestURI() {
        return ;
    }
    public MessageBytes decodedURI() {
        return ;
    }
    public MessageBytes query() {
        return ;
    }
    public MessageBytes queryString() {
        return ;
    }
    public MessageBytes protocol() {
        return ;
    }
    
    
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.
    public MessageBytes serverName() {
        return ;
    }
    public int getServerPort() {
        return ;
    }
    
    public void setServerPort(int serverPort ) {
        this.=serverPort;
    }
    public MessageBytes remoteAddr() {
        return ;
    }
    public MessageBytes remoteHost() {
        return ;
    }
    public MessageBytes localName() {
        return ;
    }    
    public MessageBytes localAddr() {
        return ;
    }
    
    public int getRemotePort(){
        return ;
    }
        
    public void setRemotePort(int port){
        this. = port;
    }
    
    public int getLocalPort(){
        return ;
    }
        
    public void setLocalPort(int port){
        this. = port;
    }
    // -------------------- encoding/type --------------------


    
Get the character encoding used for this request.
    public String getCharacterEncoding() {
        if ( != null)
            return ;
         = ContentType.getCharsetFromContentType(getContentType());
        return ;
    }
    public void setCharacterEncoding(String enc) {
        this. = enc;
    }
    public void setContentLength(long len) {
        this. = len;
    }
    public int getContentLength() {
        long length = getContentLengthLong();
        if (length < .) {
            return (intlength;
        }
        return -1;
    }
    public long getContentLengthLong() {
        if > -1 ) return ;
        MessageBytes clB = .getUniqueValue("content-length");
         = (clB == null || clB.isNull()) ? -1 : clB.getLong();
        return ;
    }
    public String getContentType() {
        contentType();
        if (( == null) || .isNull()) 
            return null;
        return .toString();
    }
    public void setContentType(String type) {
        .setString(type);
    }
    public MessageBytes contentType() {
        if ( == null)
             = .getValue("content-type");
        return ;
    }
    public void setContentType(MessageBytes mb) {
        =mb;
    }
    public String getHeader(String name) {
        return .getHeader(name);
    }
    // -------------------- Associated response --------------------
    public Response getResponse() {
        return ;
    }
    public void setResponseResponse response ) {
        this.=response;
        response.setRequestthis );
    }
    
    public void action(ActionCode actionCodeObject param) {
        if==null && !=null )
            =.getHook();
        
        if ( != null) {
            ifparam==null ) 
                .action(actionCodethis);
            else
                .action(actionCodeparam);
        }
    }
    // -------------------- Cookies --------------------
    public Cookies getCookies() {
        return ;
    }
    // -------------------- Parameters --------------------
    public Parameters getParameters() {
        return ;
    }
    // -------------------- Other attributes --------------------
    // We can use notes for most - need to discuss what is of general interest
    
    public void setAttributeString nameObject o ) {
        .putnameo );
    }
    public HashMap getAttributes() {
        return ;
    }
    public Object getAttribute(String name ) {
        return .get(name);
    }
    
    public MessageBytes getRemoteUser() {
        return ;
    }
    public MessageBytes getAuthType() {
        return ;
    }
    public int getAvailable() {
        return ;
    }
    public void setAvailable(int available) {
        this. = available;
    }
    // -------------------- Input Buffer --------------------
    public InputBuffer getInputBuffer() {
        return ;
    }
    public void setInputBuffer(InputBuffer inputBuffer) {
        this. = inputBuffer;
    }


    
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.
    public int doRead(ByteChunk chunk
        throws IOException {
        int n = .doRead(chunkthis);
        if (n > 0) {
            +=n;
        }
        return n;
    }
    // -------------------- debug --------------------
    public String toString() {
        return "R( " + requestURI().toString() + ")";
    }
    public long getStartTime() {
        return ;
    }
    public void setStartTime(long startTime) {
        this. = startTime;
    }
    // -------------------- Per-Request "notes" --------------------


    
Used to store private data. Thread data could be used instead - but if you have the req, getting/setting a note is just a array access, may be faster than ThreadLocal for very frequent operations. Example use: Jk: HandlerRequest.HOSTBUFFER = 10 CharChunk, buffer for Host decoding WorkerEnv: SSL_CERT_NOTE=16 - MessageBytes containing the cert Catalina CoyoteAdapter: ADAPTER_NOTES = 1 - stores the HttpServletRequest object ( req/res) To avoid conflicts, note in the range 0 - 8 are reserved for the servlet container ( catalina connector, etc ), and values in 9 - 16 for connector use. 17-31 range is not allocated or used.
    public final void setNote(int posObject value) {
        [pos] = value;
    }
    public final Object getNote(int pos) {
        return [pos];
    }
    // -------------------- Recycling -------------------- 
    public void recycle() {
        =0;
         = -1;
         = null;
         = null;
        .recycle();
        .recycle();
        =-1;
        .recycle();
         = -1;
         = -1;
         = 0;
        .recycle();
        .recycle();
        .recycle();
        .recycle(); 
        .recycle();
        .recycle();
        .recycle();
        .recycle();
        .recycle();
        .recycle();
        .recycle();
        .recycle();
        .clear();
    }
    // -------------------- Info  --------------------
    public void updateCounters() {
    }
    public RequestInfo getRequestProcessor() {
        return ;
    }
    public int getBytesRead() {
        return ;
    }
    public void setBytesRead(int bytesRead) {
        this. = bytesRead;
    }
New to GrepCode? Check out our FAQ X