tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r951101 - /tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
Date Thu, 03 Jun 2010 18:28:58 GMT
Author: markt
Date: Thu Jun  3 18:28:58 2010
New Revision: 951101

URL: http://svn.apache.org/viewvc?rev=951101&view=rev
Log:
Remove code duplication by used abstract base class

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=951101&r1=951100&r2=951101&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Thu Jun  3 18:28:58
2010
@@ -21,16 +21,12 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.Locale;
-import java.util.StringTokenizer;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.ActionHook;
-import org.apache.coyote.Adapter;
 import org.apache.coyote.Request;
 import org.apache.coyote.RequestInfo;
 import org.apache.coyote.Response;
@@ -50,7 +46,6 @@ import org.apache.tomcat.jni.SSL;
 import org.apache.tomcat.jni.SSLSocket;
 import org.apache.tomcat.jni.Sockaddr;
 import org.apache.tomcat.jni.Socket;
-import org.apache.tomcat.util.buf.Ascii;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.HexUtils;
 import org.apache.tomcat.util.buf.MessageBytes;
@@ -60,7 +55,6 @@ import org.apache.tomcat.util.net.Abstra
 import org.apache.tomcat.util.net.AprEndpoint;
 import org.apache.tomcat.util.net.SocketStatus;
 import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState;
-import org.apache.tomcat.util.res.StringManager;
 
 
 /**
@@ -68,7 +62,7 @@ import org.apache.tomcat.util.res.String
  *
  * @author Remy Maucherat
  */
