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 sa...@apache.org on 2008/06/18 14:44:52 UTC

svn commit: r669153 - in /webservices/axis2/trunk/java/modules/osgi: ./ resources/org/apache/axis2/osgi/deployment/ src/org/apache/axis2/osgi/deployment/ src/org/apache/axis2/osgi/util/

Author: saminda
Date: Wed Jun 18 05:44:52 2008
New Revision: 669153

URL: http://svn.apache.org/viewvc?rev=669153&view=rev
Log:
Added module layer and improved the code 

Added:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/BundleClassLoader.java
    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/Registry.java
Removed:
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/util/
Modified:
    webservices/axis2/trunk/java/modules/osgi/pom.xml
    webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml
    webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java

Modified: webservices/axis2/trunk/java/modules/osgi/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/pom.xml?rev=669153&r1=669152&r2=669153&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/pom.xml Wed Jun 18 05:44:52 2008
@@ -80,9 +80,19 @@
                             org.apache.axis2.engine.AxisConfiguration,
                             org.apache.axis2.context.ConfigurationContext
                         </Export-Service>
+                        <Bundle-RequiredExecutionEnvironment>
+                            J2SE-1.5
+                        </Bundle-RequiredExecutionEnvironment>
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
@@ -91,6 +101,7 @@
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <version>2.4</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.axis2</groupId>

Modified: webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml?rev=669153&r1=669152&r2=669153&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/resources/org/apache/axis2/osgi/deployment/axis2.xml Wed Jun 18 05:44:52 2008
@@ -108,14 +108,12 @@
     <!--any operation -->
     <!--Note : You can ovrride this for a particular service by adding the same element with your requirement-->
      <messageReceivers>
-        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
-                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
-        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
-                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
-        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-only"
-                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
-        <messageReceiver mep="http://www.w3.org/2006/01/wsdl/in-out"
-                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
+                         class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/ns/wsdl/robust-in-only"
+                         class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
+        <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
+                         class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
     </messageReceivers>
 
     <!-- ================================================= -->

Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java?rev=669153&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/AbstractRegistry.java Wed Jun 18 05:44:52 2008
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.osgi.deployment;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * @see org.apache.axis2.osgi.deployment.Registry
+ */
+public abstract class AbstractRegistry<V> implements Registry {
+
+    protected Map<Bundle, V> bundleMap = new ConcurrentHashMap<Bundle, V>();
+
+    protected final Lock lock = new ReentrantLock();
+
+    protected BundleContext context;
+
+    protected ConfigurationContext configCtx;
+
+    public AbstractRegistry(BundleContext context, ConfigurationContext configCtx) {
+        this.context = context;
+        this.configCtx = configCtx;
+    }
+
+    public void bundleChanged(BundleEvent event) {
+        Bundle bundle = event.getBundle();
+        try {
+            switch (event.getType()) {
+                case BundleEvent.STARTED:
+                    if (context.getBundle() != bundle) {
+                        register(event.getBundle());
+                    }
+                    break;
+
+                case BundleEvent.STOPPED:
+                    if (context.getBundle() != bundle) {
+                        unRegister(event.getBundle());
+                    }
+                    break;
+            }
+        } catch (AxisFault e) {
+            String msg = "Error while registering the bundle in AxisConfiguration";
+            throw new RuntimeException(msg, e);
+        }
+    }
+}

Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/BundleClassLoader.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/BundleClassLoader.java?rev=669153&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/BundleClassLoader.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/BundleClassLoader.java Wed Jun 18 05:44:52 2008
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.osgi.deployment;
+
+import org.osgi.framework.Bundle;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.io.IOException;
+
+/**
+ * This classloader will be used with AxisService, AxisModule etc
+ */
+public class BundleClassLoader extends ClassLoader {
+
+    private final Bundle bundle;
+
+    public BundleClassLoader(Bundle bundle, ClassLoader parent) {
+        super(parent);
+        this.bundle = bundle;
+    }
+
+    protected Class findClass(String name) throws ClassNotFoundException {
+        try {
+            return bundle.loadClass(name);
+        } catch (ClassNotFoundException e) {
+            //TODO: add the proper logging
+            e.printStackTrace();
+            throw e;
+        }
+    }
+
+    public URL findResource(String name) {
+        return bundle.getResource(name);
+    }
+
+    public Enumeration findResources(String name) throws IOException {
+        return bundle.getResources(name);
+    }
+
+    public URL getResource(String name) {
+        return findResource(name);
+    }
+
+    protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
+        Class clazz;
+        try {
+            clazz = findClass(name);
+        }
+        catch (ClassNotFoundException e) {
+            e.printStackTrace();
+            throw e;
+        }
+        if (resolve) {
+            resolveClass(clazz);
+        }
+        return clazz;
+    }
+
+    public Class loadClass(String name) throws ClassNotFoundException {
+        Class clazz;
+        try {
+            clazz = findClass(name);
+        }
+        catch (ClassNotFoundException e) {
+            e.printStackTrace();
+            throw e;
+        }
+        return clazz;
+    }
+}
+

