axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r675367 - in /webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi: deployment/ModuleRegistry.java deployment/OSGiConfigurationContextFactory.java deployment/ServiceRegistry.java internal/Activator.java
Date Wed, 09 Jul 2008 22:34:44 GMT
Author: saminda
Date: Wed Jul  9 15:34:43 2008
New Revision: 675367

URL: http://svn.apache.org/viewvc?rev=675367&view=rev
Log:
Added FrameworkListener to sync with refresh events 

Modified:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java?rev=675367&r1=675366&r2=675367&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java
Wed Jul  9 15:34:43 2008
@@ -104,7 +104,7 @@
                 if (resolvedBundles.containsKey(bundle)) {
                     resolvedBundles.remove(bundle);
                 }
-                log.info("[Axis2/OSGi] Stopping" + module.getName() + ":" +
+                log.info("[Axis2/OSGi] Stopping :" + module.getName() + " : " +
                          module.getVersion() + " moduel in Bundle - " +
                          bundle.getSymbolicName());
             }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java?rev=675367&r1=675366&r2=675367&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
Wed Jul  9 15:34:43 2008
@@ -19,20 +19,22 @@
 import org.apache.axis2.builder.Builder;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.deployment.Deployer;
+import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.engine.*;
 import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.*;
 import org.apache.axis2.osgi.tx.HttpListener;
-import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.transport.TransportSender;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.*;
-import org.osgi.service.cm.ManagedService;
 import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
 
 import java.util.Dictionary;
 import java.util.Iterator;
