You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by de...@apache.org on 2007/06/16 16:10:50 UTC

svn commit: r547925 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: engine/AxisServer.java transport/SimpleAxis2Server.java

Author: deepal
Date: Sat Jun 16 07:10:49 2007
New Revision: 547925

URL: http://svn.apache.org/viewvc?view=rev&rev=547925
Log:
Make the AxisServer more useful considering everyone's suggestions. 

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisServer.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/SimpleAxis2Server.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisServer.java?view=diff&rev=547925&r1=547924&r2=547925
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisServer.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisServer.java Sat Jun 16 07:10:49 2007
@@ -22,24 +22,36 @@
 *
 *
 */
+
 /**
  * This class provide a very convenient way of creating server and deploying services.
  * Once someone call start method it will fire up configuration context and start up the listeners.
  *  One can provide repository location and axis.xml as system properties.
  */
+
 public class AxisServer {
 
-    private ConfigurationContext configContext;
+    protected ConfigurationContext configContext;
+    protected ListenerManager listenerManager;
+    private boolean startOnDeploy;
+    private boolean started = false;
+
 
     /**
-     * Will create a configuration context from the avialable data and then it
-     * will start the listener manager
-     * @throws AxisFault if something went wrong
+     * If you do not want Axis2 to start the server automatically then pass the "false" else "true"
+     * @param startOnDeploy : boolean
      */
-    public void strat()throws AxisFault {
-        configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null);
-        ListenerManager listenerManager = new ListenerManager();
-        listenerManager.startSystem(configContext);
+    public AxisServer(boolean startOnDeploy){
+        this.startOnDeploy = startOnDeploy;
+        listenerManager = new ListenerManager();
+    }
+
+
+    /**
+     * Server will start automatically if you call deployService
+     */
+    public AxisServer() {
+        this(true);
     }
 
     /**
@@ -49,25 +61,69 @@
      */
     public void deployService(String serviceClassName) throws AxisFault{
         if(configContext==null){
-            strat();
+            configContext = getConfigurationContext();
         }
         AxisConfiguration axisConfig = configContext.getAxisConfiguration();
         AxisService service = AxisService.createService(serviceClassName,axisConfig);
         axisConfig.addService(service);
+        if(startOnDeploy){
+            start();
+        }
+    }
+
+    /**
+     * Will create a configuration context from the avialable data and then it
+     * will start the listener manager
+     * @throws AxisFault if something went wrong
+     */
+    protected void start()throws AxisFault {
+        if(configContext==null){
+            configContext = getConfigurationContext();
+        }
+        if(!started){
+            listenerManager.startSystem(configContext);
+            started = true;
+        }
     }
 
+    /**
+     * Stop the server, automatically terminates the listener manager as well.
+     * @throws AxisFault
+     */
     public void stop() throws AxisFault{
         if(configContext!=null){
             configContext.terminate();
         }
     }
 
+    /**
+     * Set the configuration context. Please call this before you call deployService or start method
+     *
+     * @param configContext ConfigurationContext
+     */
+    public void setConfigurationContext(ConfigurationContext configContext) {
+        this.configContext = configContext;
+    }
 
-    public ConfigurationContext getConfigContext() {
+    /**
+     * Creates a default configuration context if one is not set already via setConfigurationContext
+     *
+     * @return ConfigurationContext
+     * @throws AxisFault
+     */
+    public ConfigurationContext getConfigurationContext() throws AxisFault {
+        if(configContext == null){
+            configContext = createDefaultConfigurationContext();
+        }
         return configContext;
     }
 
-    public void setConfigContext(ConfigurationContext configContext) {
-        this.configContext = configContext;
+    /**
+     * Users extending this class can override this method to supply a custom ConfigurationContext
+     * @return ConfigurationContext
+     * @throws AxisFault
+     */
+    protected ConfigurationContext createDefaultConfigurationContext() throws AxisFault {
+        return ConfigurationContextFactory.createConfigurationContextFromFileSystem(null);
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/SimpleAxis2Server.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/SimpleAxis2Server.java?view=diff&rev=547925&r1=547924&r2=547925
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/SimpleAxis2Server.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/SimpleAxis2Server.java Sat Jun 16 07:10:49 2007
@@ -19,6 +19,7 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.engine.AxisServer;
 import org.apache.axis2.transport.http.SimpleHTTPServer;
 import org.apache.axis2.util.CommandLineOption;
 import org.apache.axis2.util.CommandLineOptionParser;
@@ -30,7 +31,7 @@
 import java.util.List;
 import java.util.Map;
 
-public class SimpleAxis2Server {
+public class SimpleAxis2Server extends AxisServer {
 
     private static final Log log = LogFactory.getLog(SimpleHTTPServer.class);
 
@@ -39,6 +40,16 @@
     public static int DEFAULT_PORT = 8080;
 
 
+    public SimpleAxis2Server (
+            String repoLocation,
+            String confLocation) throws Exception {
+        super(false);
+        configContext = ConfigurationContextFactory
+                .createConfigurationContextFromFileSystem(repoLocation,
+                        confLocation);
+    }
+
+
     /**
      * @param args
      * @throws Exception
@@ -82,12 +93,8 @@
         }
 
         try {
-            ConfigurationContext configctx = ConfigurationContextFactory
-                    .createConfigurationContextFromFileSystem(repoLocation,
-                                                              confLocation);
-            ListenerManager listenerManager = new ListenerManager();
-            listenerManager.init(configctx);
-            listenerManager.start();
+            SimpleAxis2Server server = new SimpleAxis2Server(repoLocation, confLocation);
+            server.start();
             log.info("[SimpleAxisServer] Started");
         } catch (Throwable t) {
             log.fatal("[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer", t);



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org