-public class Http11AprProcessor implements ActionHook {
+public class Http11AprProcessor extends AbstractHttp11Processor implements ActionHook {
 
 
     /**
@@ -76,13 +70,6 @@ public class Http11AprProcessor implemen
      */
     private static final Log log = LogFactory.getLog(Http11AprProcessor.class);
 
-    /**
-     * The string manager for this package.
-     */
-    protected static final StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
     // ----------------------------------------------------------- Constructors
 
 
@@ -113,24 +100,6 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Associated adapter.
-     */
-    protected Adapter adapter = null;
-
-
-    /**
-     * Request object.
-     */
-    protected Request request = null;
-
-
-    /**
-     * Response object.
-     */
-    protected Response response = null;
-
-
-    /**
      * Input.
      */
     protected InternalAprInputBuffer inputBuffer = null;
@@ -143,30 +112,6 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Error flag.
-     */
-    protected boolean error = false;
-
-
-    /**
-     * Keep-alive.
-     */
-    protected boolean keepAlive = true;
-
-
-    /**
-     * HTTP/1.1 flag.
-     */
-    protected boolean http11 = true;
-
-
-    /**
-     * HTTP/0.9 flag.
-     */
-    protected boolean http09 = false;
-
-
-    /**
      * Sendfile data.
      */
     protected AprEndpoint.SendfileData sendfileData = null;
@@ -185,31 +130,6 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Content delimiter for the request (if false, the connection will
-     * be closed at the end of the request).
-     */
-    protected boolean contentDelimitation = true;
-
-
-    /**
-     * Is there an expectation ?
-     */
-    protected boolean expectation = false;
-
-
-    /**
-     * List of restricted user agents.
-     */
-    protected Pattern[] restrictedUserAgents = null;
-
-
-    /**
-     * Maximum number of Keep-Alive requests to honor.
-     */
-    protected int maxKeepAliveRequests = -1;
-
-
-    /**
      * SSL enabled ?
      */
     protected boolean ssl = false;
@@ -222,251 +142,11 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Remote Address associated with the current connection.
-     */
-    protected String remoteAddr = null;
-
-
-    /**
-     * Remote Host associated with the current connection.
-     */
-    protected String remoteHost = null;
-
-
-    /**
-     * Local Host associated with the current connection.
-     */
-    protected String localName = null;
-
-
-
-    /**
-     * Local port to which the socket is connected
-     */
-    protected int localPort = -1;
-
-
-    /**
-     * Remote port to which the socket is connected
-     */
-    protected int remotePort = -1;
-
-
-    /**
-     * The local Host address.
-     */
-    protected String localAddr = null;
-
-
-    /**
-     * Maximum timeout on uploads. 5 minutes as in Apache HTTPD server.
-     */
-    protected int timeout = 300000;
-
-
-    /**
-     * Flag to disable setting a different time-out on uploads.
-     */
-    protected boolean disableUploadTimeout = false;
-
-
-    /**
-     * Allowed compression level.
-     */
-    protected int compressionLevel = 0;
-
-
-    /**
-     * Minimum content size to make compression.
-     */
-    protected int compressionMinSize = 2048;
-
-
-    /**
-     * Socket buffering.
-     */
-    protected int socketBuffer = -1;
-
-
-    /**
-     * Max save post size.
-     */
-    protected int maxSavePostSize = 4 * 1024;
-
-
-    /**
-     * List of user agents to not use gzip with
-     */
-    protected Pattern noCompressionUserAgents[] = null;
-
-    /**
-     * List of MIMES which could be gzipped
-     */
-    protected String[] compressableMimeTypes =
-    { "text/html", "text/xml", "text/plain" };
-
-
-    /**
-     * Host name (used to avoid useless B2C conversion on the host name).
-     */
-    protected char[] hostNameC = new char[0];
-
-
-    /**
      * Associated endpoint.
      */
     protected AprEndpoint endpoint;
 
 
-    /**
-     * Allow a customized the server header for the tin-foil hat folks.
-     */
-    protected String server = null;
-
-    
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * Return compression level.
-     */
-    public String getCompression() {
-        switch (compressionLevel) {
-        case 0:
-            return "off";
-        case 1:
-            return "on";
-        case 2:
-            return "force";
-        }
-        return "off";
-    }
-
-
-    /**
-     * Set compression level.
-     */
-    public void setCompression(String compression) {
-        if (compression.equals("on")) {
-            this.compressionLevel = 1;
-        } else if (compression.equals("force")) {
-            this.compressionLevel = 2;
-        } else if (compression.equals("off")) {
-            this.compressionLevel = 0;
-        } else {
-            try {
-                // Try to parse compression as an int, which would give the
-                // minimum compression size
-                compressionMinSize = Integer.parseInt(compression);
-                this.compressionLevel = 1;
-            } catch (Exception e) {
-                this.compressionLevel = 0;
-            }
-        }
-    }
-
-    /**
-     * Set Minimum size to trigger compression.
-     */
-    public void setCompressionMinSize(int compressionMinSize) {
-        this.compressionMinSize = compressionMinSize;
-    }
-
-
-    /**
-     * Add user-agent for which gzip compression didn't works
-     * The user agent String given will be exactly matched
-     * to the user-agent header submitted by the client.
-     *
-     * @param userAgent user-agent string
-     */
-    public void addNoCompressionUserAgent(String userAgent) {
-        try {
-            Pattern nRule = Pattern.compile(userAgent);
-            noCompressionUserAgents =
-                addREArray(noCompressionUserAgents, nRule);
-        } catch (PatternSyntaxException pse) {
-            log.error(sm.getString("http11processor.regexp.error", userAgent), pse);
-        }
-    }
-
-
-    /**
-     * Set no compression user agent list (this method is best when used with
-     * a large number of connectors, where it would be better to have all of
-     * them referenced a single array).
-     */
-    public void setNoCompressionUserAgents(Pattern[] noCompressionUserAgents) {
-        this.noCompressionUserAgents = noCompressionUserAgents;
-    }
-
-
-    /**
-     * Set no compression user agent list.
-     * List contains users agents separated by ',' :
-     *
-     * ie: "gorilla,desesplorer,tigrus"
-     */
-    public void setNoCompressionUserAgents(String noCompressionUserAgents) {
-        if (noCompressionUserAgents != null) {
-            StringTokenizer st = new StringTokenizer(noCompressionUserAgents, ",");
-
-            while (st.hasMoreTokens()) {
-                addNoCompressionUserAgent(st.nextToken().trim());
-            }
-        }
-    }
-
-    /**
-     * Add a mime-type which will be compressible
-     * The mime-type String will be exactly matched
-     * in the response mime-type header .
-     *
-     * @param mimeType mime-type string
-     */
-    public void addCompressableMimeType(String mimeType) {
-        compressableMimeTypes =
-            addStringArray(compressableMimeTypes, mimeType);
-    }
-
-
-    /**
-     * Set compressible mime-type list (this method is best when used with
-     * a large number of connectors, where it would be better to have all of
-     * them referenced a single array).
-     */
-    public void setCompressableMimeTypes(String[] compressableMimeTypes) {
-        this.compressableMimeTypes = compressableMimeTypes;
-    }
-
-
-    /**
-     * Set compressible mime-type list
-     * List contains users agents separated by ',' :
-     *
-     * ie: "text/html,text/xml,text/plain"
-     */
-    public void setCompressableMimeTypes(String compressableMimeTypes) {
-        if (compressableMimeTypes != null) {
-            this.compressableMimeTypes = null;
-            StringTokenizer st = new StringTokenizer(compressableMimeTypes, ",");
-
-            while (st.hasMoreTokens()) {
-                addCompressableMimeType(st.nextToken().trim());
-            }
-        }
-    }
-
-
-    /**
-     * Return the list of restricted user agents.
-     */
-    public String[] findCompressableMimeTypes() {
-        return (compressableMimeTypes);
-    }
-
-
-
     // --------------------------------------------------------- Public Methods
 
 
@@ -493,228 +173,6 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * General use method
-     *
-     * @param sArray the StringArray
-     * @param value string
-     */
-    private String[] addStringArray(String sArray[], String value) {
-        String[] result = null;
-        if (sArray == null) {
-            result = new String[1];
-            result[0] = value;
-        }
-        else {
-            result = new String[sArray.length + 1];
-            for (int i = 0; i < sArray.length; i++)
-                result[i] = sArray[i];
-            result[sArray.length] = value;
-        }
-        return result;
-    }
-
-
-    /**
-     * General use method
-     *
-     * @param rArray the REArray
-     * @param value Obj
-     */
-    private Pattern[] addREArray(Pattern rArray[], Pattern value) {
-        Pattern[] result = null;
-        if (rArray == null) {
-            result = new Pattern[1];
-            result[0] = value;
-        }
-        else {
-            result = new Pattern[rArray.length + 1];
-            for (int i = 0; i < rArray.length; i++)
-                result[i] = rArray[i];
-            result[rArray.length] = value;
-        }
-        return result;
-    }
-
-
-    /**
-     * Checks if any entry in the string array starts with the specified value
-     *
-     * @param sArray the StringArray
-     * @param value string
-     */
-    private boolean startsWithStringArray(String sArray[], String value) {
-        if (value == null)
-           return false;
-        for (int i = 0; i < sArray.length; i++) {
-            if (value.startsWith(sArray[i])) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-
-    /**
-     * Add restricted user-agent (which will downgrade the connector
-     * to HTTP/1.0 mode). The user agent String given will be matched
-     * via regexp to the user-agent header submitted by the client.
-     *
-     * @param userAgent user-agent string
-     */
-    public void addRestrictedUserAgent(String userAgent) {
-        try {
-            Pattern nRule = Pattern.compile(userAgent);
-            restrictedUserAgents = addREArray(restrictedUserAgents, nRule);
-        } catch (PatternSyntaxException pse) {
-            log.error(sm.getString("http11processor.regexp.error", userAgent), pse);
-        }
-    }
-
-
-    /**
-     * Set restricted user agent list (this method is best when used with
-     * a large number of connectors, where it would be better to have all of
-     * them referenced a single array).
-     */
-    public void setRestrictedUserAgents(Pattern[] restrictedUserAgents) {
-        this.restrictedUserAgents = restrictedUserAgents;
-    }
-
-
-    /**
-     * Set restricted user agent list (which will downgrade the connector
-     * to HTTP/1.0 mode). List contains users agents separated by ',' :
-     *
-     * ie: "gorilla,desesplorer,tigrus"
-     */
-    public void setRestrictedUserAgents(String restrictedUserAgents) {
-        if (restrictedUserAgents != null) {
-            StringTokenizer st =
-                new StringTokenizer(restrictedUserAgents, ",");
-            while (st.hasMoreTokens()) {
-                addRestrictedUserAgent(st.nextToken().trim());
-            }
-        }
-    }
-
-
-    /**
-     * Return the list of restricted user agents.
-     */
-    public String[] findRestrictedUserAgents() {
-        String[] sarr = new String [restrictedUserAgents.length];
-
-        for (int i = 0; i < restrictedUserAgents.length; i++)
-            sarr[i] = restrictedUserAgents[i].toString();
-
-        return (sarr);
-    }
-
-
-    /**
-     * Set the maximum number of Keep-Alive requests to honor.
-     * This is to safeguard from DoS attacks.  Setting to a negative
-     * value disables the check.
-     */
-    public void setMaxKeepAliveRequests(int mkar) {
-        maxKeepAliveRequests = mkar;
-    }
-
-
-    /**
-     * Return the number of Keep-Alive requests that we will honor.
-     */
-    public int getMaxKeepAliveRequests() {
-        return maxKeepAliveRequests;
-    }
-
-
-    /**
-     * Set the maximum size of a POST which will be buffered in SSL mode.
-     */
-    public void setMaxSavePostSize(int msps) {
-        maxSavePostSize = msps;
-    }
-
-
-    /**
-     * Return the maximum size of a POST which will be buffered in SSL mode.
-     */
-    public int getMaxSavePostSize() {
-        return maxSavePostSize;
-    }
-
-
-    /**
-     * Set the flag to control upload time-outs.
-     */
-    public void setDisableUploadTimeout(boolean isDisabled) {
-        disableUploadTimeout = isDisabled;
-    }
-
-    /**
-     * Get the flag that controls upload time-outs.
-     */
-    public boolean getDisableUploadTimeout() {
-        return disableUploadTimeout;
-    }
-
-    /**
-     * Set the socket buffer flag.
-     */
-    public void setSocketBuffer(int socketBuffer) {
-        this.socketBuffer = socketBuffer;
-    }
-
-    /**
-     * Get the socket buffer flag.
-     */
-    public int getSocketBuffer() {
-        return socketBuffer;
-    }
-
-    /**
-     * Set the upload timeout.
-     */
-    public void setTimeout( int timeouts ) {
-        timeout = timeouts ;
-    }
-
-    /**
-     * Get the upload timeout.
-     */
-    public int getTimeout() {
-        return timeout;
-    }
-
-    /**
-     * Set the server header name.
-     */
-    public void setServer( String server ) {
-        if (server==null || server.equals("")) {
-            this.server = null;
-        } else {
-            this.server = server;
-        }
-    }
-
-    /**
-     * Get the server header name.
-     */
-    public String getServer() {
-        return server;
-    }
-
-
-    /** Get the request associated with this processor.
-     *
-     * @return The request
-     */
-    public Request getRequest() {
-        return request;
-    }
-
-    /**
      * Process pipelined HTTP requests using the specified input and output
      * streams.
      *
@@ -1299,29 +757,6 @@ public class Http11AprProcessor implemen
     }
 
 
-    // ------------------------------------------------------ Connector Methods
-
-
-    /**
-     * Set the associated adapter.
-     *
-     * @param adapter the new adapter
-     */
-    public void setAdapter(Adapter adapter) {
-        this.adapter = adapter;
-    }
-
-
-    /**
-     * Get the associated adapter.
-     *
-     * @return the associated adapter
-     */
-    public Adapter getAdapter() {
-        return adapter;
-    }
-
-
     // ------------------------------------------------------ Protected Methods
 
 
@@ -1583,67 +1018,6 @@ public class Http11AprProcessor implemen
 
 
     /**
-     * Check for compression
-     */
-    private boolean isCompressable() {
-
-        // Nope Compression could works in HTTP 1.0 also
-        // cf: mod_deflate
-
-        // Compression only since HTTP 1.1
-        // if (! http11)
-        //    return false;
-
-        // Check if browser support gzip encoding
-        MessageBytes acceptEncodingMB =
-            request.getMimeHeaders().getValue("accept-encoding");
-
-        if ((acceptEncodingMB == null)
-            || (acceptEncodingMB.indexOf("gzip") == -1))
-            return false;
-
-        // Check if content is not already gzipped
-        MessageBytes contentEncodingMB =
-            response.getMimeHeaders().getValue("Content-Encoding");
-
-        if ((contentEncodingMB != null)
-            && (contentEncodingMB.indexOf("gzip") != -1))
-            return false;
-
-        // If force mode, always compress (test purposes only)
-        if (compressionLevel == 2)
-           return true;
-
-        // Check for incompatible Browser
-        if (noCompressionUserAgents != null) {
-            MessageBytes userAgentValueMB =
-                request.getMimeHeaders().getValue("user-agent");
-            if(userAgentValueMB != null) {
-                String userAgentValue = userAgentValueMB.toString();
-
-                // If one Regexp rule match, disable compression
-                for (int i = 0; i < noCompressionUserAgents.length; i++)
-                    if (noCompressionUserAgents[i].matcher(userAgentValue).matches())
-                        return false;
-            }
-        }
-
-        // Check if sufficient length to trigger the compression
-        long contentLength = response.getContentLengthLong();
-        if ((contentLength == -1)
-            || (contentLength > compressionMinSize)) {
-            // Check for compatible MIME-TYPE
-            if (compressableMimeTypes != null) {
-                return (startsWithStringArray(compressableMimeTypes,
-                                              response.getContentType()));
-            }
-        }
-
-        return false;
-    }
-
-
-    /**
      * When committing the response, we have to validate the set of headers, as
      * well as setup the response filters.
      */
@@ -1851,48 +1225,4 @@ public class Http11AprProcessor implemen
         return true;
     }
 
-
-    /**
-     * Specialized utility method: find a sequence of lower case bytes inside
-     * a ByteChunk.
-     */
-    protected int findBytes(ByteChunk bc, byte[] b) {
-
-        byte first = b[0];
-        byte[] buff = bc.getBuffer();
-        int start = bc.getStart();
-        int end = bc.getEnd();
-
-    // Look for first char
-    int srcEnd = b.length;
-
-    for (int i = start; i <= (end - srcEnd); i++) {
-        if (Ascii.toLower(buff[i]) != first) continue;
-        // found first char, now look for a match
-            int myPos = i+1;
-        for (int srcPos = 1; srcPos < srcEnd; ) {
-                if (Ascii.toLower(buff[myPos++]) != b[srcPos++])
-            break;
-                if (srcPos == srcEnd) return i - start; // found it
-        }
-    }
-    return -1;
-
-    }
-
-    /**
-     * Determine if we must drop the connection because of the HTTP status
-     * code.  Use the same list of codes as Apache/httpd.
-     */
-    protected boolean statusDropsConnection(int status) {
-        return status == 400 /* SC_BAD_REQUEST */ ||
-               status == 408 /* SC_REQUEST_TIMEOUT */ ||
-               status == 411 /* SC_LENGTH_REQUIRED */ ||
-               status == 413 /* SC_REQUEST_ENTITY_TOO_LARGE */ ||
-               status == 414 /* SC_REQUEST_URI_TOO_LONG */ ||
-               status == 500 /* SC_INTERNAL_SERVER_ERROR */ ||
-               status == 503 /* SC_SERVICE_UNAVAILABLE */ ||
-               status == 501 /* SC_NOT_IMPLEMENTED */;
-    }
-
 }



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


Mime
View raw message