[jbossws-commits] JBossWS SVN: r2382 - in branches/jbossws-1.2.0: integration-jboss42/src/main/java/org/jboss/ws/integration/jboss42 and 7 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Fri Feb 16 07:12:28 EST 2007


Author: thomas.diesler at jboss.com
Date: 2007-02-16 07:12:28 -0500 (Fri, 16 Feb 2007)
New Revision: 2382

Modified:
   branches/jbossws-1.2.0/integration-jboss40/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
   branches/jbossws-1.2.0/integration-jboss42/src/main/java/org/jboss/ws/integration/jboss42/ServerConfigImpl.java
   branches/jbossws-1.2.0/integration-jboss42/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
   branches/jbossws-1.2.0/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServerConfigImpl.java
   branches/jbossws-1.2.0/integration-jboss50/src/main/resources/jbossws.deployer/META-INF/jbossws-deployer-beans.xml
   branches/jbossws-1.2.0/integration-tomcat/src/main/java/org/jboss/ws/integration/tomcat/ServerConfigImpl.java
   branches/jbossws-1.2.0/integration-tomcat/src/main/resources/jbossws.war/META-INF/jboss-beans.xml
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/KernelLocator.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServerConfig.java
   branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointManager.java
   branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1115/JBWS1115TestCase.java
Log:
[JBWS-1115] Auto discover HTTP(S) port configuration from Tomcat

Modified: branches/jbossws-1.2.0/integration-jboss40/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
===================================================================
--- branches/jbossws-1.2.0/integration-jboss40/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-jboss40/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2007-02-16 12:12:28 UTC (rev 2382)
@@ -4,6 +4,10 @@
   xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
   xmlns="urn:jboss:bean-deployer">
   
+  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
+    <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
+  </bean>
+  
   <bean name="ServiceEndpointManager" class="org.jboss.ws.core.server.ServiceEndpointManager">
     
     <!--
@@ -16,10 +20,16 @@
       If next line (webServiceHost) is commented, JBossWS uses requesters protocolo, host and port when rewriting the <soap:address>.
     -->
     <property name="webServiceHost">${jboss.bind.address}</property>
-    <property name="webServiceSecurePort">8443</property>
-    <property name="webServicePort">8080</property>
     <property name="alwaysModifySOAPAddress">true</property>
     
+    <!-- 
+      Set these properties to explicitly define the ports that will be used for rewriting the SOAP address.
+      Otherwise the ports will be identified by querying the list of installed connectors. 
+      If multiple connectors are found the port of the first connector is used.                                                         -->
+      <property name="webServiceSecurePort">8443</property>
+      <property name="webServicePort">8080</property>
+    -->
+    
     <property name="serviceEndpointInvokerJSE">org.jboss.ws.core.server.ServiceEndpointInvokerJSE</property>
     <property name="serviceEndpointInvokerEJB3">org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3</property>
     <property name="serviceEndpointInvokerEJB21">org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB21</property>
@@ -47,8 +57,4 @@
   
   <bean name="ServerConfig" class="org.jboss.ws.integration.jboss42.ServerConfigImpl"/>
   
-  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
-    <!--property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property-->
-  </bean>
-  
 </deployment>

Modified: branches/jbossws-1.2.0/integration-jboss42/src/main/java/org/jboss/ws/integration/jboss42/ServerConfigImpl.java
===================================================================
--- branches/jbossws-1.2.0/integration-jboss42/src/main/java/org/jboss/ws/integration/jboss42/ServerConfigImpl.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-jboss42/src/main/java/org/jboss/ws/integration/jboss42/ServerConfigImpl.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -145,6 +145,5 @@
       {
          return -1;
       }
-
    }
 }

Modified: branches/jbossws-1.2.0/integration-jboss42/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
===================================================================
--- branches/jbossws-1.2.0/integration-jboss42/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-jboss42/src/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2007-02-16 12:12:28 UTC (rev 2382)
@@ -4,6 +4,10 @@
   xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
   xmlns="urn:jboss:bean-deployer">
   
+  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
+    <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
+  </bean>
+  
   <bean name="ServiceEndpointManager" class="org.jboss.ws.core.server.ServiceEndpointManager">
     
     <!--
@@ -16,10 +20,16 @@
         If next line (webServiceHost) is commented, JBossWS uses requesters protocolo, host and port when rewriting the <soap:address>.
     -->
     <property name="webServiceHost">${jboss.bind.address}</property>
-    <property name="webServiceSecurePort">8443</property>
-    <property name="webServicePort">8080</property>
     <property name="alwaysModifySOAPAddress">true</property>
     
