tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1042814 - in /tomcat/trunk/java/org/apache/coyote: AbstractProtocolHandler.java ajp/AbstractAjpProtocol.java http11/AbstractHttp11JsseProtocol.java http11/AbstractHttp11Protocol.java
Date Mon, 06 Dec 2010 22:06:52 GMT
Author: markt
Date: Mon Dec  6 22:06:52 2010
New Revision: 1042814

URL: http://svn.apache.org/viewvc?rev=1042814&view=rev
Log:
Re-factoring in support of https://issues.apache.org/bugzilla/show_bug.cgi?id=50360
Pull up JMX related methods
Tidy up the remaining protocol specific methods

Modified:
    tomcat/trunk/java/org/apache/coyote/AbstractProtocolHandler.java
    tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11JsseProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocolHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocolHandler.java?rev=1042814&r1=1042813&r2=1042814&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProtocolHandler.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProtocolHandler.java Mon Dec  6 22:06:52 2010
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.concurrent.Executor;
 
 import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.juli.logging.Log;
@@ -252,10 +253,76 @@ public abstract class AbstractProtocolHa
     }
 
 
+    // ---------------------------------------------------------- Public methods
+
+    /**
+     * The name will be prefix-address-port if address is non-null and
+     * prefix-port if the address is null. The name will be appropriately quoted
+     * so it can be used directly in an ObjectName.
+     */
+    public String getName() {
+        StringBuilder name = new StringBuilder(getNamePrefix());
+        name.append('-');
+        if (getAddress() != null) {
+            name.append(getAddress());
+            name.append('-');
+        }
+        name.append(endpoint.getPort());
+        return ObjectName.quote(name.toString());
+    }
+
+    
     // -------------------------------------------------------- Abstract methods
+    
     /**
      * Concrete implementations need to provide access to their logger to be
      * used by the abstract classes.
      */
     protected abstract Log getLog();
+    
+    
+    /**
+     * Obtain the prefix to be used when construction a name for this protocol
+     * handler. The name will be prefix-address-port.
+     */
+    protected abstract String getNamePrefix();
+
+
+    // ----------------------------------------------------- JMX related methods
+
+    protected String domain;
+    protected ObjectName oname;
+    protected MBeanServer mserver;
+
+    public ObjectName getObjectName() {
+        return oname;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    @Override
+    public ObjectName preRegister(MBeanServer server, ObjectName name)
+            throws Exception {
+        oname = name;
+        mserver = server;
+        domain = name.getDomain();
+        return name;
+    }
+
+    @Override
+    public void postRegister(Boolean registrationDone) {
+        // NOOP
+    }
+
+    @Override
+    public void preDeregister() throws Exception {
+        // NOOP
+    }
+
+    @Override
+    public void postDeregister() {
+        // NOOP
+    }
 }

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProtocol.java?rev=1042814&r1=1042813&r2=1042814&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProtocol.java Mon Dec  6 22:06:52 2010
@@ -16,21 +16,66 @@
  */
 package org.apache.coyote.ajp;
 