@@ -46,72 +48,100 @@
  */
 public class OSGiConfigurationContextFactory implements ManagedService {
 
+    private static Log log = LogFactory.getLog(OSGiConfigurationContextFactory.class);
+
     private BundleContext context;
 
-    private ServiceRegistration registration;
+    private ServiceRegistration mngServiceRegistration;
 
-    public synchronized void start(BundleContext context) {
+    private ConfigurationContext configCtx;
+
+    private ServiceRegistration configCtxServiceRegistration;
+
+
+    public synchronized void init(BundleContext context) {
         this.context = context;
         Dictionary props = new Properties();
         props.put(Constants.SERVICE_PID, "org.apache.axis2.osgi");
-        registration = context.registerService(ManagedService.class.getName(), this, props);
+        mngServiceRegistration =
+                context.registerService(ManagedService.class.getName(), this, props);
     }
 
     public synchronized void stop() {
-        registration.unregister();
+        if (mngServiceRegistration != null) {
+            mngServiceRegistration.unregister();
+        }
+        if (configCtx != null) {
+            try {
+                configCtx.terminate();
+                configCtx = null;
+            } catch (AxisFault e) {
+                String msg = "Error while ConfigurationContext is terminated";
+                log.error(msg, e);
+            }
+        }
+        log.info("Axis2 environment has stopped");
     }
 
     public synchronized void startConfigurationContext(Dictionary dictionary) throws AxisFault
{
         AxisConfigurator configurator = new OSGiServerConfigurator(context);
-        ConfigurationContext configCtx =
-                ConfigurationContextFactory.createConfigurationContext(configurator);
+        configCtx = ConfigurationContextFactory.createConfigurationContext(configurator);
         ListenerManager listenerManager = new ListenerManager();
         listenerManager.init(configCtx);
         listenerManager.start();
         ListenerManager.defaultConfigurationContext = configCtx;
-        //register ConfigurationContext as a OSGi serivce
-        context.registerService(ConfigurationContext.class.getName(), configCtx, null);
+    }
 
-        // first check (bundlestarts at the end or partially) {
-        //      // loop  and add axis*
-        // } then {
-        //      // stat the bundle early
-        // }
-        Registry servicesRegistry = new ServiceRegistry(context, configCtx);
-        Registry moduleRegistry = new ModuleRegistry(context, configCtx, servicesRegistry);
-        Bundle[] bundles = context.getBundles();
-        if (bundles != null) {
-            for (Bundle bundle : bundles) {
-                if (bundle != context.getBundle()) {
-                    if (bundle.getState() == Bundle.ACTIVE) {
-                        moduleRegistry.register(bundle);
+    public void updated(Dictionary dictionary) throws ConfigurationException {
+        try {
+            startConfigurationContext(dictionary);
+            if (configCtxServiceRegistration != null) {
+                configCtxServiceRegistration.unregister();
+            }
+            //register ConfigurationContext as a OSGi serivce
+            configCtxServiceRegistration =
+                    context.registerService(ConfigurationContext.class.getName(), configCtx,
null);
+
+            // first check (bundlestarts at the end or partially) {
+            //      // loop  and add axis*
+            // } then {
+            //      // stat the bundle early
+            // }
+            Registry servicesRegistry = new ServiceRegistry(context, configCtx);
+            Registry moduleRegistry = new ModuleRegistry(context, configCtx, servicesRegistry);
+            Bundle[] bundles = context.getBundles();
+            if (bundles != null) {
+                for (Bundle bundle : bundles) {
+                    if (bundle != context.getBundle()) {
+                        if (bundle.getState() == Bundle.ACTIVE) {
+                            moduleRegistry.register(bundle);
+                        }
                     }
                 }
-            }
-            for (Bundle bundle : bundles) {
-                if (bundle != context.getBundle()) {
-                    if (bundle.getState() == Bundle.ACTIVE) {
-                        servicesRegistry.register(bundle);
+                for (Bundle bundle : bundles) {
+                    if (bundle != context.getBundle()) {
+                        if (bundle.getState() == Bundle.ACTIVE) {
+                            servicesRegistry.register(bundle);
+                        }
                     }
                 }
             }
-        }
-        context.addBundleListener(moduleRegistry);
-        context.addBundleListener(servicesRegistry);
-        context.addServiceListener(new AxisConfigServiceListener(configCtx, context));
-        context.addServiceListener(new WSListener(configCtx, context));
-
-        Dictionary prop = new Properties();
-        prop.put(PROTOCOL, "http");
-        //adding the default listener
-        context.registerService(TransportListener.class.getName(), new HttpListener(context),
prop);
-    }
+            context.addBundleListener(moduleRegistry);
+            context.addBundleListener(servicesRegistry);
+            context.addServiceListener(new AxisConfigServiceListener(configCtx, context));
+            context.addServiceListener(new WSListener(configCtx, context));
+
+            Dictionary prop = new Properties();
+            prop.put(PROTOCOL, "http");
+            //adding the default listener
+            context.registerService(TransportListener.class.getName(), new HttpListener(context),
+                                    prop);
 
-    public void updated(Dictionary dictionary) throws ConfigurationException {
-        try {
-            startConfigurationContext(dictionary);
+
+            log.info("Axis2 environment has started.");
         } catch (AxisFault e) {
             String msg = "Error while creating ConfigurationContext";
+            log.error(msg, e);
             throw new ConfigurationException(msg, msg, e);
         }
 
@@ -146,8 +176,9 @@
             if (service instanceof TransportListener) {
                 String protocol = (String) reference.getProperty(PROTOCOL);
                 if (protocol == null || protocol.length() == 0) {
-                    throw new RuntimeException(
-                            "Protocol is not found for the trnasport object");
+                    String msg = "Protocol is not found for the trnasport object";
+                    log.error(msg);
+                    throw new RuntimeException(msg);
                 }
                 if (event.getType() == ServiceEvent.REGISTERED) {
                     TransportListener txListener =
@@ -172,6 +203,7 @@
                             } catch (AxisFault e) {
                                 String msg = "Error while reading transport properties from
:" +
                                              txListener.toString();
+                                log.error(msg, e);
                                 throw new RuntimeException(msg, e);
                             }
                         }
@@ -192,6 +224,7 @@
                         }
                     } catch (AxisFault e) {
                         String msg = "Error while intiating and starting the listener";
+                        log.error(msg, e);
                         throw new RuntimeException(msg, e);
                     }
                 }
@@ -199,7 +232,9 @@
             } else if (service instanceof Builder) {
                 String contextType = (String) reference.getProperty(CONTENT_TYPE);
                 if (contextType == null || contextType.length() == 0) {
-                    throw new RuntimeException(CONTENT_TYPE + " is missing from builder object");
+                    String msg = CONTENT_TYPE + " is missing from builder object";
+                    log.error(msg);
+                    throw new RuntimeException(msg);
                 }
                 if (event.getType() == ServiceEvent.REGISTERED || event.getType() ==
                                                                   ServiceEvent.MODIFIED)
{
@@ -214,7 +249,9 @@
             } else if (service instanceof MessageFormatter) {
                 String contextType = (String) reference.getProperty(CONTENT_TYPE);
                 if (contextType == null || contextType.length() == 0) {
-                    throw new RuntimeException(CONTENT_TYPE + " is missing from formatter
object");
+                    String msg = CONTENT_TYPE + " is missing from formatter object";
+                    log.error(msg);
+                    throw new RuntimeException(msg);
                 }
                 if (event.getType() == ServiceEvent.REGISTERED || event.getType() ==
                                                                   ServiceEvent.MODIFIED)
{
@@ -229,7 +266,9 @@
             } else if (service instanceof MessageReceiver) {
                 String mep = (String) reference.getProperty(MEP);
                 if (mep == null || mep.length() == 0) {
-                    throw new RuntimeException(MEP + " is missing from message receiver object");
+                    String msg = MEP + " is missing from message receiver object";
+                    log.error(msg);
+                    throw new RuntimeException(msg);
                 }
                 if (event.getType() == ServiceEvent.REGISTERED || event.getType() ==
                                                                   ServiceEvent.MODIFIED)
{

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java?rev=675367&r1=675366&r2=675367&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ServiceRegistry.java
Wed Jul  9 15:34:43 2008
@@ -62,7 +62,7 @@
      */
     private void addServices(Bundle bundle) {
         if (!resolvedBundles.containsKey(bundle)) {
-            Enumeration enumeration = bundle.findEntries("META-INF", "services.xml", false);
+            Enumeration enumeration = bundle.findEntries("META-INF", "*services.xml", false);
             int i = 0;
             List<AxisServiceGroup> axisServiceGroupList = null;
             if (enumeration != null) {
@@ -172,11 +172,11 @@
                 try {
                     for (Iterator iterator = axisServiceGroup.getServices(); iterator.hasNext();)
{
                         AxisService service = (AxisService) iterator.next();
-                        System.out.println("[Axis2/OSGi]      Service - " + service.getName());
+                        System.out.println("[Axis2/OSGi] Service - " + service.getName());
                     }
                     configCtx.getAxisConfiguration()
                             .removeServiceGroup(axisServiceGroup.getServiceGroupName());
-                    System.out.println("[Axis2/OSGi] Stopping" +
+                    System.out.println("[Axis2/OSGi] Stopping " +
                                        axisServiceGroup.getServiceGroupName() +
                                        " service group in Bundle - " +
                                        bundle.getSymbolicName());

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java?rev=675367&r1=675366&r2=675367&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
(original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/internal/Activator.java
Wed Jul  9 15:34:43 2008
@@ -19,9 +19,9 @@
 import org.apache.axis2.osgi.OSGiAxisServlet;
 import static org.apache.axis2.osgi.deployment.OSGiAxis2Constants.AXIS2_OSGi_ROOT_CONTEXT;
 import org.apache.axis2.osgi.deployment.OSGiConfigurationContextFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.*;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.http.NamespaceException;
 import org.osgi.util.tracker.ServiceTracker;
@@ -31,25 +31,32 @@
 /**
  * Activator will set the necessary parameters that initiate Axis2 OSGi integration
  */
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator, FrameworkListener {
+
+    private static Log log = LogFactory.getLog(Activator.class);
 
     private HttpServiceTracker tracker;
 
     private final OSGiConfigurationContextFactory managedService;
 
+    private BundleContext context;
+
+
     public Activator() {
         managedService = new OSGiConfigurationContextFactory();
     }
 
 
     public void start(BundleContext context) throws Exception {
-        managedService.start(context);
+        context.addFrameworkListener(this);
+        this.context = context;
+        managedService.init(context);
         managedService.updated(null);
         tracker = new HttpServiceTracker(context);
         tracker.open();
     }
 
-    public void stop(BundleContext context) throws Exception {
+    public void stop(BundleContext context) {
         tracker.close();
         managedService.stop();
         //ungetService ConfigurationContext.class.getName()
@@ -60,6 +67,30 @@
         }
     }
 
+    public void frameworkEvent(FrameworkEvent event) {
+        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
+            try {
+                Runnable thread = new Runnable() {
+                    public void run() {
+                        Bundle thisBundle = context.getBundle();
+                        try {
+                            thisBundle.stop();
+                            thisBundle.start();
+                        } catch (BundleException e) {
+                            String msg = "Error while refreshing the bundle";
+                            log.error(msg, e);
+                        }
+                    }
+                };
+                new Thread(thread).start();
+            } catch (Exception e) {
+                String msg = "Error while FrameworkEvent.PACKAGES_REFRESHED";
+                log.error(msg, e);
+            }
+        }
+
+    }
+
     //HttpServiceTracker
 
     class HttpServiceTracker extends ServiceTracker {
@@ -87,13 +118,15 @@
                     }
                 }
                 configCtx.setServicePath(serviceContextRoot);
-                httpService.registerServlet("/" + serviceContextRoot, axisServlet, null,
null);
+                String contextRoot = "/" + serviceContextRoot;
+                log.info("Registering SOAP message listener servlet to context : " + contextRoot);
+                httpService.registerServlet(contextRoot, axisServlet, null, null);
             } catch (ServletException e) {
                 String msg = "Error while registering servlets";
-                throw new RuntimeException(msg, e);
+                log.error(msg, e);
             } catch (NamespaceException e) {
                 String msg = "Namespace missmatch when registering servlets";
-                throw new RuntimeException(msg, e);
+                log.error(msg, e);
             }
             return httpService;
         }



Mime
View raw message