tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r801351 - in /tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2: Axis2ConfiguratorHelper.java Axis2ServiceClient.java Axis2ServiceProvider.java TuscanyAxisConfigurator.java
Date Wed, 05 Aug 2009 18:32:57 GMT
Author: rfeng
Date: Wed Aug  5 18:32:56 2009
New Revision: 801351

URL: http://svn.apache.org/viewvc?rev=801351&view=rev
Log:
Set the thread context classloader so that Axis2 configuration can be loaded 

Added:
    tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
  (with props)
Modified:
    tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java
    tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
    tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java

Added: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java?rev=801351&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
(added)
+++ tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
Wed Aug  5 18:32:56 2009
@@ -0,0 +1,154 @@
+/*
+ * 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.tuscany.sca.binding.ws.axis2;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.URLBasedAxisConfigurator;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * The Helper class that loades the Axis2 configuration from the axis2.xml
+ */
+public class Axis2ConfiguratorHelper {
+
+    /**
+     * This classloader is used in OSGi to work around XXXFactory.newInstance()
+     */
+    static class MultiParentClassLoader extends ClassLoader {
+        private final Collection<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
+    
+        /**
+         * @param parent The parent classloaders
+         * @param loaders A list of classloaders to be used to load classes or resources
+         */
+        public MultiParentClassLoader(ClassLoader parent, ClassLoader[] loaders) {
+            super(parent);
+            if (loaders != null) {
+                for (ClassLoader cl : loaders) {
+                    if (cl != null && cl != parent && !classLoaders.contains(cl))
{
+                        this.classLoaders.add(cl);
+                    }
+                }
+            }
+        }
+    
+        @Override
+        protected Class<?> findClass(String className) throws ClassNotFoundException
{
+            for (ClassLoader parent : classLoaders) {
+                try {
+                    return parent.loadClass(className);
+                } catch (ClassNotFoundException e) {
+                    continue;
+                }
+            }
+            throw new ClassNotFoundException(className);
+        }
+    
+        @Override
+        protected URL findResource(String resName) {
+            for (ClassLoader parent : classLoaders) {
+                URL url = parent.getResource(resName);
+                if (url != null) {
+                    return url;
+                }
+            }
+            return null;
+        }
+    
+        @Override
+        protected Enumeration<URL> findResources(String resName) throws IOException
{
+            Set<URL> urlSet = new HashSet<URL>();
+            for (ClassLoader parent : classLoaders) {
+                Enumeration<URL> urls = parent.getResources(resName);
+                if (urls != null) {
+                    while (urls.hasMoreElements()) {
+                        urlSet.add(urls.nextElement());
+                    }
+                }
+            }
+            return Collections.enumeration(urlSet);
+        }
+    }
+
+    
+    /**
+     * We cannot hold this method directly in the {@link TuscanyAxisConfigurator} class as
the super class
+     * uses the TCCL to load classes
+     * 
+     * @param isRampartRequired
+     * @return
+     */
+    public static ConfigurationContext getAxis2ConfigurationContext(final boolean isRampartRequired)
{
+        try {
+            // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+            // Allow privileged access to read properties. Requires PropertyPermission read
in
+            // security policy.
+            ConfigurationContext configContext =
+                AccessController.doPrivileged(new PrivilegedExceptionAction<ConfigurationContext>()
{
+                    public ConfigurationContext run() throws AxisFault {
+                        // The tuscany-binding-ws-axis2 class loader. We contribute the message
+                        // receivers in the axis2.xml
+                        ClassLoader cl0 = getClass().getClassLoader();
+                        
+                        // The axis2 class loader
+                        ClassLoader cl1 = URLBasedAxisConfigurator.class.getClassLoader();
+                        
+                        // The extensibility class loader that sees all 3rd party jars
+                        ClassLoader cl2 = ServiceDiscovery.getInstance().getContextClassLoader();
+                        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+                        ClassLoader newTccl = tccl;
+                        if (cl0 != tccl || cl1 != tccl || cl2 != tccl) {
+                            newTccl = new MultiParentClassLoader(null, new ClassLoader[]
{cl0, cl1, cl2, tccl});
+                        }
+                        if (newTccl != null && newTccl != tccl) {
+                            Thread.currentThread().setContextClassLoader(newTccl);
+                        }
+                        try {
+                            return new TuscanyAxisConfigurator(isRampartRequired).getConfigurationContext();
+                        } finally {
+                            if (newTccl != null && newTccl != tccl) {
+                                Thread.currentThread().setContextClassLoader(tccl);
+                            }
+                        }
+                    }
+                });
+            return configContext;
+            // deployRampartModule();
+            // configureSecurity();
+        } catch (PrivilegedActionException e) {
+            throw new ServiceRuntimeException(e.getException());
+        }
+    }
+
+}