+    <!-- 
+      Set these properties to explicitly define the ports that will be used for rewriting the SOAP address.
+      Otherwise the ports will be identified by querying the list of installed connectors. 
+      If multiple connectors are found the port of the first connector is used.                                                         -->
+      <property name="webServiceSecurePort">8443</property>
+      <property name="webServicePort">8080</property>
+    -->
+    
     <property name="serviceEndpointInvokerJSE">org.jboss.ws.core.server.ServiceEndpointInvokerJSE</property>
     <property name="serviceEndpointInvokerEJB3">org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB3</property>
     <property name="serviceEndpointInvokerEJB21">org.jboss.ws.integration.jboss42.ServiceEndpointInvokerEJB21</property>
@@ -44,8 +54,4 @@
   
   <bean name="ServerConfig" class="org.jboss.ws.integration.jboss42.ServerConfigImpl"/>
   
-  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
-    <!--property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property-->
-  </bean>
-  
 </deployment>

Modified: branches/jbossws-1.2.0/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServerConfigImpl.java
===================================================================
--- branches/jbossws-1.2.0/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServerConfigImpl.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/ServerConfigImpl.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -24,11 +24,14 @@
 //$Id$
 
 import java.io.File;
+import java.util.Set;
 
+import javax.management.AttributeNotFoundException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.jboss.logging.Logger;
 import org.jboss.mx.util.MBeanServerLocator;
 import org.jboss.ws.core.server.ServerConfig;
 import org.jboss.ws.core.utils.ObjectNameFactory;
@@ -37,10 +40,13 @@
  * JBoss specific implementation of a ServerConfig 
  *
  * @author Thomas.Diesler at jboss.org
+ * @author darran.lofthouse at jboss.com
  * @since 08-May-2006
  */
 public class ServerConfigImpl implements ServerConfig
 {
+   private static final Logger log = Logger.getLogger(ServerConfigImpl.class);
+   
    public File getServerTempDir()
    {
       try
@@ -70,4 +76,73 @@
          return null;
       }
    }
+   
+   public int getWebServicePort()
+   {
+      int port = getConnectorPort("HTTP/1.1", false);
+      if (port > -1)
+      {
+         return port;
+      }
+
+      log.warn("Unable to calculate 'WebServicePort', using default '8080'");
+      return 8080;
+   }
+
+   public int getWebServiceSecurePort()
+   {
+      int port = getConnectorPort("HTTP/1.1", true);
+      if (port > -1)
+      {
+         return port;
+      }
+
+      log.warn("Unable to calculate 'WebServiceSecurePort', using default '8443'");
+      return 8443;
+   }
+
+   private int getConnectorPort(final String protocol, final boolean secure)
+   {
+      int port = -1;
+
+      try
+      {
+         MBeanServer server = MBeanServerLocator.locateJBoss();
+         ObjectName connectors = new ObjectName("jboss.web:type=Connector,*");
+
+         Set connectorNames = server.queryNames(connectors, null);
+         for (Object current : connectorNames)
+         {
+            ObjectName currentName = (ObjectName)current;
+
+            try
+            {
+               int connectorPort = (Integer)server.getAttribute(currentName, "port");
+               boolean connectorSecure = (Boolean)server.getAttribute(currentName, "secure");
+               String connectorProtocol = (String)server.getAttribute(currentName, "protocol");
+
+               if (protocol.equals(connectorProtocol) && secure == connectorSecure)
+               {
+                  if (port > -1)
+                  {
+                     log.warn("Found multiple connectors for protocol='" + protocol + "' and secure='" + secure + "', using first port found '" + port + "'");
+                  }
+                  else
+                  {
+                     port = connectorPort;
+                  }
+               }
+            }
+            catch (AttributeNotFoundException ignored)
+            {
+            }
+         }
+
+         return port;
+      }
+      catch (JMException e)
+      {
+         return -1;
+      }
+   }
 }

Modified: branches/jbossws-1.2.0/integration-jboss50/src/main/resources/jbossws.deployer/META-INF/jbossws-deployer-beans.xml
===================================================================
--- branches/jbossws-1.2.0/integration-jboss50/src/main/resources/jbossws.deployer/META-INF/jbossws-deployer-beans.xml	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-jboss50/src/main/resources/jbossws.deployer/META-INF/jbossws-deployer-beans.xml	2007-02-16 12:12:28 UTC (rev 2382)
@@ -2,6 +2,10 @@
 
 <deployment xmlns="urn:jboss:bean-deployer:2.0">
   
+  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
+    <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
+  </bean>
+  
   <bean name="ServiceEndpointManager" class="org.jboss.ws.core.server.ServiceEndpointManager">
     
     <!--
