You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2008/02/21 20:46:51 UTC

svn commit: r629955 - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/jaxws/framework/ osgi/ osgi/src/org/apache/axis2/extensions/osgi/ osgi/src/org/apache/axis2/extensions/osgi/util/

Author: dims
Date: Thu Feb 21 11:46:49 2008
New Revision: 629955

URL: http://svn.apache.org/viewvc?rev=629955&view=rev
Log:
Intermediate checkin...trying to deploy classes inside bundles as jaxws web services. Need to merge with Roy's changes hence the check-in.


Added:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java
Removed:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleListener.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
    webservices/axis2/trunk/java/modules/osgi/pom.xml
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/OSGiAxis2Servlet.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleClassLoader.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java?rev=629955&r1=629954&r2=629955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/framework/JAXWSDeployer.java Thu Feb 21 11:46:49 2008
@@ -148,9 +148,9 @@
                 Thread.currentThread().setContextClassLoader(classLoader);
 
                 ArrayList classList = getListOfClasses(deploymentFileData);
-                int count = deployClasses(groupName, location, classLoader, classList); 
+                AxisServiceGroup serviceGroup = deployClasses(groupName, location, classLoader, classList); 
                 
-                if(count == 0) {
+                if(serviceGroup == null) {
                     String msg = "Error:\n No annotated classes found in the jar: " +
                             location.toString() +
                             ". Service deployment failed.";
@@ -169,7 +169,7 @@
         }
     }
 
-    protected int deployClasses(String groupName, URL location, ClassLoader classLoader, List classList)
+    protected AxisServiceGroup deployClasses(String groupName, URL location, ClassLoader classLoader, List classList)
             throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxisFault {
         ArrayList axisServiceList = new ArrayList();
         for (int i = 0; i < classList.size(); i++) {
@@ -193,16 +193,17 @@
             }
         }
         int count = axisServiceList.size();
