geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1133244 - in /geronimo/server/trunk/plugins/webservices/geronimo-webservices: ./ src/main/java/org/apache/geronimo/webservices/saaj/ src/main/resources/META-INF/services/
Date Wed, 08 Jun 2011 04:25:12 GMT
Author: xuhaihong
Date: Wed Jun  8 04:25:11 2011
New Revision: 1133244

URL: http://svn.apache.org/viewvc?rev=1133244&view=rev
Log:
Use the registry to locate the expected SAAJ provider

Added:
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MessageFactory
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MetaFactory
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPConnectionFactory
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPFactory
Modified:
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/pom.xml
    geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJFactoryFinder.java

Modified: geronimo/server/trunk/plugins/webservices/geronimo-webservices/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/pom.xml?rev=1133244&r1=1133243&r2=1133244&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/pom.xml (original)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/pom.xml Wed Jun  8 04:25:11
2011
@@ -113,6 +113,11 @@
             <artifactId>pax-logging-api</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-osgi-registry</artifactId>
+        </dependency>
+
         <!-- Use org.apache.geronimo.javamail/geronimo-javamail_1.4_mail
           uber jar containing both the spec and the providers in order that
           users can actually use mail without advanced degrees in geronimo
@@ -140,6 +145,7 @@
                             org.apache.geronimo.javamail.handlers,
                             *
                         </Import-Package>
+                        <SPI-Provider>true</SPI-Provider>
                     </instructions>
                 </configuration>
             </plugin>

Modified: geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJFactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJFactoryFinder.java?rev=1133244&r1=1133243&r2=1133244&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJFactoryFinder.java
(original)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/saaj/SAAJFactoryFinder.java
Wed Jun  8 04:25:11 2011
@@ -16,29 +16,34 @@
  */
 package org.apache.geronimo.webservices.saaj;
 
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.soap.SOAPException;
 
