You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2009/01/29 04:50:07 UTC

svn commit: r738739 - in /ode/branches/APACHE_ODE_1.X: Rakefile utils/src/main/java/org/apache/ode/utils/AxisUtils.java

Author: midon
Date: Thu Jan 29 03:50:06 2009
New Revision: 738739

URL: http://svn.apache.org/viewvc?rev=738739&view=rev
Log:
Create a helper to configure an AxisService from a service.xml file

Added:
    ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java
Modified:
    ode/branches/APACHE_ODE_1.X/Rakefile

Modified: ode/branches/APACHE_ODE_1.X/Rakefile
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/Rakefile?rev=738739&r1=738738&r2=738739&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/Rakefile (original)
+++ ode/branches/APACHE_ODE_1.X/Rakefile Thu Jan 29 03:50:06 2009
@@ -565,7 +565,7 @@
 
   desc "ODE Utils"
   define "utils" do
-    compile.with COMMONS.collections, COMMONS.logging, COMMONS.pool, COMMONS.httpclient, COMMONS.codec, LOG4J, XERCES, JAVAX.stream, WSDL4J
+    compile.with AXIOM, AXIS2_ALL, COMMONS.collections, COMMONS.logging, COMMONS.pool, COMMONS.httpclient, COMMONS.codec, LOG4J, XERCES, JAVAX.stream, WSDL4J
 	test.exclude "*TestResources"
     package :jar
   end

Added: ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java?rev=738739&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java (added)
+++ ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java Thu Jan 29 03:50:06 2009
@@ -0,0 +1,64 @@
+package org.apache.ode.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.deployment.ServiceBuilder;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.AxisFault;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ *
+ */
+public class AxisUtils {
+
+    private static final Log log = LogFactory.getLog(AxisUtils.class);
+
+    public static void configureService(AxisService axisService, URL service_file) throws IOException, XMLStreamException, AxisFault {
+        configureService(new ConfigurationContext(axisService.getAxisConfiguration()), axisService, service_file);
+    }
+
+    /**
+     * Configure a service instance woth the specified service.xml document.
+     * If modules are mentionned in the document, <code>this</code> method will make sure they are properly engaged and engage them if necessary.
+     * The modules have to be available in the module repository otherwise an AxisFault will be thrown.
+     *
+     * @param axisService  the service to configure
+     * @param service_file the service.xm document to configure the service with
+     * @throws IOException
+     * @throws XMLStreamException
+     * @throws org.apache.axis2.AxisFault if a module listed in the service.xml is not available in the module repository
+     */
+    public static void configureService(ConfigurationContext configCtx, AxisService axisService, URL service_file) throws IOException, XMLStreamException, AxisFault {
+        InputStream ais = service_file.openStream();
+        log.debug("Looking for Axis2 service configuration file: " + service_file);
+        if (ais != null) {
+            log.debug("Configuring service " + axisService.getName() + " using: " + service_file);
+            try {
+                if (configCtx == null)
+                    configCtx = new ConfigurationContext(axisService.getAxisConfiguration());
+                ServiceBuilder builder = new ServiceBuilder(ais, configCtx, axisService);
+                builder.populateService(builder.buildOM());
+            } finally {
+                ais.close();
+            }
+            // the service builder only updates the module list but do not engage them
+            // modules have to be engaged manually,
+            for (int i = 0; i < axisService.getModules().size(); i++) {
+                String moduleRef = (String) axisService.getModules().get(i);
+                AxisModule module = axisService.getAxisConfiguration().getModule(moduleRef);
+                if (module != null) {
+                    axisService.engageModule(module);
+                } else {
+                    throw new AxisFault("Unable to engage module: " + moduleRef);
+                }
+            }
+        }
+    }
+}