mx4j/src/tools/mx4j/tools/remote/soap SOAPConnectorServer.java,1.11,1.12

Simone Bordet <[email protected]>
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/soap
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32381/src/tools/mx4j/tools/remote/soap

Modified Files:
	SOAPConnectorServer.java 
Log Message:
Simplied usage by allowing:
+ Simple URLs: not anymore soap://host:8080/path/id/1 but only soap://host:8080/path
+ Allow more in-VM SOAPConnectorServers to share one instance only of Jetty (on different paths)

Index: SOAPConnectorServer.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/remote/soap/SOAPConnectorServer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** SOAPConnectorServer.java	2 Mar 2004 09:10:21 -0000	1.11
--- SOAPConnectorServer.java	18 Jul 2004 21:43:29 -0000	1.12
***************
*** 11,26 ****
  import java.io.IOException;
  import java.net.MalformedURLException;
- import java.util.Map;
  import java.util.HashMap;
! 
  import javax.management.MBeanServer;
  import javax.management.remote.JMXServiceURL;
- import javax.management.remote.JMXConnectorServerFactory;
  
  import mx4j.remote.ConnectionResolver;
  import mx4j.tools.remote.AbstractJMXConnectorServer;
- import mx4j.tools.remote.soap.web.axis.SimpleAxisWebContainer;
  import mx4j.tools.remote.soap.web.WebContainer;
- import mx4j.tools.remote.soap.web.jetty.JettyWebContainer;
  
  /**
--- 11,22 ----
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.util.HashMap;
! import java.util.Map;
  import javax.management.MBeanServer;
  import javax.management.remote.JMXServiceURL;
  
  import mx4j.remote.ConnectionResolver;
  import mx4j.tools.remote.AbstractJMXConnectorServer;
  import mx4j.tools.remote.soap.web.WebContainer;
  
  /**
***************
*** 32,38 ****
     public static final String USE_EXTERNAL_WEB_CONTAINER = "jmx.remote.x.soap.use.external.web.container";
     public static final String EMBEDDED_WEB_CONTAINER_CLASS = "jmx.remote.x.soap.embedded.web.container.class";
-    public static final String AXIS_DEPLOY_URL = "jmx.remote.x.axis.deploy.url";
-    // TODO: maybe worth to make this private ?
-    public static final String DEFAULT_AXIS_DEPLOY_URL = "/axis/services/AdminService";
     private static Map instances = new HashMap();
  
--- 28,31 ----
***************
*** 45,49 ****
     }
  
-    private MBeanServer mbeanServer;
     private WebContainer webContainer;
     private SOAPConnectionManager connectionManager;
--- 38,41 ----
***************
*** 54,62 ****
     }
  
-    public MBeanServer getMBeanServer()
-    {
-       return mbeanServer;
-    }
- 
     protected void doStart() throws IOException, IllegalStateException
     {
--- 46,49 ----
***************
*** 67,122 ****
        if (resolver == null) throw new MalformedURLException("Unsupported protocol: " + protocol);
  
!       MBeanServer realServer = null;
!       MBeanServer server = super.getMBeanServer();
! 
!       MBeanServer resolvedServer = (MBeanServer)resolver.createServer(address, environment);
!       if (resolvedServer == null)
!       {
!          if (server == null) throw new IllegalStateException("This SOAPConnectorServer is not attached to an MBeanServer");
!          realServer = server;
!       }
!       else
!       {
!          if (server == null)
!          {
!             realServer = resolvedServer;
!          }
!          else
!          {
!             if (server != resolvedServer) throw new IllegalStateException("This SOAPConnectorServer cannot be attached to 2 MBeanServers");
!             realServer = server;
!          }
!       }
!       this.mbeanServer = realServer;
  
!       boolean useExternalWebContainer = environment == null ? false : Boolean.valueOf(String.valueOf(environment.get(USE_EXTERNAL_WEB_CONTAINER))).booleanValue();
!       if (!useExternalWebContainer)
!       {
!          // Create and start an embedded web container
!          String webContainerClassName = environment == null ? null : (String)environment.get(EMBEDDED_WEB_CONTAINER_CLASS);
!          // Not present, by default use Jetty
!          if (webContainerClassName == null || webContainerClassName.length() == 0) webContainerClassName = JettyWebContainer.class.getName();
!          webContainer = createWebContainer(webContainerClassName, environment);
!          // Jetty not present, use AXIS
!          if (webContainer == null) webContainer = createWebContainer(SimpleAxisWebContainer.class.getName(), environment);
!          // Nothing present, give up
!          if (webContainer == null) throw new IOException("Could not start embedded web container");
!          try
!          {
!             webContainer.start(address, environment);
!          }
!          catch (RuntimeException x)
!          {
!             throw x;
!          }
!          catch (Exception x)
!          {
!             throw new IOException(x.toString());
!          }
!       }
  
        connectionManager = new SOAPConnectionManager(this, environment);
  
!       setAddress(resolver.bindServer(realServer, address, environment));
  
        // Here is where we give to clients the possibility to access us
--- 54,65 ----
        if (resolver == null) throw new MalformedURLException("Unsupported protocol: " + protocol);
  
!       MBeanServer server = getMBeanServer();
!       if (server == null) throw new IllegalStateException("This RMIConnectorServer is not attached to an MBeanServer");
  
!       webContainer = (WebContainer)resolver.createServer(address, environment);
  
        connectionManager = new SOAPConnectionManager(this, environment);
  
!       setAddress(resolver.bindServer(webContainer, address, environment));
  
        // Here is where we give to clients the possibility to access us
***************
*** 124,146 ****
     }
  
-    private WebContainer createWebContainer(String webContainerClassName, Map environment)
-    {
-       ClassLoader loader = Thread.currentThread().getContextClassLoader();
-       if (environment != null)
-       {
-          Object cl = environment.get(JMXConnectorServerFactory.PROTOCOL_PROVIDER_CLASS_LOADER);
-          if (cl instanceof ClassLoader) loader = (ClassLoader)cl;
-       }
- 
-       try
-       {
-          return (WebContainer)loader.loadClass(webContainerClassName).newInstance();
-       }
-       catch (Exception x)
-       {
-       }
-       return null;
-    }
- 
     private void register(JMXServiceURL url, SOAPConnectionManager manager) throws IOException
     {
--- 67,70 ----
***************
*** 168,182 ****
        ConnectionResolver resolver = ConnectionResolver.newConnectionResolver(protocol, environment);
        if (resolver == null) throw new MalformedURLException("Unsupported protocol: " + protocol);
!       resolver.unbindServer(getMBeanServer(), address, environment);
! 
!       try
!       {
!          if (webContainer != null) webContainer.stop();
!          webContainer = null;
!       }
!       catch (Exception x)
!       {
!          throw new IOException(x.toString());
!       }
     }
  
--- 92,97 ----
        ConnectionResolver resolver = ConnectionResolver.newConnectionResolver(protocol, environment);
        if (resolver == null) throw new MalformedURLException("Unsupported protocol: " + protocol);
!       resolver.unbindServer(webContainer, address, environment);
!       resolver.destroyServer(webContainer, address, environment);
     }
  



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.