+import org.apache.geronimo.osgi.registry.api.ProviderRegistry;
+import org.apache.xbean.osgi.bundle.util.BundleUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 class SAAJFactoryFinder {
-    
+
     private static final Logger LOG = LoggerFactory.getLogger(SAAJFactoryFinder.class);
-    
-    private static final String SAAJ_PROVIDER_PROPERTY = 
-        "org.apache.geronimo.saaj.provider";
-       
-    private static final Map<String, Map<String,String>> SAAJ_FACTORIES = 
-        new HashMap<String, Map<String, String>>();
-    
+
+    private static final String SAAJ_PROVIDER_PROPERTY = "org.apache.geronimo.saaj.provider";
+
+    private static final Map<String, Map<String, String>> SAAJ_FACTORIES = new
HashMap<String, Map<String, String>>();
+
     private static SAAJUniverse.Type DEFAULT_SAAJ_UNIVERSE = null;
-                                                     
+
     static {
-        SAAJ_FACTORIES.put(SAAJUniverse.Type.AXIS1.toString(), 
-                           createSAAJInfo("org.apache.axis.soap.MessageFactoryImpl", 
+        SAAJ_FACTORIES.put(SAAJUniverse.Type.AXIS1.toString(),
+                           createSAAJInfo("org.apache.axis.soap.MessageFactoryImpl",
                                           "org.apache.axis.soap.SOAPFactoryImpl",
                                           "org.apache.axis.soap.SOAPConnectionFactoryImpl",
                                           "org.apache.axis.soap.SAAJMetaFactoryImpl"));
@@ -48,14 +53,14 @@ class SAAJFactoryFinder {
                                           "org.apache.axis2.saaj.SOAPConnectionFactoryImpl",
                                           "org.apache.axis2.saaj.SAAJMetaFactoryImpl"));
         SAAJ_FACTORIES.put(SAAJUniverse.Type.SUN.toString(),
-                           createSAAJInfo("com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl",

+                           createSAAJInfo("com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl",
                                           "com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl",
-                                          "com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory",

+                                          "com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory",
                                           "com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl"));
-        
-        initDefaultSAAJProvider();      
+
+        initDefaultSAAJProvider();
     }
-    
+
     private static void initDefaultSAAJProvider() {
         String provider = System.getProperty(SAAJ_PROVIDER_PROPERTY);
         if (provider != null) {
@@ -66,13 +71,13 @@ class SAAJFactoryFinder {
             } else {
                 throw new RuntimeException("Invalid SAAJ universe specified: " + provider);
             }
-            
+
             LOG.info("Default SAAJ universe: " + DEFAULT_SAAJ_UNIVERSE);
         } else {
             LOG.info("Default SAAJ universe not set");
         }
     }
-    
+
     private static Map<String, String> createSAAJInfo(String messageFactory,
                                                       String soapFactory,
                                                       String soapConnectionFactory,
@@ -84,25 +89,23 @@ class SAAJFactoryFinder {
         map.put("javax.xml.soap.MetaFactory", metaFactory);
         return map;
     }
-    
+
     static Object find(String factoryPropertyName) throws SOAPException {
         String factoryClassName = getFactoryClass(factoryPropertyName);
         if (factoryClassName == null) {
-            throw new SOAPException(
-                    "Provider for " + factoryPropertyName + " cannot be found",
-                    null);
+            throw new SOAPException("Provider for " + factoryPropertyName + " cannot be found",
null);
         } else {
-            return newInstance(factoryClassName);
-        }        
+            return newInstance(factoryPropertyName, factoryClassName);
+        }
     }
-    
+
     private static String getFactoryClass(String factoryName) {
         SAAJUniverse.Type universe = SAAJUniverse.getCurrentUniverse();
-        if (universe == null || universe == SAAJUniverse.Type.DEFAULT) {            
+        if (universe == null || universe == SAAJUniverse.Type.DEFAULT) {
             if (DEFAULT_SAAJ_UNIVERSE == null) {
-                // Default SAAJ universe not set. 
+                // Default SAAJ universe not set.
                 // Prefer Axis2 SAAJ if it is in class loader, otherwise use Sun's
-                if (isAxis2InClassLoader()) {
+                if (isAxis2Available()) {
                     universe = SAAJUniverse.Type.AXIS2;
                 } else {
                     universe = SAAJUniverse.Type.SUN;
@@ -112,43 +115,78 @@ class SAAJFactoryFinder {
                 universe = DEFAULT_SAAJ_UNIVERSE;
             }
         }
-        
+
         return SAAJ_FACTORIES.get(universe.toString()).get(factoryName);
     }
-    
-    private static boolean isAxis2InClassLoader() {
+
+    private static boolean isAxis2Available() {
         try {
-            loadClass("org.apache.axis2.saaj.MessageFactoryImpl");
+            loadClass("javax.xml.soap.MessageFactory", "org.apache.axis2.saaj.MessageFactoryImpl");
             return true;
         } catch (ClassNotFoundException e) {
             return false;
         }
     }
-    
-    private static Class loadClass(String className) throws ClassNotFoundException {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();       

-        if (classLoader == null) {
-            return Class.forName(className);
-        } else {
-            return classLoader.loadClass(className);
+
+    private static Class<?> loadClass(String providerId, String className) throws ClassNotFoundException
{
+        //1. Use the traditional classLoader search strategy
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            if (classLoader != null) {
+                return classLoader.loadClass(className);
+            }
+        } catch (ClassNotFoundException e) {
+            try {
+                return Class.forName(className);
+            } catch (ClassNotFoundException e1) {
+            }
         }
+        //2. Use the bundle search strategy
+        List<Class<?>> serviceClasses = getServiceClasses(providerId);
+        for (Class<?> cls : serviceClasses) {
+            if (cls.getName().equals(className)) {
+                return cls;
+            }
+        }
+        throw new ClassNotFoundException("class " + className + " could not be founded in
both classpath and bundle registry");
     }
-    
-    private static Object newInstance(String factoryClassName) throws SOAPException {
+
+    private static List<Class<?>> getServiceClasses(String providerid) {
+        Bundle bundle = BundleUtils.getContextBundle(true);
+        if (bundle == null || bundle.getBundleContext() == null) {
+            bundle = BundleUtils.getBundle(SAAJFactoryFinder.class.getClassLoader(), true);
+        }
+        if (bundle == null || bundle.getBundleContext() == null) {
+            return Collections.<Class<?>>emptyList();
+        }
+        BundleContext bundleContext = bundle.getBundleContext();
+        ServiceReference serviceReference = null;
         try {
-            Class factory = null;
-            try {
-                factory = loadClass(factoryClassName);
-            } catch (ClassNotFoundException cnfe) {
-                factory = SAAJFactoryFinder.class.getClassLoader().loadClass(factoryClassName);
+            serviceReference = bundleContext.getServiceReference("org.apache.geronimo.osgi.registry.api.ProviderRegistry");
+            if (serviceReference != null) {
+                ProviderRegistry registry = (ProviderRegistry) bundleContext.getService(serviceReference);
+                return registry.getServiceClasses(providerid);
+            }
+            return Collections.<Class<?>>emptyList();
+        } finally {
+            if (serviceReference != null) {
+                try {
+                    bundleContext.ungetService(serviceReference);
+                } catch (Exception e) {
+                }
             }
+        }
+
+    }
+
+    private static Object newInstance(String providerId, String factoryClassName) throws
SOAPException {
+        try {
+            Class<?> factory = loadClass(providerId, factoryClassName);
             return factory.newInstance();
         } catch (ClassNotFoundException e) {
-            throw new SOAPException("Provider " + factoryClassName + " not found", e);
+            throw new SOAPException(e);
         } catch (Exception e) {
-            throw new SOAPException("Provider " + factoryClassName + " could not be instantiated:
"
-                                    + e.getMessage(), e);
+            throw new SOAPException("Provider " + factoryClassName + " could not be instantiated:
" + e.getMessage(), e);
         }
     }
-    
 }

Added: geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MessageFactory
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MessageFactory?rev=1133244&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MessageFactory
(added)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MessageFactory
Wed Jun  8 04:25:11 2011
@@ -0,0 +1,19 @@
+##
+## 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.
+##
+## $Rev$ $Date$
+##
+org.apache.geronimo.webservices.saaj.GeronimoMessageFactory
\ No newline at end of file

Added: geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MetaFactory
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MetaFactory?rev=1133244&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MetaFactory
(added)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.MetaFactory
Wed Jun  8 04:25:11 2011
@@ -0,0 +1,19 @@
+##
+## 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.
+##
+## $Rev$ $Date$
+##
+org.apache.geronimo.webservices.saaj.GeronimoMetaFactory
\ No newline at end of file

Added: geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPConnectionFactory
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPConnectionFactory?rev=1133244&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPConnectionFactory
(added)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPConnectionFactory
Wed Jun  8 04:25:11 2011
@@ -0,0 +1,19 @@
+##
+## 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.
+##
+## $Rev$ $Date$
+##
+org.apache.geronimo.webservices.saaj.GeronimoSOAPConnectionFactory
\ No newline at end of file

Added: geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPFactory
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPFactory?rev=1133244&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPFactory
(added)
+++ geronimo/server/trunk/plugins/webservices/geronimo-webservices/src/main/resources/META-INF/services/javax.xml.soap.SOAPFactory
Wed Jun  8 04:25:11 2011
@@ -0,0 +1,19 @@
+##
+## 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.
+##
+## $Rev$ $Date$
+##
+org.apache.geronimo.webservices.saaj.GeronimoSOAPFactory
\ No newline at end of file



Mime
View raw message