Propchange: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ConfiguratorHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java?rev=801351&r1=801350&r2=801351&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java
(original)
+++ tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java
Wed Aug  5 18:32:56 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.sca.binding.ws.axis2;
 
+import static org.apache.tuscany.sca.binding.ws.axis2.Axis2ConfiguratorHelper.getAxis2ConfigurationContext;
 import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.SOAP12_INTENT;
 import static org.apache.tuscany.sca.binding.ws.axis2.AxisPolicyHelper.isIntentRequired;
 
@@ -77,7 +78,6 @@
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.xsd.xml.XMLDocumentHelper;
 import org.apache.ws.commons.schema.resolver.URIResolver;
-import org.oasisopen.sca.ServiceRuntimeException;
 
 public class Axis2ServiceClient {
 
@@ -126,31 +126,10 @@
      * Create an Axis2 ServiceClient
      */
     protected ServiceClient createServiceClient() {
-    	ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-    	ClassLoader axiscl = this.getClass().getClassLoader();
-
-    	try {
-    		if( axiscl != tccl ) Thread.currentThread().setContextClassLoader(axiscl);
-    		
+        try {
             final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding);
-            ConfigurationContext configContext;
-            
-            try {
-                // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
-                // Allow privileged access to read properties. Requires PropertyPermission
read in
-                // security policy.
-                TuscanyAxisConfigurator tuscanyAxisConfigurator =
-                    AccessController.doPrivileged(new PrivilegedExceptionAction<TuscanyAxisConfigurator>()
{
-                        public TuscanyAxisConfigurator run() throws AxisFault {
-                            return new TuscanyAxisConfigurator(isRampartRequired);
-                        }
-                    });
-                configContext = tuscanyAxisConfigurator.getConfigurationContext();
-                // deployRampartModule();
-                // configureSecurity();
-            } catch (PrivilegedActionException e) {
-                throw new ServiceRuntimeException(e.getException());
-            } // end try
+            ConfigurationContext configContext =
+                getAxis2ConfigurationContext(isRampartRequired);
 
             createPolicyHandlers();
 
@@ -176,7 +155,7 @@
                         }
                     }
                 }
-            } // end if
+            }
             AxisService axisService =
                 createClientSideAxisService(definition, serviceQName, port.getName(), new
Options());
 
@@ -193,7 +172,7 @@
                 configContext.setThreadPool(new ThreadPool(1, 5));
                 configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE);
                 configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
-            } // end if
+            }
 
             return new ServiceClient(configContext, axisService);
 