@@ -14,10 +18,16 @@
         If next line (webServiceHost) is commented, JBossWS uses requesters protocolo, host and port when rewriting the <soap:address>.
     -->
     <property name="webServiceHost">${jboss.bind.address}</property>
-    <property name="webServiceSecurePort">8443</property>
-    <property name="webServicePort">8080</property>
     <property name="alwaysModifySOAPAddress">true</property>
     
+    <!-- 
+      Set these properties to explicitly define the ports that will be used for rewriting the SOAP address.
+      Otherwise the ports will be identified by querying the list of installed connectors. 
+      If multiple connectors are found the port of the first connector is used.                                                         -->
+      <property name="webServiceSecurePort">8443</property>
+      <property name="webServicePort">8080</property>
+    -->
+    
     <property name="serviceEndpointInvokerJSE">org.jboss.ws.core.server.ServiceEndpointInvokerJSE</property>
     <property name="serviceEndpointInvokerEJB3">org.jboss.ws.integration.jboss50.ServiceEndpointInvokerEJB3</property>
     <property name="serviceEndpointInvokerEJB21">org.jboss.ws.integration.jboss50.ServiceEndpointInvokerEJB21</property>
@@ -48,10 +58,6 @@
   
   <bean name="ServerConfig" class="org.jboss.ws.integration.jboss50.ServerConfigImpl"/>
   
-  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
-    <!--property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property-->
-  </bean>
-  
   <bean name="JAXWSDeployerEJB3" class="org.jboss.ws.integration.jboss50.JAXWSDeployerEJB3">
     <install bean="MainDeployer" method="addDeployer">
       <parameter>

Modified: branches/jbossws-1.2.0/integration-tomcat/src/main/java/org/jboss/ws/integration/tomcat/ServerConfigImpl.java
===================================================================
--- branches/jbossws-1.2.0/integration-tomcat/src/main/java/org/jboss/ws/integration/tomcat/ServerConfigImpl.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-tomcat/src/main/java/org/jboss/ws/integration/tomcat/ServerConfigImpl.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -65,4 +65,14 @@
          return null;
       }
    }
+   
+   public int getWebServicePort()
+   {      
+      return 8080;
+   }
+
+   public int getWebServiceSecurePort()
+   {      
+      return 8443;
+   }   
 }

Modified: branches/jbossws-1.2.0/integration-tomcat/src/main/resources/jbossws.war/META-INF/jboss-beans.xml
===================================================================
--- branches/jbossws-1.2.0/integration-tomcat/src/main/resources/jbossws.war/META-INF/jboss-beans.xml	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/integration-tomcat/src/main/resources/jbossws.war/META-INF/jboss-beans.xml	2007-02-16 12:12:28 UTC (rev 2382)
@@ -4,6 +4,10 @@
   xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
   xmlns="urn:jboss:bean-deployer">
   
+  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator">
+    <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
+  </bean>
+  
   <bean name="ServiceEndpointManager" class="org.jboss.ws.core.server.ServiceEndpointManager">
     <!--
       The WSDL, that is a required deployment artifact for an endpoint, has a <soap:address>
@@ -12,10 +16,17 @@
       If the content of <soap:address> is a valid URL, JBossWS will not rewrite it unless AlwaysModifySOAPAddress is true.
       If the content of <soap:address> is not a valid URL, JBossWS will rewrite it using the attribute values given below.
     -->
+    <property name="webServiceHost">localhost</property>
     <property name="alwaysModifySOAPAddress">true</property>
-    <property name="webServiceHost">localhost</property>
-    <property name="webServiceSecurePort">8443</property>
-    <property name="webServicePort">8080</property>
+    
+    <!-- 
+      Set these properties to explicitly define the ports that will be used for rewriting the SOAP address.
+      Otherwise the ports will be identified by querying the list of installed connectors. 
+      If multiple connectors are found the port of the first connector is used.                                                         -->
+      <property name="webServiceSecurePort">8443</property>
+      <property name="webServicePort">8080</property>
+    -->
+    
     <property name="serviceEndpointInvokerJSE">org.jboss.ws.core.server.ServiceEndpointInvokerJSE</property>
   </bean>
   
@@ -37,6 +48,4 @@
   
   <bean name="ServerConfig" class="org.jboss.ws.integration.tomcat.ServerConfigImpl"/>
   
-  <bean name="KernelLocator" class="org.jboss.ws.core.server.KernelLocator"/>
-  
 </deployment>

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/KernelLocator.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/KernelLocator.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/KernelLocator.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -24,8 +24,6 @@
 //$Id: WebServiceDeployer.java 312 2006-05-11 10:49:22Z thomas.diesler at jboss.com $
 
 import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
 
 /**
  * Locate the single instance of the kernel 
@@ -33,22 +31,17 @@
  * @author Thomas.Diesler at jboss.org
  * @since 12-May-2006
  */
