You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/10/22 21:23:17 UTC

svn commit: r1187754 - in /tomcat/trunk/java/org/apache: coyote/Request.java tomcat/util/http/ContentType.java tomcat/util/http/MimeHeaders.java tomcat/util/http/Parameters.java tomcat/util/http/ServerCookie.java

Author: markt
Date: Sat Oct 22 19:23:17 2011
New Revision: 1187754

URL: http://svn.apache.org/viewvc?rev=1187754&view=rev
Log:
Remove unused code. Move utility method that is only usedonce to where
it is used.

Removed:
    tomcat/trunk/java/org/apache/tomcat/util/http/ContentType.java
Modified:
    tomcat/trunk/java/org/apache/coyote/Request.java
    tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java
    tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java
    tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java

Modified: tomcat/trunk/java/org/apache/coyote/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Request.java?rev=1187754&r1=1187753&r2=1187754&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Request.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Request.java Sat Oct 22 19:23:17 2011
@@ -23,18 +23,17 @@ import java.util.HashMap;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.buf.UDecoder;
-import org.apache.tomcat.util.http.ContentType;
 import org.apache.tomcat.util.http.Cookies;
 import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.http.Parameters;
 
 /**
- * This is a low-level, efficient representation of a server request. Most 
- * fields are GC-free, expensive operations are delayed until the  user code 
+ * 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
@@ -50,7 +49,7 @@ import org.apache.tomcat.util.http.Param
  * Tomcat defines a number of attributes:
  * <ul>
  *   <li>"org.apache.tomcat.request" - allows access to the low-level
- *       request object in trusted applications 
+ *       request object in trusted applications
  * </ul>
  *
  * @author James Duncan Davidson [duncan@eng.sun.com]
@@ -80,34 +79,34 @@ public final class Request {
 
 
     private int serverPort = -1;
-    private MessageBytes serverNameMB = MessageBytes.newInstance();
+    private final MessageBytes serverNameMB = MessageBytes.newInstance();
 
     private int remotePort;
     private int localPort;
 
-    private MessageBytes schemeMB = MessageBytes.newInstance();
+    private final 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();
+    private final MessageBytes methodMB = MessageBytes.newInstance();
+    private final MessageBytes unparsedURIMB = 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();
 
     // 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 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 MessageBytes instanceId = MessageBytes.newInstance();
+    private final MessageBytes instanceId = MessageBytes.newInstance();
 
     /**
      * Notes.
      */
-    private Object notes[] = new Object[Constants.MAX_NOTES];
+    private final Object notes[] = new Object[Constants.MAX_NOTES];
 
 
     /**
@@ -119,7 +118,7 @@ public final class Request {
     /**
      * URL decoder.
      */