@@ -205,11 +184,8 @@
             throw new RuntimeException(e);
         } catch (IllegalAccessException e) {
             throw new RuntimeException(e);
-        } finally {
-        	// Restore the Thread Context ClassLoader...
-    		if( axiscl != tccl ) Thread.currentThread().setContextClassLoader(tccl);
-        } // end try
-    } // end method createServiceClient
+        }
+    }
 
     /**
      * URI resolver implementation for XML schema

Modified: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java?rev=801351&r1=801350&r2=801351&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
(original)
+++ tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
Wed Aug  5 18:32:56 2009
@@ -19,25 +19,20 @@
 
 package org.apache.tuscany.sca.binding.ws.axis2;
 
-import java.io.IOException;
+import static org.apache.tuscany.sca.binding.ws.axis2.Axis2ConfiguratorHelper.getAxis2ConfigurationContext;
+
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -61,7 +56,6 @@
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.deployment.URLBasedAxisConfigurator;
 import org.apache.axis2.deployment.util.Utils;
 import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.description.AxisOperation;
@@ -93,7 +87,6 @@
 import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString;
 import org.apache.tuscany.sca.core.FactoryExtensionPoint;
 import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
-import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
 import org.apache.tuscany.sca.host.http.ServletHost;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -113,7 +106,6 @@
 import org.apache.ws.security.WSSecurityEngineResult;
 import org.apache.ws.security.handler.WSHandlerConstants;
 import org.apache.ws.security.handler.WSHandlerResult;
-import org.oasisopen.sca.ServiceRuntimeException;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -167,65 +159,6 @@
     public static final List<QName> XSD_QNAME_LIST =
         Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001});
 
-    /**
-     * This classloader is used in OSGi to work around XXXFactory.newInstance()
-     */
-    private static class MultiParentClassLoader extends ClassLoader {
-        private final Collection<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
-
-        /**
-         * @param parent The parent classloaders
-         * @param loaders A list of classloaders to be used to load classes or resources
-         */
-        public MultiParentClassLoader(ClassLoader parent, ClassLoader[] loaders) {
-            super(parent);
-            if (loaders != null) {
-                for (ClassLoader cl : loaders) {
-                    if (cl != null && cl != parent && !classLoaders.contains(cl))
{
-                        this.classLoaders.add(cl);
-                    }
-                }
-            }
-        }
-
-        @Override
-        protected Class<?> findClass(String className) throws ClassNotFoundException
{
-            for (ClassLoader parent : classLoaders) {
-                try {
-                    return parent.loadClass(className);
-                } catch (ClassNotFoundException e) {
-                    continue;
-                }
-            }
-            throw new ClassNotFoundException(className);
-        }
-
-        @Override
-        protected URL findResource(String resName) {
-            for (ClassLoader parent : classLoaders) {
-                URL url = parent.getResource(resName);
-                if (url != null) {
-                    return url;
-                }
-            }
-            return null;
-        }
-
-        @Override
-        protected Enumeration<URL> findResources(String resName) throws IOException
{
-            Set<URL> urlSet = new HashSet<URL>();
-            for (ClassLoader parent : classLoaders) {
-                Enumeration<URL> urls = parent.getResources(resName);
-                if (urls != null) {
-                    while (urls.hasMoreElements()) {
-                        urlSet.add(urls.nextElement());
-                    }
-                }
-            }
-            return Collections.enumeration(urlSet);
-        }
-    }
-
     public Axis2ServiceProvider(RuntimeComponent component,
                                 AbstractContract contract,
                                 WebServiceBinding wsBinding,
@@ -242,39 +175,7 @@
         this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
 
         final boolean isRampartRequired = AxisPolicyHelper.isRampartRequired(wsBinding);
-        try {
-            // TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
-            // Allow privileged access to read properties. Requires PropertyPermission read
in
-            // security policy.
-            configContext = AccessController.doPrivileged(new PrivilegedExceptionAction<ConfigurationContext>()
{
-                public ConfigurationContext run() throws AxisFault {
-                    ClassLoader cl0 = getClass().getClassLoader();
-                    ClassLoader cl1 = URLBasedAxisConfigurator.class.getClassLoader();
-                    ClassLoader cl2 = ServiceDiscovery.getInstance().getContextClassLoader();
-//                    ClassLoader cl3 =
-//                        modelFactories.getFactory(DocumentBuilderFactory.class).getClass().getClassLoader();
-                    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-                    ClassLoader newTccl = tccl;
-                    if (cl0 != tccl || cl1 != tccl || cl2 != tccl) {
-                        newTccl = new MultiParentClassLoader(null, new ClassLoader[] {cl0,
cl1, cl2, tccl});
-                    }
-                    if (newTccl != null && newTccl != tccl) {
-                        Thread.currentThread().setContextClassLoader(newTccl);
-                    }
-                    try {
-                        return new TuscanyAxisConfigurator(isRampartRequired).getConfigurationContext();
-                    } finally {
-                        if (newTccl != null && newTccl != tccl) {
-                            Thread.currentThread().setContextClassLoader(tccl);
-                        }
-                    }
-                }
-            });
-            // deployRampartModule();
-            // configureSecurity();
-        } catch (PrivilegedActionException e) {
-            throw new ServiceRuntimeException(e.getException());
-        }
+        configContext = getAxis2ConfigurationContext(isRampartRequired);
 
         configContext.setContextRoot(servletHost.getContextPath());
 

Modified: tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java?rev=801351&r1=801350&r2=801351&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java
(original)
+++ tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java
Wed Aug  5 18:32:56 2009
@@ -26,8 +26,14 @@
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
@@ -43,6 +49,8 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisConfigurator;
 import org.apache.axis2.i18n.Messages;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.oasisopen.sca.ServiceRuntimeException;
 
 /**
  * Helps configure Axis2 from a resource in binding.ws.axis2 instead of Axis2.xml 
@@ -324,7 +332,5 @@
             throw new DeploymentException(e);
         }
     }
-    
-    /************** end of fix *************************************************************/
 
 }



Mime
View raw message