geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r263979 - in /geronimo/trunk/modules: deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/ jetty/src/java/org/apache/geronimo/jetty/connector/ management/src/java/org/apache/geronimo/management/geronimo/ tomcat/src/java/org/ap...
Date Mon, 29 Aug 2005 01:02:19 GMT
Author: ammulder
Date: Sun Aug 28 18:02:11 2005
New Revision: 263979

URL: http://svn.apache.org/viewcvs?rev=263979&view=rev
Log:
Explicitly provide a connection URL to avoid supplying "localhost"
  or "0.0.0.0" to a remote client
Fix Tomcat connector to correctly handle if Tomcat changes the String
  host property into an InetAddress (GERONIMO-939)

Modified:
    geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
    geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebConnector.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java

Modified: geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
(original)
+++ geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
Sun Aug 28 18:02:11 2005
@@ -274,6 +274,10 @@
         addWebURLs(kernel, moduleIDs);
     }
 
+    /**
+     * Given a list of TargetModuleIDs, figure out which ones represent web
+     * modules and add a WebURL to each if possible.
+     */
     public static void addWebURLs(Kernel kernel, List moduleIDs) {
         Set webApps = null;
         String url = null;
@@ -294,19 +298,13 @@
                         if((connector = (ObjectName) map.get("HTTP")) == null) {
                             if((connector = (ObjectName) map.get("HTTPS")) == null) {
                                 connector = (ObjectName) map.get("AJP");
-                                if(connector != null) {
-                                    url = "ajp://";
-                                }
-                            } else {
-                                url = "https://";
                             }
-                        } else {
-                            url = "http://";
                         }
                         if(connector != null) {
                             try {
-                                url = url + kernel.getAttribute(connector, "host") + ":"
+ kernel.getAttribute(connector, "port");
+                                url = (String) kernel.getAttribute(connector, "connectUrl");
                             } catch (Exception e) {
+                                e.printStackTrace();
                                 url = null;
                             }
                         }

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
Sun Aug 28 18:02:11 2005
@@ -35,6 +35,10 @@
         return WebContainer.PROTOCOL_AJP;
     }
 
+    public int getDefaultPort() {
+        return -1;
+    }
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
Sun Aug 28 18:02:11 2005
@@ -35,6 +35,10 @@
         return WebContainer.PROTOCOL_HTTP;
     }
 
+    public int getDefaultPort() {
+        return 80;
+    }
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
Sun Aug 28 18:02:11 2005
@@ -46,6 +46,10 @@
         https = (SslListener) listener;
     }
 
+    public int getDefaultPort() {
+        return 443;
+    }
+
     public String getProtocol() {
         return WebContainer.PROTOCOL_HTTPS;
     }

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
Sun Aug 28 18:02:11 2005
@@ -19,6 +19,7 @@
 
 import java.net.UnknownHostException;
 import java.net.InetSocketAddress;
+import java.net.InetAddress;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
@@ -38,6 +39,7 @@
 public abstract class JettyConnector implements GBeanLifecycle, JettyWebConnector {
     private final JettyContainer container;
     protected final HttpListener listener;
+    private String connectHost;
 
     /**
      * Only used to allow declaration as a reference.
@@ -78,6 +80,29 @@
         listener.setPort(port);
     }
 
+    public abstract int getDefaultPort();
+
+    public String getConnectUrl() {
+        if(connectHost == null) {
+            String host = getHost();
+            if(host == null || host.equals("0.0.0.0")) {
+                InetAddress address = null;
+                try {
+                    address = InetAddress.getLocalHost();
+                } catch (UnknownHostException e) {
+                    host = "unknown-host";
+                }
+                if(address != null) {
+                    host = address.getHostName();
+                    if(host == null || host.equals("")) {
+                        host = address.getHostAddress();
+                    }
+                }
+            }
+            connectHost = host;
+        }
+        return getProtocol().toLowerCase()+"://"+connectHost+(getPort() == getDefaultPort()
? "" : ":"+getPort());
+    }
 
     public void setMinThreads(int minThreads) {
       ((ThreadedServer)listener).setMinThreads(minThreads);
@@ -228,7 +253,7 @@
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty HTTP Connector", JettyConnector.class);
         infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE);
-        infoFactory.addInterface(JettyWebConnector.class, new String[]{"host", "port", "minThreads","maxThreads","bufferSizeBytes","acceptQueueSize","lingerMillis","tcpNoDelay","redirectPort",},
+        infoFactory.addInterface(JettyWebConnector.class, new String[]{"host", "port", "minThreads","maxThreads","bufferSizeBytes","acceptQueueSize","lingerMillis","tcpNoDelay","redirectPort","connectUrl",},
                                                           new String[]{"host", "port", "redirectPort"});
         infoFactory.setConstructor(new String[] {"JettyContainer"});
         GBEAN_INFO = infoFactory.getBeanInfo();

Modified: geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebConnector.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebConnector.java
(original)
+++ geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebConnector.java
Sun Aug 28 18:02:11 2005
@@ -97,4 +97,13 @@
      */
     public void setRedirectPort(int port);
 
+    /**
+     * Gets a URL used to connect to the web server via this connector.
+     * This is not guaranteed to work (for example, if the server is
+     * located behind a proxy), but it should give a reasonable value if
+     * possible.  The form of the returned String should be
+     * http://hostname or http://hostname:port (in other words, suitable
+     * for appending a context path).
+     */
+    public String getConnectUrl();
 }

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java?rev=263979&r1=263978&r2=263979&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/ConnectorGBean.java
Sun Aug 28 18:02:11 2005
@@ -18,6 +18,7 @@
 
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
+import java.net.InetAddress;
 import java.util.Map;
 import java.util.HashMap;
 