-    private UDecoder urlDecoder = new UDecoder();
+    private final UDecoder urlDecoder = new UDecoder();
 
 
     /**
@@ -128,12 +127,12 @@ public final class Request {
     private long contentLength = -1;
     private MessageBytes contentTypeMB = null;
     private String charEncoding = null;
-    private Cookies cookies = new Cookies(headers);
-    private Parameters parameters = new Parameters();
+    private final Cookies cookies = new Cookies(headers);
+    private final Parameters parameters = new Parameters();
 
-    private MessageBytes remoteUser=MessageBytes.newInstance();
-    private MessageBytes authType=MessageBytes.newInstance();
-    private HashMap<String,Object> attributes=new HashMap<String,Object>();
+    private final MessageBytes remoteUser=MessageBytes.newInstance();
+    private final MessageBytes authType=MessageBytes.newInstance();
+    private final HashMap<String,Object> attributes=new HashMap<String,Object>();
 
     private Response response;
     private ActionHook hook;
@@ -143,7 +142,7 @@ public final class Request {
     private long startTime = 0L;
     private int available = 0;
 
-    private RequestInfo reqProcessorMX=new RequestInfo(this);
+    private final RequestInfo reqProcessorMX=new RequestInfo(this);
     // ------------------------------------------------------------- Properties
 
 
@@ -151,7 +150,7 @@ public final class Request {
      * Get the instance id (or JVM route). Currently Ajp is sending it with each
      * request. In future this should be fixed, and sent only once ( or
      * 'negotiated' at config time so both tomcat and apache share the same name.
-     * 
+     *
      * @return the instance id
      */
     public MessageBytes instanceId() {
@@ -174,11 +173,11 @@ public final class Request {
     public MessageBytes scheme() {
         return schemeMB;
     }
-    
+
     public MessageBytes method() {
         return methodMB;
     }
-    
+
     public MessageBytes unparsedURI() {
         return unparsedURIMB;
     }
@@ -198,8 +197,8 @@ public final class Request {
     public MessageBytes protocol() {
         return protoMB;
     }
-    
-    /** 
+
+    /**
      * Return the buffer holding the server name, if
      * any. Use isNull() to check if there is no value
      * set.
@@ -213,7 +212,7 @@ public final class Request {
     public int getServerPort() {
         return serverPort;
     }
-    
+
     public void setServerPort(int serverPort ) {
         this.serverPort=serverPort;
     }
@@ -228,24 +227,24 @@ public final class Request {
 
     public MessageBytes localName() {
         return localNameMB;
-    }    
+    }
 
     public MessageBytes localAddr() {
         return localAddrMB;
     }
-    
+
     public int getRemotePort(){
         return remotePort;
     }
-        
+
     public void setRemotePort(int port){
         this.remotePort = port;
     }
-    
+
     public int getLocalPort(){
         return localPort;
     }
-        
+
     public void setLocalPort(int port){
         this.localPort = port;
     }
@@ -258,10 +257,11 @@ public final class Request {
      */
     public String getCharacterEncoding() {
 
-        if (charEncoding != null)
+        if (charEncoding != null) {
             return charEncoding;
+        }
 
-        charEncoding = ContentType.getCharsetFromContentType(getContentType());
+        charEncoding = getCharsetFromContentType(getContentType());
         return charEncoding;
 
     }
@@ -287,7 +287,9 @@ public final class Request {
     }
 
     public long getContentLengthLong() {
-        if( contentLength > -1 ) return contentLength;
+        if( contentLength > -1 ) {
+            return contentLength;
+        }
 
         MessageBytes clB = headers.getUniqueValue("content-length");
         contentLength = (clB == null || clB.isNull()) ? -1 : clB.getLong();
@@ -297,8 +299,9 @@ public final class Request {
 
     public String getContentType() {
         contentType();
-        if ((contentTypeMB == null) || contentTypeMB.isNull()) 
+        if ((contentTypeMB == null) || contentTypeMB.isNull()) {
             return null;
+        }
         return contentTypeMB.toString();
     }
 
@@ -309,8 +312,9 @@ public final class Request {
 
 
     public MessageBytes contentType() {
-        if (contentTypeMB == null)
+        if (contentTypeMB == null) {
             contentTypeMB = headers.getValue("content-type");
+        }
         return contentTypeMB;
     }
 
@@ -334,16 +338,18 @@ public final class Request {
         this.response=response;
         response.setRequest( this );
     }
-    
+
     public void action(ActionCode actionCode, Object param) {
-        if( hook==null && response!=null )
+        if( hook==null && response!=null ) {
             hook=response.getHook();
-        
+        }
+
         if (hook != null) {
-            if( param==null ) 
+            if( param==null ) {
                 hook.action(actionCode, this);
-            else
+            } else {
                 hook.action(actionCode, param);
+            }
         }
     }
 
@@ -366,7 +372,7 @@ public final class Request {
 
     // -------------------- Other attributes --------------------
     // We can use notes for most - need to discuss what is of general interest
-    
+
     public void setAttribute( String name, Object o ) {
         attributes.put( name, o );
     }
@@ -378,7 +384,7 @@ public final class Request {
     public Object getAttribute(String name ) {
         return attributes.get(name);
     }
-    
+
     public MessageBytes getRemoteUser() {
         return remoteUser;
     }
@@ -417,7 +423,7 @@ public final class Request {
      * InputStream, this interface allows the app to process data in place, without copy.
      *
      */
-    public int doRead(ByteChunk chunk) 
+    public int doRead(ByteChunk chunk)
         throws IOException {
         int n = inputBuffer.doRead(chunk, this);
         if (n > 0) {
@@ -445,23 +451,23 @@ public final class Request {
     // -------------------- Per-Request "notes" --------------------
 
 
-    /** 
-     * Used to store private data. Thread data could be used instead - but 
+    /**
+     * 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: 
+     *
+     *  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. 
-     *   
+     *      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 pos, Object value) {
@@ -474,7 +480,7 @@ public final class Request {
     }
 
 
-    // -------------------- Recycling -------------------- 
+    // -------------------- Recycling --------------------
 
 
     public void recycle() {
@@ -494,7 +500,7 @@ public final class Request {
         parameters.recycle();
 
         unparsedURIMB.recycle();
-        uriMB.recycle(); 
+        uriMB.recycle();
         decodedUriMB.recycle();
         queryMB.recycle();
         methodMB.recycle();
@@ -524,4 +530,35 @@ public final class Request {
     public boolean isProcessing() {
         return reqProcessorMX.getStage()==org.apache.coyote.Constants.STAGE_SERVICE;
     }
+
+    /**
+     * Parse the character encoding from the specified content type header.
+     * If the content type is null, or there is no explicit character encoding,
+     * <code>null</code> is returned.
+     *
+     * @param contentType a content type header
+     */
+    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());
+
+    }
+
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java?rev=1187754&r1=1187753&r2=1187754&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/MimeHeaders.java Sat Oct 22 19:23:17 2011
@@ -253,15 +253,6 @@ public class MimeHeaders {
         return mhf.getValue();
     }
 
-    /** Create a new named header using translated char[].
-     */
-    public MessageBytes addValue(char c[], int startN, int len)
-    {
-        MimeHeaderField mhf=createHeader();
-        mhf.getName().setChars(c, startN, len);
-        return mhf.getValue();
-    }
-
     /** Allow "set" operations -
         return a MessageBytes container for the
         header value ( existing header or new
@@ -454,11 +445,6 @@ class ValuesEnumerator implements Enumer
 }
 
 class MimeHeaderField {
-    // multiple headers with same name - a linked list will
-    // speed up name enumerations and search ( both cpu and
-    // GC)
-    MimeHeaderField next;
-    MimeHeaderField prev;
 
     protected final MessageBytes nameB = MessageBytes.newInstance();
     protected final MessageBytes valueB = MessageBytes.newInstance();
@@ -473,7 +459,6 @@ class MimeHeaderField {
     public void recycle() {
         nameB.recycle();
         valueB.recycle();
-        next=null;
     }
 
     public MessageBytes getName() {

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java?rev=1187754&r1=1187753&r2=1187754&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java Sat Oct 22 19:23:17 2011
@@ -32,13 +32,9 @@ import org.apache.tomcat.util.buf.UDecod
  */
 public final class Parameters {
 
-
     private static final org.apache.juli.logging.Log log=
         org.apache.juli.logging.LogFactory.getLog(Parameters.class );
 
-    // Transition: we'll use the same Hashtable( String->String[] )
-    // for the beginning. When we are sure all accesses happen through
-    // this class - we can switch to MultiMap
     private final Hashtable<String,String[]> paramHashStringArray =
         new Hashtable<String,String[]>();
     private boolean didQueryParameters=false;

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java?rev=1187754&r1=1187753&r2=1187754&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/ServerCookie.java Sat Oct 22 19:23:17 2011
@@ -46,11 +46,9 @@ public class ServerCookie implements Ser
     // Expires - Not stored explicitly. Generated from Max-Age (see V1)
     private final MessageBytes path=MessageBytes.newInstance();
     private final MessageBytes domain=MessageBytes.newInstance();
-    private boolean secure;
 
     // Version 1 (RFC2109) attributes
     private final MessageBytes comment=MessageBytes.newInstance();
-    private int maxAge = -1;
     private int version = 0;
 
     // Other fields
@@ -90,11 +88,9 @@ public class ServerCookie implements Ser
         name.recycle();
         value.recycle();
         comment.recycle();
-        maxAge=-1;
         path.recycle();
         domain.recycle();
         version=0;
-        secure=false;
     }
 
     public MessageBytes getComment() {
@@ -105,26 +101,10 @@ public class ServerCookie implements Ser
         return domain;
     }
 
-    public void setMaxAge(int expiry) {
-        maxAge = expiry;
-    }
-
-    public int getMaxAge() {
-        return maxAge;
-    }
-
     public MessageBytes getPath() {
         return path;
     }
 
-    public void setSecure(boolean flag) {
-        secure = flag;
-    }
-
-    public boolean getSecure() {
-        return secure;
-    }
-
     public MessageBytes getName() {
         return name;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org