-import java.net.URLEncoder;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
 import org.apache.coyote.AbstractProtocolHandler;
 import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.res.StringManager;
 
 public abstract class AbstractAjpProtocol extends AbstractProtocolHandler {
+    
     /**
      * The string manager for this package.
      */
-    protected static final StringManager sm = StringManager.getManager(Constants.Package);
-        
+    protected static final StringManager sm =
+        StringManager.getManager(Constants.Package);
+
+
+    // ------------------------------------------------- AJP specific properties
+    // ------------------------------------------ managed in the ProtocolHandler
+    
+    /**
+     * Should authentication be done in the native webserver layer, 
+     * or in the Servlet container ?
+     */
+    protected boolean tomcatAuthentication = true;
+    public boolean getTomcatAuthentication() { return tomcatAuthentication; }
+    public void setTomcatAuthentication(boolean tomcatAuthentication) {
+        this.tomcatAuthentication = tomcatAuthentication;
+    }
+
+
+    /**
+     * Required secret.
+     */
+    protected String requiredSecret = null;
+    public void setRequiredSecret(String requiredSecret) {
+        this.requiredSecret = requiredSecret;
+    }
+
+
+    /**
+     * AJP packet size.
+     */
+    protected int packetSize = Constants.MAX_PACKET_SIZE;
+    public int getPacketSize() { return packetSize; }
+    public void setPacketSize(int packetSize) {
+        if(packetSize < Constants.MAX_PACKET_SIZE) {
+            this.packetSize = Constants.MAX_PACKET_SIZE;
+        } else {
+            this.packetSize = packetSize;
+        }
+    }
+
+
+    // ----------------------------------------------------- JMX related methods
+
+    @Override
+    protected String getNamePrefix() {
+        return ("ajp");
+    }
+    
+    
+    // ------------------------------------------------------- Lifecycle methods
+
     @Override
     public void pause() throws Exception {
         try {
@@ -43,18 +88,21 @@ public abstract class AbstractAjpProtoco
             getLog().info(sm.getString("ajpprotocol.pause", getName()));
     }
 
+
     @Override
     public void resume() throws Exception {
         try {
             endpoint.resume();
         } catch (Exception ex) {
-            getLog().error(sm.getString("ajpprotocol.endpoint.resumeerror"), ex);
+            getLog().error(sm.getString("ajpprotocol.endpoint.resumeerror"),
+                    ex);
             throw ex;
         }
         if (getLog().isInfoEnabled())
             getLog().info(sm.getString("ajpprotocol.resume", getName()));
     }
 
+
     @Override
     public void stop() throws Exception {
         try {
@@ -67,6 +115,7 @@ public abstract class AbstractAjpProtoco
             getLog().info(sm.getString("ajpprotocol.stop", getName()));
     }
 
+
     @Override
     public void destroy() throws Exception {
         if (getLog().isInfoEnabled())
@@ -77,81 +126,4 @@ public abstract class AbstractAjpProtoco
         if (rgOname != null)
             Registry.getRegistry(null, null).unregisterComponent(rgOname);
     }
-
-    public String getName() {
-        String encodedAddr = "";
-        if (getAddress() != null) {
-            encodedAddr = "" + getAddress();
-            if (encodedAddr.startsWith("/"))
-                encodedAddr = encodedAddr.substring(1);
-            encodedAddr = URLEncoder.encode(encodedAddr) + "-";
-        }
-        return ("ajp-" + encodedAddr + endpoint.getPort());
-    }
-
-    /**
-     * Should authentication be done in the native webserver layer, 
-     * or in the Servlet container ?
-     */
-    protected boolean tomcatAuthentication = true;
-    public boolean getTomcatAuthentication() { return tomcatAuthentication; }
-    public void setTomcatAuthentication(boolean tomcatAuthentication) { this.tomcatAuthentication
= tomcatAuthentication; }
-
-    /**
-     * Required secret.
-     */
-    protected String requiredSecret = null;
-    public void setRequiredSecret(String requiredSecret) { this.requiredSecret = requiredSecret;
}
-    
-    /**
-     * AJP packet size.
-     */
-    protected int packetSize = Constants.MAX_PACKET_SIZE;
-    public int getPacketSize() { return packetSize; }
-    public void setPacketSize(int packetSize) {
-        if(packetSize < Constants.MAX_PACKET_SIZE) {
-            this.packetSize = Constants.MAX_PACKET_SIZE;
-        } else {
-            this.packetSize = packetSize;
-        }
-    }
-
-    
-    // -------------------- JMX related methods --------------------
-
-    protected String domain;
-    protected ObjectName oname;
-    protected MBeanServer mserver;
-
-    public ObjectName getObjectName() {
-        return oname;
-    }
-
-    public String getDomain() {
-        return domain;
-    }
-
-    @Override
-    public ObjectName preRegister(MBeanServer server,
-                                  ObjectName name) throws Exception {
-        oname=name;
-        mserver=server;
-        domain=name.getDomain();
-        return name;
-    }
-
-    @Override
-    public void postRegister(Boolean registrationDone) {
-        // NOOP
-    }
-
-    @Override
-    public void preDeregister() throws Exception {
-        // NOOP
-    }
-
-    @Override
-    public void postDeregister() {
-        // NOOP
-    }
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11JsseProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11JsseProtocol.java?rev=1042814&r1=1042813&r2=1042814&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11JsseProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11JsseProtocol.java Mon Dec  6
22:06:52 2010
@@ -16,9 +16,13 @@
  */
 package org.apache.coyote.http11;
 
+import org.apache.tomcat.util.net.SSLImplementation;
+
 public abstract class AbstractHttp11JsseProtocol
         extends AbstractHttp11Protocol {
 
+    protected SSLImplementation sslImplementation = null;
+
     public String getAlgorithm() { return endpoint.getAlgorithm();}
     public void setAlgorithm(String s ) { endpoint.setAlgorithm(s);}
     

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java?rev=1042814&r1=1042813&r2=1042814&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Protocol.java Mon Dec  6 22:06:52
2010
@@ -16,130 +16,29 @@
  */
 package org.apache.coyote.http11;
 
-import java.net.URLEncoder;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
 import org.apache.coyote.AbstractProtocolHandler;
 import org.apache.tomcat.util.modeler.Registry;
-import org.apache.tomcat.util.net.SSLImplementation;
 import org.apache.tomcat.util.res.StringManager;
 
 public abstract class AbstractHttp11Protocol extends AbstractProtocolHandler {
+
     /**
      * The string manager for this package.
      */
-    protected static final StringManager sm = StringManager.getManager(Constants.Package);
+    protected static final StringManager sm =
+        StringManager.getManager(Constants.Package);
 
-    protected SSLImplementation sslImplementation = null;
-    
-    
-    public String getName() {
-        String encodedAddr = "";
-        if (getAddress() != null) {
-            encodedAddr = "" + getAddress();
-            if (encodedAddr.startsWith("/"))
-                encodedAddr = encodedAddr.substring(1);
-            encodedAddr = URLEncoder.encode(encodedAddr) + "-";
-        }
-        return ("http-" + encodedAddr + endpoint.getPort());
-    }
-    
-    
-    @Override
-    public void pause() throws Exception {
-        try {
-            endpoint.pause();
-        } catch (Exception ex) {
-            getLog().error(sm.getString("http11protocol.endpoint.pauseerror"), ex);
-            throw ex;
-        }
-        if(getLog().isInfoEnabled())
-            getLog().info(sm.getString("http11protocol.pause", getName()));
-    }
 
-    @Override
-    public void resume() throws Exception {
-        try {
-            endpoint.resume();
-        } catch (Exception ex) {
-            getLog().error(sm.getString("http11protocol.endpoint.resumeerror"), ex);
-            throw ex;
-        }
-        if(getLog().isInfoEnabled())
-            getLog().info(sm.getString("http11protocol.resume", getName()));
-    }
-
-    @Override
-    public void stop() throws Exception {
-        try {
-            endpoint.stop();
-        } catch (Exception ex) {
-            getLog().error(sm.getString("http11protocol.endpoint.stoperror"), ex);
-            throw ex;
-        }
-        if(getLog().isInfoEnabled())
-            getLog().info(sm.getString("http11protocol.stop", getName()));
-    }
-
-    @Override
-    public void destroy() throws Exception {
-        if(getLog().isInfoEnabled())
-            getLog().info(sm.getString("http11protocol.destroy", getName()));
-        endpoint.destroy();
-        if( tpOname!=null )
-            Registry.getRegistry(null, null).unregisterComponent(tpOname);
-        if( rgOname != null )
-            Registry.getRegistry(null, null).unregisterComponent(rgOname);
-    }
-    
-    public boolean isSSLEnabled() { return endpoint.isSSLEnabled();}
-    public void setSSLEnabled(boolean SSLEnabled) { endpoint.setSSLEnabled(SSLEnabled);}
   
-    
-    /**
-     * This field indicates if the protocol is secure from the perspective of
-     * the client (= https is used).
-     */
-    private boolean secure;
-    public boolean getSecure() { return secure; }
-    public void setSecure(boolean b) { 
-        secure = b;         
-        setAttribute("secure", "" + b);
-    }
-    
+    // ------------------------------------------------ HTTP specific properties
+    // ------------------------------------------ managed in the ProtocolHandler
 
     private int socketBuffer = 9000;
     public int getSocketBuffer() { return socketBuffer; }
-    public void setSocketBuffer(int socketBuffer) { this.socketBuffer = socketBuffer; }
-
-    // HTTP
-    /**
-     * Maximum number of requests which can be performed over a keepalive 
-     * connection. The default is the same as for Apache HTTP Server.
-     */
-    public int getMaxKeepAliveRequests() { return endpoint.getMaxKeepAliveRequests(); }
-    public void setMaxKeepAliveRequests(int mkar) {
-        endpoint.setMaxKeepAliveRequests(mkar);
-        setAttribute("maxKeepAliveRequests", "" + mkar);
-    }
-    
-    /**
-     * Return the Keep-Alive policy for the connection.
-     */
-    public boolean getKeepAlive() {
-        return ((endpoint.getMaxKeepAliveRequests() != 0) && (endpoint.getMaxKeepAliveRequests()
!= 1));
-    }
-
-    /**
-     * Set the keep-alive policy for this connection.
-     */
-    public void setKeepAlive(boolean keepAlive) {
-        if (!keepAlive) {
-            setMaxKeepAliveRequests(1);
-        }
+    public void setSocketBuffer(int socketBuffer) {
+        this.socketBuffer = socketBuffer;
     }
 
+    
     /**
      * Maximum size of the post which will be saved when processing certain
      * requests, such as a POST.
@@ -149,7 +48,6 @@ public abstract class AbstractHttp11Prot
     public void setMaxSavePostSize(int valueI) { maxSavePostSize = valueI; }
     
 
-    // HTTP
     /**
      * Maximum size of the HTTP message header.
      */
@@ -169,7 +67,6 @@ public abstract class AbstractHttp11Prot
     }
 
 
-    // HTTP
     /**
      * If true, the connectionUploadTimeout will be ignored and the regular
      * socket timeout will be used for the full duration of the connection.
@@ -179,51 +76,66 @@ public abstract class AbstractHttp11Prot
     public void setDisableUploadTimeout(boolean isDisabled) {
         disableUploadTimeout = isDisabled;
     }
-    
-    
-    // HTTP
+
+
     /**
      * Integrated compression support.
      */
     private String compression = "off";
     public String getCompression() { return compression; }
     public void setCompression(String valueS) { compression = valueS; }
-        
 
-    // HTTP
+
     private String noCompressionUserAgents = null;
-    public String getNoCompressionUserAgents() { return noCompressionUserAgents; }
-    public void setNoCompressionUserAgents(String valueS) { noCompressionUserAgents = valueS;
}
-    
-    // HTTP
+    public String getNoCompressionUserAgents() {
+        return noCompressionUserAgents;
+    }
+    public void setNoCompressionUserAgents(String valueS) {
+        noCompressionUserAgents = valueS;
+    }
+
+
     private String compressableMimeTypes = "text/html,text/xml,text/plain";
     public String getCompressableMimeType() { return compressableMimeTypes; }
-    public void setCompressableMimeType(String valueS) { compressableMimeTypes = valueS;
}
-    public String getCompressableMimeTypes() { return getCompressableMimeType(); }
-    public void setCompressableMimeTypes(String valueS) { setCompressableMimeType(valueS);
}
-    
-    // HTTP
+    public void setCompressableMimeType(String valueS) {
+        compressableMimeTypes = valueS;
+    }
+    public String getCompressableMimeTypes() {
+        return getCompressableMimeType();
+    }
+    public void setCompressableMimeTypes(String valueS) {
+        setCompressableMimeType(valueS);
+    }
+
+
     private int compressionMinSize = 2048;
     public int getCompressionMinSize() { return compressionMinSize; }
-    public void setCompressionMinSize(int valueI) { compressionMinSize = valueI; }
- 
-    // HTTP
+    public void setCompressionMinSize(int valueI) {
+        compressionMinSize = valueI;
+    }
+
+
     /**
-     * User agents regular expressions which should be restricted to HTTP/1.0 support.
+     * User agents regular expressions which should be restricted to HTTP/1.0
+     * support.
      */
     private String restrictedUserAgents = null;
     public String getRestrictedUserAgents() { return restrictedUserAgents; }
-    public void setRestrictedUserAgents(String valueS) { restrictedUserAgents = valueS; }
+    public void setRestrictedUserAgents(String valueS) {
+        restrictedUserAgents = valueS;
+    }
+
 
-    // HTTP
     /**
      * Server header.
      */
     private String server;
-    public void setServer( String server ) { this.server = server; }
     public String getServer() { return server; }
-    
-    // HTTP
+    public void setServer( String server ) {
+        this.server = server;
+    }
+
+
     /**
      * Maximum size of trailing headers in bytes
      */
@@ -233,44 +145,107 @@ public abstract class AbstractHttp11Prot
         this.maxTrailerSize = maxTrailerSize;
     }
 
-    @Override
-    public abstract void init() throws Exception;
+
+    // ------------------------------------------------ HTTP specific properties
+    // ------------------------------------------ passed through to the EndPoint
     
-    // -------------------- JMX related methods --------------------
+    public boolean isSSLEnabled() { return endpoint.isSSLEnabled();}
+    public void setSSLEnabled(boolean SSLEnabled) {
+        endpoint.setSSLEnabled(SSLEnabled);
+    }    
+
 
-    protected String domain;
-    protected ObjectName oname;
-    protected MBeanServer mserver;
+    // ------------------------------------------------ HTTP specific properties
+    // --------- passed through to the EndPoint and made available as attributes
 
-    public ObjectName getObjectName() {
-        return oname;
+    /**
+     * This field indicates if the protocol is treated as if it is secure. This
+     * normally means https is being used but can be used to fake https e.g
+     * behind a reverse proxy.
+     */
+    private boolean secure;
+    public boolean getSecure() { return secure; }
+    public void setSecure(boolean b) { 
+        secure = b;         
+        setAttribute("secure", "" + b);
     }
+    
 
-    public String getDomain() {
-        return domain;
+    /**
+     * Maximum number of requests which can be performed over a keepalive 
+     * connection. The default is the same as for Apache HTTP Server.
+     */
+    public int getMaxKeepAliveRequests() { 
+        return endpoint.getMaxKeepAliveRequests();
+    }
+    public void setMaxKeepAliveRequests(int mkar) {
+        endpoint.setMaxKeepAliveRequests(mkar);
+        setAttribute("maxKeepAliveRequests", "" + mkar);
     }
 
+    
+    // ----------------------------------------------------- JMX related methods
+
     @Override
-    public ObjectName preRegister(MBeanServer server,
-                                  ObjectName name) throws Exception {
-        oname=name;
-        mserver=server;
-        domain=name.getDomain();
-        return name;
+    protected String getNamePrefix() {
+        return ("http");
     }
+    
+    
+    // ------------------------------------------------------- Lifecycle methods
+    
+    @Override
+    public abstract void init() throws Exception;
 
     @Override
-    public void postRegister(Boolean registrationDone) {
-        // NOOP
+    public void pause() throws Exception {
+        try {
+            endpoint.pause();
+        } catch (Exception ex) {
+            getLog().error(sm.getString("http11protocol.endpoint.pauseerror"),
+                    ex);
+            throw ex;
+        }
+        if(getLog().isInfoEnabled())
+            getLog().info(sm.getString("http11protocol.pause", getName()));
+    }
+
+    @Override
+    public void resume() throws Exception {
+        try {
+            endpoint.resume();
+        } catch (Exception ex) {
+            getLog().error(sm.getString("http11protocol.endpoint.resumeerror"),
+                    ex);
+            throw ex;
+        }
+        if(getLog().isInfoEnabled())
+            getLog().info(sm.getString("http11protocol.resume", getName()));
     }
 
     @Override
-    public void preDeregister() throws Exception {
-        // NOOP
+    public void stop() throws Exception {
+        try {
+            endpoint.stop();
+        } catch (Exception ex) {
+            getLog().error(sm.getString("http11protocol.endpoint.stoperror"),
+                    ex);
+            throw ex;
+        }
+        if(getLog().isInfoEnabled())
+            getLog().info(sm.getString("http11protocol.stop", getName()));
     }
 
     @Override
-    public void postDeregister() {
-        // NOOP
+    public void destroy() throws Exception {
+        if(getLog().isInfoEnabled())
+            getLog().info(sm.getString("http11protocol.destroy", getName()));
+        endpoint.destroy();
+        if( tpOname!=null )
+            Registry.getRegistry(null, null).unregisterComponent(tpOname);
+        if( rgOname != null )
+            Registry.getRegistry(null, null).unregisterComponent(rgOname);
     }
+    
+
 }



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


Mime
View raw message