axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntha...@apache.org
Subject svn commit: r528246 - in /webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2: jaxws/i18n/ jaxws/util/ metadata/ metadata/factory/ metadata/registry/ metadata/resource/ metadata/resource/impl/
Date Thu, 12 Apr 2007 21:49:32 GMT
Author: nthaker
Date: Thu Apr 12 14:49:31 2007
New Revision: 528246

URL: http://svn.apache.org/viewvc?view=rev&rev=528246
Log:
AXIS2-2521

Added:
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/ResourceFinderFactory.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/MetadataFactoryRegistry.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/ResourceFinder.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/ResourceFinderImpl.java
Modified:
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=528246&r1=528245&r2=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
(original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
Thu Apr 12 14:49:31 2007
@@ -128,6 +128,7 @@
 JAXBBlockFactoryErr1=An internal assertion error occurred. The context parameter of the JAXBBlockFactory.createFrom
method should be a JAXBBlockContext object, but a {0} object was found.
 JAXBBlockFactoryErr2=An internal assertion error occurred. The business object parameter
of JAXBBlockFactory.createFrom method should be a JAXBElement object or an object with an
@XmlRootElement annotation, but a {0} object was found.
 JAXBBlockFactoryErr3=An internal assertion error occurred. The qName parameter of JAXBBlockFactory.createFrom
method should not be null.
+WSDL4JWrapperErr1=Unable to read wsdl from relative path.
 WebServiceContextInjectionImplErr1=A null service instance cannot be injected into the resource.
 WebServiceContextInjectionImplErr2=The injection of private and protected set methods are
not supported.
 WebServiceContextInjectionImplErr3=A null service instance cannot be injected into the webservices
context.

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java?view=diff&rev=528246&r1=528245&r2=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java
(original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/WSDL4JWrapper.java
Thu Apr 12 14:49:31 2007
@@ -19,6 +19,10 @@
 
 import org.apache.axis2.java.security.AccessController;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.metadata.factory.ResourceFinderFactory;
+import org.apache.axis2.metadata.registry.MetadataFactoryRegistry;
+import org.apache.axis2.metadata.resource.ResourceFinder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -38,10 +42,12 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.ConnectException;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLConnection;
 import java.net.UnknownHostException;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
@@ -61,13 +67,28 @@
     public WSDL4JWrapper(URL wsdlURL) throws FileNotFoundException, UnknownHostException,
             ConnectException, IOException, WSDLException {
         super();
+        if(log.isDebugEnabled()) {
+            log.debug("Looking for wsdl file on client: " + (wsdlURL != null ? 
+                    wsdlURL.getPath():null));
+        }
+        ClassLoader classLoader = (ClassLoader) AccessController.doPrivileged(
+                new PrivilegedAction() {
+                    public Object run() {
+                        return Thread.currentThread().getContextClassLoader();
+                    }
+                });
         this.wsdlURL = wsdlURL;
         try {
             URL url = wsdlURL;
+            String filePath = null;
             boolean isFileProtocol =
                     (url != null && "file".equals(url.getProtocol())) ? true : false;
             if (isFileProtocol) {
-                String filePath = (url != null) ? url.getPath() : null;
+                filePath = (url != null) ? url.getPath() : null;
+                URI uri = null;
+                if(url != null) {
+                    uri = url.toURI();
+                }
                 //Check is the uri has relative path i.e path is not absolute and is not
starting with a "/"
                 boolean isRelativePath =
                         (filePath != null && !new File(filePath).isAbsolute()) ?
true : false;
@@ -75,19 +96,9 @@
                     if (log.isDebugEnabled()) {
                         log.debug("WSDL URL has a relative path");
                     }
-                    ClassLoader loader = Thread.currentThread().getContextClassLoader();
                     //Lets read the complete WSDL URL for relative path from class loader
                     //Use relative path of url to fetch complete URL.
-                    url = loader.getResource(filePath);
-                    if (url == null) {
-                        //Let see if we can get this resource from a jar file. This code
is only relevant in case of a 
-                        //thin client scenario where client has chose to put wsdl inside
a jar and provided a relative
-                        //path.
-                        if (loader instanceof URLClassLoader) {
-                            URLClassLoader urlLoader = (URLClassLoader)loader;
-                            url = getURLFromJAR(urlLoader, wsdlURL);
-                        }
-                    }
+                    url = getAbsoluteURL(classLoader, filePath);
                     if (url == null) {
                         if (log.isDebugEnabled()) {
                             log.debug("WSDL URL for relative path not found in ClassLoader");
@@ -99,12 +110,51 @@
                         }
                         url = wsdlURL;
                     }
+                    else {
+                        if(log.isDebugEnabled()) {
+                            log.debug("WSDL URL found for relative path: " + filePath + "
scheme: " +
+                                    uri.getScheme());
+                        }
+                    }
                 }
             }
 
             URLConnection urlCon = url.openConnection();
-            InputStream is = urlCon.getInputStream();
-            is.close();
+            InputStream is = null;
+            try {
+                is = urlCon.getInputStream();
+            }
+            catch(IOException e) {
+                if(log.isDebugEnabled()) {
+                    log.debug("Could not open url connection. Trying to use " +
+                    "classloader to get another URL.");
+                }
+                if(filePath != null) {
+                    url = getAbsoluteURL(classLoader, filePath);
+                    if(url == null) {
+                        if(log.isDebugEnabled()) {
+                            log.debug("Could not locate URL for wsdl. Reporting error");
+                        }
+                            throw new WSDLException("WSDL4JWrapper : ", e.getMessage(), e);
+                        }
+                    else {
+                        urlCon = url.openConnection();
+                        if(log.isDebugEnabled()) {
+                             log.debug("Found URL for WSDL from jar");
+                        }
+                    }
+                }
+                else {
+                    if(log.isDebugEnabled()) {
+                        log.debug("Could not get URL from classloader. Reporting " +
+                        "error due to no file path.");
+                    }
+                    throw new WSDLException("WSDL4JWrapper : ", e.getMessage(), e);
+                }
+            }
+            if(is != null) {
+                is.close();
+            }
             final String explicitWsdl = urlCon.getURL().toString();
             try {
                 wsdlDefinition = (Definition)AccessController.doPrivileged(
@@ -135,9 +185,32 @@
         }
     }
 
+    private URL getAbsoluteURL(ClassLoader classLoader, String filePath){
+    	URL url = classLoader.getResource(filePath);
+    	if(url == null) {
+    		if(log.isDebugEnabled()) {
+    			log.debug("Could not get URL from classloader. Looking in a jar.");
+    		}
+    		if(classLoader instanceof URLClassLoader){
+    			URLClassLoader urlLoader = (URLClassLoader)classLoader;
+    			url = getURLFromJAR(urlLoader, wsdlURL);
+    		}
+    	}
+    	return url;    
+    }
     private URL getURLFromJAR(URLClassLoader urlLoader, URL relativeURL) {
 
-        URL[] urlList = urlLoader.getURLs();
+    	URL[] urlList = null;
+    	ResourceFinderFactory rff =(ResourceFinderFactory)MetadataFactoryRegistry.getFactory(ResourceFinderFactory.class);
+    	ResourceFinder cf = rff.getResourceFinder();
+    	urlList = cf.getURLs(urlLoader);
+    	if(urlList == null){
+    		if(log.isDebugEnabled()){
+    			log.debug("No URL's found in URL ClassLoader");
+    		}
+    		ExceptionFactory.makeWebServiceException(Messages.getMessage("WSDL4JWrapperErr1"));
+
+    	}
 
         for (URL url : urlList) {
             if ("file".equals(url.getProtocol())) {

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/ResourceFinderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/ResourceFinderFactory.java?view=auto&rev=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/ResourceFinderFactory.java
(added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/factory/ResourceFinderFactory.java
Thu Apr 12 14:49:31 2007
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.metadata.factory;
+
+import org.apache.axis2.metadata.resource.ResourceFinder;
+import org.apache.axis2.metadata.resource.impl.ResourceFinderImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ResourceFinderFactory {
+    
+    private static final Log log = LogFactory.getLog(ResourceFinderFactory.class);
+
+        private ResourceFinder finder = null;
+
+        public ResourceFinder getResourceFinder() {
+                if (finder != null) {
+                        return finder;
+                }
+                return new ResourceFinderImpl();
+        }
+
+        public void setResourceFinder(ResourceFinder finder) {
+                if(this.finder == null) {
+                        this.finder = finder;
+                }
+        }
+
+}

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/MetadataFactoryRegistry.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/MetadataFactoryRegistry.java?view=auto&rev=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/MetadataFactoryRegistry.java
(added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/registry/MetadataFactoryRegistry.java
Thu Apr 12 14:49:31 2007
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.metadata.registry;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.axis2.metadata.factory.ResourceFinderFactory;
+
+public class MetadataFactoryRegistry {
+    private final static Map<Class,Object> table;
+        static {
+                table = new Hashtable<Class,Object>();
+                table.put(ResourceFinderFactory.class, new ResourceFinderFactory());
+        }
+        
+        /**
+         * FactoryRegistry is currently a static singleton
+         */
+        private MetadataFactoryRegistry() {
+        }
+        
+        /**
+         * getFactory
+         * @param intface of the Factory
+         * @return Object that is the factory implementation for the intface
+         */
+        public static Object getFactory(Class intface) {
+                return table.get(intface);
+        }
+        
+        /**
+         * setFactory
+         * @param intface
+         * @param factoryObject
+         */
+        public static void setFactory(Class intface, Object factoryObject){
+                table.put(intface, factoryObject);
+        }
+
+}

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/ResourceFinder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/ResourceFinder.java?view=auto&rev=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/ResourceFinder.java
(added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/ResourceFinder.java
Thu Apr 12 14:49:31 2007
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.metadata.resource;
+
+import java.net.URL;
+
+/*
+ * ResourceFinder will be used to find Resources from a classloader. 
+ * for example a ResourceFinder can be used to get all the resources as url from classloader
+ * or it can be used to find a class in classpath from Classloader. 
+ */
+
+public interface ResourceFinder {
+    
+    /**
+     * This method reads all the resource URLs available to this classLoader.
+     * @param cl
+     * @return
+     */
+    URL[] getURLs(ClassLoader cl);
+
+}

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/ResourceFinderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/ResourceFinderImpl.java?view=auto&rev=528246
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/ResourceFinderImpl.java
(added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/metadata/resource/impl/ResourceFinderImpl.java
Thu Apr 12 14:49:31 2007
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.metadata.resource.impl;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.apache.axis2.metadata.resource.ResourceFinder;
+
+
+public class ResourceFinderImpl implements ResourceFinder {
+
+    /* (non-Javadoc)
+     * @see org.apache.axis2.metadata.resource.ResourceFinder#getURLs(java.lang.ClassLoader)
+     */
+    public URL[] getURLs(ClassLoader cl) {
+        if(cl instanceof URLClassLoader){
+            URLClassLoader urlLoader = (URLClassLoader)cl;
+            return urlLoader.getURLs();
+        }
+         return null;
+    }
+
+}



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


Mime
View raw message