@@ -41,6 +42,7 @@
     protected final Connector connector;
     private final TomcatContainer container;
     private String name;
+    private String connectHost;
 
     public ConnectorGBean(String name, String protocol, String host, int port, TomcatContainer
container) throws Exception {
         super(); // TODO: make it an attribute
@@ -144,6 +146,33 @@
         doStop();
     }
 
+    public int getDefaultPort() {
+        return getProtocol().equals(WebContainer.PROTOCOL_AJP) ? -1 :
+                getProtocol().equals(WebContainer.PROTOCOL_HTTP) ? 80 :
+                getProtocol().equals(WebContainer.PROTOCOL_HTTPS) ? 443 : -1;
+    }
+
+    public String getConnectUrl() {
+        if(connectHost == null) {
+            String host = getHost();
+            if(host == null || host.equals("0.0.0.0")) {
+                InetAddress address = null;
+                try {
+                    address = InetAddress.getLocalHost();
+                } catch (UnknownHostException e) {
+                    host = "unknown-host";
+                }
+                if(address != null) {
+                    host = address.getHostName();
+                    if(host == null || host.equals("")) {
+                        host = address.getHostAddress();
+                    }
+                }
+            }
+            connectHost = host;
+        }
+        return getProtocol().toLowerCase()+"://"+connectHost+(getPort() == getDefaultPort()
? "" : ":"+getPort());
+    }
 
     /**
      * Gets the network protocol that this connector handles.
@@ -179,7 +208,11 @@
      */
     public String getHost() {
         Object value = connector.getAttribute("address");
-        return value == null ? "0.0.0.0" : value.toString();
+        if(value == null) {
+            return "0.0.0.0";
+        } else if(value instanceof InetAddress) {
+            return ((InetAddress)value).getHostAddress();
+        } else return value.toString();
     }
 
     /**
@@ -377,7 +410,7 @@
         infoFactory.addAttribute("protocol", String.class, true);
         infoFactory.addReference("TomcatContainer", TomcatContainer.class, NameFactory.GERONIMO_SERVICE);
         infoFactory.addOperation("getInternalObject");
-        infoFactory.addInterface(TomcatWebConnector.class, new String[]{"host","port","bufferSizeBytes","maxThreads","acceptQueueSize","lingerMillis","tcpNoDelay","redirectPort","minSpareThreads","maxSpareThreads","maxHttpHeaderSizeBytes","hostLookupEnabled","connectionTimeoutMillis","uploadTimeoutEnabled"},
+        infoFactory.addInterface(TomcatWebConnector.class, new String[]{"host","port","bufferSizeBytes","maxThreads","acceptQueueSize","lingerMillis","tcpNoDelay","redirectPort","minSpareThreads","maxSpareThreads","maxHttpHeaderSizeBytes","hostLookupEnabled","connectionTimeoutMillis","uploadTimeoutEnabled","connectUrl",},
                                                            new String[]{"host","port","redirectPort"});
         infoFactory.setConstructor(new String[] { "name", "protocol", "host", "port", "TomcatContainer"});
         GBEAN_INFO = infoFactory.getBeanInfo();



Mime
View raw message