-public class KernelLocator implements KernelControllerContextAware
+public class KernelLocator 
 {
    private static Kernel kernel;
 
    public static Kernel getKernel()
    {
-      return kernel;
+      return KernelLocator.kernel;
    }
 
-   public void setKernelControllerContext(KernelControllerContext context) throws Exception
+   public void setKernel(Kernel kernel)
    {
-      kernel = context.getKernel();
+      KernelLocator.kernel = kernel;
    }
-
-   public void unsetKernelControllerContext(KernelControllerContext arg0) throws Exception
-   {
-      kernel = null;
-   }
 }

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServerConfig.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServerConfig.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServerConfig.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -38,4 +38,8 @@
    File getServerTempDir();
 
    File getServerDataDir();
+
+   int getWebServicePort();
+   
+   int getWebServiceSecurePort();
 }

Modified: branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointManager.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointManager.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/jbossws-core/src/main/java/org/jboss/ws/core/server/ServiceEndpointManager.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -148,11 +148,25 @@
 
    public void setWebServicePort(int port)
    {
+      if (port == 0)
+      {
+         ServerConfigFactory factory = ServerConfigFactory.getInstance();
+         ServerConfig config = factory.getServerConfig();
+         port = config.getWebServicePort();
+         log.debug("Using WebServicePort: " + port);
+      }
       this.webServicePort = port;
    }
 
    public void setWebServiceSecurePort(int port)
    {
+      if (port == 0)
+      {
+         ServerConfigFactory factory = ServerConfigFactory.getInstance();
+         ServerConfig config = factory.getServerConfig();
+         port = config.getWebServiceSecurePort();
+         log.debug("Using WebServiceSecurePort: " + port);
+      }
       this.webServiceSecurePort = port;
    }
 

Modified: branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1115/JBWS1115TestCase.java
===================================================================
--- branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1115/JBWS1115TestCase.java	2007-02-16 11:23:55 UTC (rev 2381)
+++ branches/jbossws-1.2.0/jbossws-tests/src/main/java/org/jboss/test/ws/jaxrpc/jbws1115/JBWS1115TestCase.java	2007-02-16 12:12:28 UTC (rev 2382)
@@ -34,32 +34,34 @@
  * http://jira.jboss.org/jira/browse/JBWS-1115
  * 
  * @author darran.lofthouse at jboss.com
+ * @author Thomas.Diesler at jboss.com
  * @since 15-October-2006
  */
 public class JBWS1115TestCase extends JBossWSTest
 {
-
    private final ObjectName manager = ObjectNameFactory.create("jboss.ws:service=ServiceEndpointManager");
 
    public void testDiscoverWebServicePort() throws Exception
    {
       MBeanServerConnection server = getServer();
-      Attribute attribute = new Attribute("WebServicePort", new Integer(0));
-      server.setAttribute(manager, attribute);
-      Integer port = (Integer)server.getAttribute(manager, "WebServicePort");
+      
+      String attrName = "WebServicePort";
+      Integer orgPort = (Integer)server.getAttribute(manager, attrName);
+      server.setAttribute(manager, new Attribute(attrName, new Integer(0)));
+      Integer newPort = (Integer)server.getAttribute(manager, attrName);
 
-      System.out.println("FIXME: [JBWS-1115] Auto discover HTTP(S) port configuration from Tomcat");
-      //assertEquals("WebServicePort", 8080, port.intValue());
+      assertEquals(attrName, orgPort, newPort);
    }
 
    public void testDiscoverWebServiceSecurePort() throws Exception
    {
       MBeanServerConnection server = getServer();
-      Attribute attribute = new Attribute("WebServiceSecurePort", new Integer(0));
-      server.setAttribute(manager, attribute);
-      Integer port = (Integer)server.getAttribute(manager, "WebServiceSecurePort");
+      
+      String attrName = "WebServiceSecurePort";
+      Integer orgPort = (Integer)server.getAttribute(manager, attrName);
+      server.setAttribute(manager, new Attribute(attrName, new Integer(0)));
+      Integer newPort = (Integer)server.getAttribute(manager, attrName);
 
-      System.out.println("FIXME: [JBWS-1115] Auto discover HTTP(S) port configuration from Tomcat");
-      //assertEquals("WebServiceSecurePort", 8443, port.intValue());
+      assertEquals(attrName, orgPort, newPort);
    }
 }




More information about the jbossws-commits mailing list