-        if (count > 0) {
-            AxisServiceGroup serviceGroup = new AxisServiceGroup();
-            serviceGroup.setServiceGroupName(groupName);
-            for (int i = 0; i < axisServiceList.size(); i++) {
-                AxisService axisService = (AxisService) axisServiceList.get(i);
-                serviceGroup.addService(axisService);
-            }
-            axisConfig.addServiceGroup(serviceGroup);
+        if (count <= 0) {
+            return null;
+        }
+        AxisServiceGroup serviceGroup = new AxisServiceGroup();
+        serviceGroup.setServiceGroupName(groupName);
+        for (int i = 0; i < axisServiceList.size(); i++) {
+            AxisService axisService = (AxisService) axisServiceList.get(i);
+            serviceGroup.addService(axisService);
         }
-        return count;
+        axisConfig.addServiceGroup(serviceGroup);
+        return serviceGroup;
     }
 
     protected ArrayList getListOfClasses(DeploymentFileData deploymentFileData) throws IOException {

Modified: webservices/axis2/trunk/java/modules/osgi/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/pom.xml?rev=629955&r1=629954&r2=629955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/pom.xml Thu Feb 21 11:46:49 2008
@@ -65,7 +65,7 @@
                         <Bundle-Description>OSGi Bundle for Axis2</Bundle-Description>
                         <Bundle-SymbolicName>org.apache.axis2.osgi</Bundle-SymbolicName>
                         <Bundle-Activator>org.apache.axis2.extensions.osgi.Activator</Bundle-Activator>
-                        <Export-Package>${bundle.namespace}.*;version="1.4"</Export-Package>
+                        <Export-Package>${bundle.namespace}.*;version="1.4",javax.jws.*;version="0.0.0",com.sun.tools.ws.spi.*;version="0.0.0"</Export-Package>
                         <Import-Package>*;resolution:=optional</Import-Package>
                         <Private-Package>org.apache.axis2.extensions.osgi.*</Private-Package>
                         <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
@@ -97,6 +97,69 @@
                 <exclusion>
                     <groupId>javax.servlet</groupId>
                     <artifactId>servlet-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.axis2</groupId>
+            <artifactId>axis2-jaxws</artifactId>
+            <version>${version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.servlet</groupId>
+                    <artifactId>servlet-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-xjc</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.ws</groupId> 
+            <artifactId>jaxws-rt</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-xjc</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.jvnet.staxex</groupId>
+                    <artifactId>stax-ex</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.jvnet</groupId>
+                    <artifactId>mimepull</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.ws</groupId> 
+            <artifactId>jaxws-tools</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-xjc</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.xml.bind</groupId>
+                    <artifactId>jaxb-impl</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.jvnet.staxex</groupId>
+                    <artifactId>stax-ex</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.jvnet</groupId>
+                    <artifactId>mimepull</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java?rev=629955&r1=629954&r2=629955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/Activator.java Thu Feb 21 11:46:49 2008
@@ -19,36 +19,78 @@
 
 package org.apache.axis2.extensions.osgi;
 
-import org.apache.axis2.extensions.osgi.util.BundleListener;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.HttpService;
+import org.osgi.service.log.LogService;
 
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator, BundleListener {
 
     BundleContext context;
+    OSGiAxis2Servlet servlet = new OSGiAxis2Servlet();
+    ServiceRegistry registry = null;
+    HttpService httpServ = null;
+    LogService log = null;
 
     public void start(BundleContext context) throws Exception {
         this.context = context;
+        context.addBundleListener(this);
 
         ServiceReference sr = context.getServiceReference(HttpService.class.getName());
         if (sr != null) {
             HttpService httpServ = (HttpService) context.getService(sr);
-
             try {
-                OSGiAxis2Servlet servlet = new OSGiAxis2Servlet();
                 httpServ.registerServlet("/axis2",
                         servlet, null, null);
-                context.addBundleListener(new BundleListener(servlet));
             } catch (Exception e) {
                 System.err.println("Exception registering Axis Servlet:"
                         + e);
             }
         }
+
+        ServiceReference sr2 = context.getServiceReference(LogService.class.getName());
+        if (sr2 != null) {
+            log = (LogService) context.getService(sr);
+            if (log == null) {
+                System.err.println("Unable to find Log Service");
+            }
+        }
+
+        registry = new ServiceRegistry(servlet, log);
+        
+// TODO: We should poke at all the bundles already in the system
+//        Bundle bundles[] = context.getBundles();
+//        for (int i = 0; i < bundles.length; i++) {
+//            if ((bundles[i].getState() &
+//                    (Bundle.STARTING | Bundle.ACTIVE)) != 0) {
+//                if(context.getBundle() != event.getBundle()){
+//                    registry.register(bundles[i]);
+//                }
+//            }
+//        }
     }
 
-    public void stop(BundleContext context) throws Exception {
+    public void bundleChanged(BundleEvent event) {
+        switch (event.getType()) {
+            case BundleEvent.STARTED:
+                if(context.getBundle() != event.getBundle()){
+                    registry.register(event.getBundle());
+                }
+                break;
+
+            case BundleEvent.STOPPED:
+                if(context.getBundle() != event.getBundle()){
+                    registry.unregister(event.getBundle());
+                }
+                break;
+        }
     }
 
+    public void stop(BundleContext context) throws Exception {
+        this.context.removeBundleListener(this);
+        registry.close();
+    }
 }

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/OSGiAxis2Servlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/OSGiAxis2Servlet.java?rev=629955&r1=629954&r2=629955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/OSGiAxis2Servlet.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/OSGiAxis2Servlet.java Thu Feb 21 11:46:49 2008
@@ -58,7 +58,7 @@
 
         configContext.setContextRoot(contextRoot);
     }
-    
+
     public AxisConfiguration getConfiguration() {
         return this.axisConfiguration;
     }

Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java?rev=629955&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/ServiceRegistry.java Thu Feb 21 11:46:49 2008
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.extensions.osgi;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.extensions.osgi.util.BundleClassLoader;
+import org.apache.axis2.jaxws.framework.JAXWSDeployer;
+import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogService;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
+public class ServiceRegistry extends JAXWSDeployer {
+    private OSGiAxis2Servlet servlet;
+    private LogService log;
+    private HashMap services = new HashMap();
+
+    public ServiceRegistry(OSGiAxis2Servlet servlet, LogService log) {
+        this.servlet = servlet;
+        this.log = log;
+    }
+
+    public void register(Bundle bundle) {
+        axisConfig = servlet.getConfiguration();
+        ClassLoader loader = new BundleClassLoader(bundle, this.getClass().getClassLoader());
+        ArrayList classes = new ArrayList();
+
+        Enumeration enumeration = bundle.findEntries("/", "*.class", true);
+        while (enumeration.hasMoreElements()) {
+            URL url = (URL) enumeration.nextElement();
+            String path = url.getPath();
+            // skip the leading '/' the trailing ".class" and replace path separator with '.'
+            path = path.substring(1, path.length() - 6).replace('/', '.');
+            classes.add(path);
+        }
+        try {
+            AxisServiceGroup serviceGroup = deployClasses(bundle.getSymbolicName(), null, loader, classes);
+            if (serviceGroup != null) {
+                System.out.println("Deployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+
+                for (Iterator iterator = serviceGroup.getServices(); iterator.hasNext();) {
+                    AxisService service = (AxisService) iterator.next();
+                    System.out.println("     Service - " + service.getName());
+                }
+                services.put(bundle, serviceGroup);
+            }
+        } catch (Exception e) {
+            log.log(LogService.LOG_INFO, "Exception deploying classes", e);
+        }
+    }
+
+    public void close() {
+        for (Iterator iterator = services.values().iterator(); iterator.hasNext();) {
+            AxisServiceGroup serviceGroup = (AxisServiceGroup) iterator.next();
+            try {
+                axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
+                System.out.println("Undeployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+
+                for (Iterator iterator2 = serviceGroup.getServices(); iterator2.hasNext();) {
+                    AxisService service = (AxisService) iterator2.next();
+                    System.out.println("     Service - " + service.getName());
+                }
+            } catch (AxisFault axisFault) {
+                log.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
+            }
+        }
+    }
+
+    public void unregister(Bundle bundle) {
+        AxisServiceGroup serviceGroup = (AxisServiceGroup) services.get(bundle);
+        if (serviceGroup != null) {
+            try {
+                axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
+                System.out.println("Undeployed ServiceGroup - " + serviceGroup.getServiceGroupName());
+
+                for (Iterator iterator2 = serviceGroup.getServices(); iterator2.hasNext();) {
+                    AxisService service = (AxisService) iterator2.next();
+                    System.out.println("     Service - " + service.getName());
+                }
+            } catch (AxisFault axisFault) {
+                log.log(LogService.LOG_INFO, axisFault.getMessage(), axisFault);
+            }
+        }
+    }
+}

Modified: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleClassLoader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleClassLoader.java?rev=629955&r1=629954&r2=629955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleClassLoader.java (original)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/extensions/osgi/util/BundleClassLoader.java Thu Feb 21 11:46:49 2008
@@ -34,10 +34,14 @@
     }
 
     protected Class findClass(String name) throws ClassNotFoundException {
-        return bundle.loadClass(name);
+        try {
+            return bundle.loadClass(name);
+        } catch (Exception e) {
+            return super.loadClass(name);
+        }
     }
 
-    protected URL findResource(String name) {
+    public URL findResource(String name) {
         URL resource = bundle.getResource(name);
         if (resource != null) {
             return resource;
@@ -45,7 +49,7 @@
         return super.findResource(name);
     }
 
-    protected Enumeration findResources(String name) throws IOException {
+    public Enumeration findResources(String name) throws IOException {
         Enumeration enumeration = bundle.getResources(name);
         if (enumeration != null) {
             return enumeration;



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