Added: 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=669153&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/ModuleRegistry.java Wed Jun 18 05:44:52 2008
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.osgi.deployment;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.DeploymentEngine;
+import org.apache.axis2.deployment.ModuleBuilder;
+import org.apache.axis2.description.AxisModule;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * @see org.osgi.framework.BundleListener
+ */
+public class ModuleRegistry extends AbstractRegistry<AxisModule> {
+
+
+    public ModuleRegistry(BundleContext context, ConfigurationContext configCtx) {
+        super(context, configCtx);
+    }
+
+    public void register(Bundle bundle) throws AxisFault {
+        lock.lock();
+        try {
+            addModules(bundle);
+        } finally {
+            lock.unlock();
+        }
+
+    }
+
+    public void unRegister(Bundle bundle) throws AxisFault {
+        lock.lock();
+        try {
+            AxisModule module = bundleMap.get(bundle);
+            if (module != null) {
+                bundleMap.remove(bundle);
+                configCtx.getAxisConfiguration()
+                        .removeModule(module.getName(), module.getVersion());
+                System.out.println("[Axis2/OSGi] Stopping" + module.getName() + ":" +
+                                   module.getVersion() + " moduel in Bundle - " +
+                                   bundle.getSymbolicName());
+            }
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    private void addModules(Bundle bundle) throws AxisFault {
+        if (!bundleMap.containsKey(bundle)) {
+            try {
+                Enumeration enumeration = bundle.findEntries("META-INF", "module.xml", false);
+                while (enumeration != null && enumeration.hasMoreElements()) {
+                    URL url = (URL) enumeration.nextElement();
+                    String urlString = url.toString();
+                    //                String shortFileName = urlString.substring(urlString.lastIndexOf('/'));
+                    AxisModule axismodule = new AxisModule();
+                    ClassLoader loader =
+                            new BundleClassLoader(bundle, Registry.class.getClassLoader());
+                    axismodule.setModuleClassLoader(loader);
+                    ModuleBuilder builder =
+                            new ModuleBuilder(url.openStream(), axismodule,
+                                              configCtx.getAxisConfiguration());
+                    //                axismodule.setName(org.apache.axis2.util.Utils.getModuleName(shortFileName));
+                    //                axismodule.setVersion(org.apache.axis2.util.Utils.getModuleVersion(shortFileName));
+                    builder.populateModule();
+                    axismodule.setParent(configCtx.getAxisConfiguration());
+                    //                axismodule.setFileName(new URL(bundle.getLocation()));
+                    //TODO this logic needed to be revised. remove sout
+                    AxisModule module =
+                            configCtx.getAxisConfiguration().getModule(axismodule.getName());
+                    if (module == null) {
+                        DeploymentEngine.addNewModule(axismodule, configCtx.getAxisConfiguration());
+                        bundleMap.put(bundle, axismodule);
+                        System.out.println("[Axis2/OSGi] Starting any modules in Bundle - " +
+                                           bundle.getSymbolicName());
+                    } else {
+                        System.out.println("[ModuleRegistry] Module : " + axismodule.getName() +
+                                           " is already available.");
+                    }
+                }
+                //TODO init the module 
+            } catch (IOException e) {
+                String msg = "Error while reading module.xml";
+                throw new AxisFault(msg, e);
+            }
+        }
+
+    }
+}

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=669153&r1=669152&r2=669153&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 Jun 18 05:44:52 2008
@@ -20,6 +20,7 @@
 import org.apache.axis2.engine.AxisConfigurator;
 import org.apache.axis2.AxisFault;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Bundle;
 
 /**
  *
@@ -30,7 +31,25 @@
             AxisConfigurator axisConfigurator, BundleContext context) throws AxisFault {
         ConfigurationContext configCtx =
                 ConfigurationContextFactory.createConfigurationContext(axisConfigurator);
-        //TODO: TBD, add service, module listeners
+
+        // first check (bundlestarts at the end or partially) {
+        //      // loop  and add axis*
+        // } then {
+        //      // stat the bundle early
+        // }
+        Registry moduleRegistry = new ModuleRegistry(context, configCtx);
+        Bundle[] bundles = context.getBundles();
+        if (bundles != null) {
+            for (Bundle bundle : bundles) {
+                if (bundle != context.getBundle()) {
+                    moduleRegistry.register(bundle);
+                }
+            }
+        }
+        context.addBundleListener(moduleRegistry);
+
+        //TODO: TBD, service listeners
+
         return configCtx;
 
     }

Added: webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java?rev=669153&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java (added)
+++ webservices/axis2/trunk/java/modules/osgi/src/org/apache/axis2/osgi/deployment/Registry.java Wed Jun 18 05:44:52 2008
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.osgi.deployment;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleListener;
+import org.apache.axis2.AxisFault;
+
+/**
+ *  This interface will be used to register the extension/file
+ * that needed be processed and create the relevant Axis* object.
+ */
+public interface Registry extends BundleListener{
+
+    void register(Bundle bundle) throws AxisFault;
+
+    void unRegister(Bundle bundle) throws AxisFault;
+}