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 ba...@apache.org on 2009/02/19 18:00:11 UTC

svn commit: r745925 - in /webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws: catalog/impl/OASISCatalogManager.java description/impl/ServiceDescriptionImpl.java description/impl/URIResolverImpl.java util/CatalogURIResolver.java

Author: barrettj
Date: Thu Feb 19 17:00:10 2009
New Revision: 745925

URL: http://svn.apache.org/viewvc?rev=745925&view=rev
Log:
AXIS2-4158
Patch contributed by Lori VanGulick.  CatalogURIResolver should use a catalog if one is available.

Modified:
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/catalog/impl/OASISCatalogManager.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/URIResolverImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/CatalogURIResolver.java

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/catalog/impl/OASISCatalogManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/catalog/impl/OASISCatalogManager.java?rev=745925&r1=745924&r2=745925&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/catalog/impl/OASISCatalogManager.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/catalog/impl/OASISCatalogManager.java Thu Feb 19 17:00:10 2009
@@ -74,8 +74,15 @@
      * @param classLoader
      */
     public OASISCatalogManager(ClassLoader classLoader) {
-        this();
+    	super();
+    	this.acceptDefaults();
+    	if (DEBUG_LEVEL != null) {
+    		this.debug.setDebug(Integer.parseInt(DEBUG_LEVEL)); 
+    	}
+        // need to set classloader before calling determineFileName
         this.classloader = classLoader;
+        this.setDeterminedCatalogFiles();
+
     }
     
     /**
@@ -99,12 +106,7 @@
     	if (DEBUG_LEVEL != null) {
     		this.debug.setDebug(Integer.parseInt(DEBUG_LEVEL)); 
     	}
-    	
-    	String filepath = determineFileName();
-    
-        if (filepath != null) {
-            this.setCatalogFiles(filepath);
-        }
+    	setDeterminedCatalogFiles();
     }
 
     
@@ -119,6 +121,14 @@
         }
     }
     
+    private void setDeterminedCatalogFiles() {    	
+    	String filepath = determineFileName();
+    
+        if (filepath != null) {
+            this.setCatalogFiles(filepath);
+        }
+    }
+    
     private void acceptDefaults() {
     	this.setUseStaticCatalog(true);
     	this.setIgnoreMissingProperties(true);

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java?rev=745925&r1=745924&r2=745925&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java Thu Feb 19 17:00:10 2009
@@ -296,7 +296,12 @@
         this.isServerSide = true;
         this.serviceQName = serviceQName;
         this.catalogManager = this.composite.getCatalogManager();
+        // if the composit doesn't have a catalogManager, get one only if we have a catalog file
+        if (catalogManager == null) {
+            catalogManager = createCatalogManager(composite.getClassLoader());
+        }
         
+
         
         // if the ServiceDescriptionImpl was constructed with a specific service QName
         // we should use that to retrieve the potential list of PortComposite objects
@@ -2648,4 +2653,41 @@
             }
         }
     }
+    /**
+     * create a catalog manager only if a catalog file is found for this classloader.
+     * Also parses the catalog to get it ready for resolution.
+     * @param cl - Classloader of the composite passes to this ServiceDescription
+     * @return a catalogManager with parsed catalog, or null if no catalog found
+     */
+    private JAXWSCatalogManager createCatalogManager(ClassLoader cl) {
+        JAXWSCatalogManager returnCatalogManager = null;
+
+        try {
+            URL catalogURL = cl.getResource(
+                    OASISCatalogManager.DEFAULT_CATALOG_WEB);
+            if (catalogURL == null) {
+                catalogURL = cl.getResource(
+                        OASISCatalogManager.DEFAULT_CATALOG_EJB);
+                if (catalogURL != null) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Found JAX-WS catalog in EJB file");
+                    }
+                    returnCatalogManager = new OASISCatalogManager(cl);
+                    returnCatalogManager.getCatalog().parseCatalog(catalogURL);
+                }
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug("Found JAX-WS catalog in WAR file");
+                }
+                returnCatalogManager = new OASISCatalogManager(cl);
+                returnCatalogManager.getCatalog().parseCatalog(catalogURL);
+            }
+        } catch (Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug("ServiceDescriptionImpl caught exception from parseCatalog ",e);
+            }
+            returnCatalogManager = null;
+        }
+        return (returnCatalogManager);
+    }
 }

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/URIResolverImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/URIResolverImpl.java?rev=745925&r1=745924&r2=745925&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/URIResolverImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/URIResolverImpl.java Thu Feb 19 17:00:10 2009
@@ -51,7 +51,7 @@
     
     private static final String BUNDLE_RESOURCE_PROTOCOL = "bundleresource";
 
-    private ClassLoader classLoader;
+    protected ClassLoader classLoader;
     
     private static final Log log = LogFactory.getLog(URIResolverImpl.class);
 
@@ -203,7 +203,7 @@
      * @param location
      * @return
      */
-    private boolean isAbsolute(String location) {
+    protected boolean isAbsolute(String location) {
         boolean absolute = false;
         if (location.indexOf(":/") != -1) {
             absolute = true;
@@ -222,7 +222,7 @@
      * @param uri
      * @return
      */
-    private InputStream getInputStreamForURI(String uri) {
+    protected InputStream getInputStreamForURI(String uri) {
         URL streamURL = null;
         InputStream is = null;
         URI pathURI = null;
@@ -232,6 +232,9 @@
             is = openStream_doPriv(streamURL);
         } catch (Throwable t) {
             //Exception handling not needed
+            if (log.isDebugEnabled()) {
+                log.debug("Exception occured in getInputStreamForURI, ignoring exception continuing processing: "+t.getMessage());
+            }
         }
 
         if (is == null) {
@@ -241,6 +244,9 @@
                 is = openStream_doPriv(streamURL);
             } catch (Throwable t) {
                 //Exception handling not needed
+                if (log.isDebugEnabled()) {
+                    log.debug("Exception occured in getInputStreamForURI, ignoring exception continuing processing: "+t.getMessage());
+                }
             }
         }
 
@@ -257,6 +263,9 @@
                 is = openStream_doPriv(streamURL);
             } catch (Throwable t) {
                 //Exception handling not needed
+                if (log.isDebugEnabled()) {
+                    log.debug("Exception occured in getInputStreamForURI, ignoring exception continuing processing: "+t.getMessage());
+                }
             }
         }
         return is;

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/CatalogURIResolver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/CatalogURIResolver.java?rev=745925&r1=745924&r2=745925&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/CatalogURIResolver.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/CatalogURIResolver.java Thu Feb 19 17:00:10 2009
@@ -1,113 +1,222 @@
-/*
- * 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.axis2.jaxws.util;
-
-import java.io.IOException;
-
-import org.apache.axis2.jaxws.catalog.JAXWSCatalogManager;
-import org.apache.axis2.jaxws.description.impl.URIResolverImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.xml.resolver.Catalog;
-import org.xml.sax.InputSource;
-
-/**
- * This resolver provides the means of resolving the imports and includes of a
- * given schema document. It allows the use of the Apache Commons Resolver API
- * to redirect resource requests to alternative locations.
- */
-public class CatalogURIResolver extends URIResolverImpl {
-
-    private static Log log = LogFactory.getLog(CatalogWSDLLocator.class);
-    private Catalog catalogResolver;
-    
-    /**
-     * CatalogURIResolver constructor.  Resolves WSDL URIs using Apache Commons Resolver API.
-     * @param catalogManager
-     *            the OASISCatalogManager which will determine the settings for the XML catalog
-     */
-    public CatalogURIResolver(JAXWSCatalogManager catalogManager) {
-        this(catalogManager, null);
-    }
-    
-    /**
-     * CatalogURIResolver constructor.  Resolves WSDL URIs using Apache Commons Resolver API.
-     * @param catalogManager
-     *            the OASISCatalogManager which will determine the settings for the XML catalog
-     * @param classLoader
-     */    
-    public CatalogURIResolver(JAXWSCatalogManager catalogManager, ClassLoader classLoader) {
-        super(classLoader);
-        if (catalogManager != null) {
-            this.catalogResolver = catalogManager.getCatalog();
-        }
-    }
-    
-    /**
-     * Resolves URIs using Apache Commons Resolver API.
-     * 
-     * @param importURI a URI specifying the document to import
-     * @param parent a URI specifying the location of the parent document doing
-     * the importing
-     * @return the resolved import location, or null if no indirection is performed
-     */
-    public String getRedirectedURI(String namespace,
-                                   String schemaLocation,
-                                   String baseUri) {
-        String resolvedImportLocation = null;
-        try {
-            resolvedImportLocation = this.catalogResolver.resolveSystem(namespace);
-            if (resolvedImportLocation == null) {
-                resolvedImportLocation = catalogResolver.resolveURI(schemaLocation);
-            }
-            if (resolvedImportLocation == null) {
-                resolvedImportLocation = catalogResolver.resolvePublic(namespace, namespace);
-            }
-        
-        } catch (IOException e) {
-            throw new RuntimeException("Catalog resolution failed", e);
-        }
-
-        return resolvedImportLocation;
-    }
-    
-    /**
-     * As for the resolver the public ID is the target namespace of the
-     * schema and the schemaLocation is the value of the schema location
-     * @param namespace
-     * @param schemaLocation
-     * @param baseUri
-     */
-    public InputSource resolveEntity(String namespace,
-                                     String schemaLocation,
-                                     String baseUri) {
-        String location = schemaLocation;     
-        
-        if (this.catalogResolver != null) {
-            String redirectedURI = getRedirectedURI(namespace, schemaLocation, baseUri);
-            if (redirectedURI != null) {
-                location = redirectedURI;
-            }
-        }
-        
-        return super.resolveEntity(namespace, location, baseUri);
-    }
-
-}
+/*
+ * 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.axis2.jaxws.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.axis2.jaxws.catalog.JAXWSCatalogManager;
+import org.apache.axis2.jaxws.description.impl.URIResolverImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.xml.resolver.Catalog;
+import org.xml.sax.InputSource;
+
+/**
+ * This resolver provides the means of resolving the imports and includes of a
+ * given schema document. It allows the use of the Apache Commons Resolver API
+ * to redirect resource requests to alternative locations.
+ */
+public class CatalogURIResolver extends URIResolverImpl {
+
+    private static Log log = LogFactory.getLog(CatalogURIResolver.class);
+    private Catalog catalogResolver;
+    
+    /**
+     * CatalogURIResolver constructor.  Resolves WSDL URIs using Apache Commons Resolver API.
+     * @param catalogManager
+     *            the OASISCatalogManager which will determine the settings for the XML catalog
+     */
+    public CatalogURIResolver(JAXWSCatalogManager catalogManager) {
+        this(catalogManager, null);
+    }
+    
+    /**
+     * CatalogURIResolver constructor.  Resolves WSDL URIs using Apache Commons Resolver API.
+     * @param catalogManager
+     *            the OASISCatalogManager which will determine the settings for the XML catalog
+     * @param classLoader
+     */    
+    public CatalogURIResolver(JAXWSCatalogManager catalogManager, ClassLoader classLoader) {
+        super(classLoader);
+        if (log.isDebugEnabled()) {
+            log.debug("init: catalogManager :"+ catalogManager);
+        }
+        if (catalogManager != null) {
+            this.catalogResolver = catalogManager.getCatalog();
+        }
+    }
+    
+    /**
+     * Resolves URIs using Apache Commons Resolver API.
+     * 
+     * @param namespace a URI specifying the namespace of the document 
+     * @param schemaLocation a URI specifying the document to import
+     * @param baseURI a URI specifying the location of the parent document doing
+     * the importing
+     * @return the resolved import location, or null if no indirection is performed
+     */
+    public String getRedirectedURI(String namespace,
+                                   String schemaLocation,
+                                   String baseUri) {
+        String resolvedImportLocation = null;
+        try {
+            resolvedImportLocation = this.catalogResolver.resolveSystem(schemaLocation);
+            if (resolvedImportLocation == null) {
+                resolvedImportLocation = catalogResolver.resolveSystem(namespace);
+            }
+            if (resolvedImportLocation == null) {
+                resolvedImportLocation = catalogResolver.resolveURI(schemaLocation);
+            }
+            if (resolvedImportLocation == null) {
+                resolvedImportLocation = catalogResolver.resolvePublic(namespace, namespace);
+            }
+        
+        } catch (IOException e) {
+            if (log.isDebugEnabled()) {
+                log.debug("getRedirectedURI error: Catalog resolution failed");
+            }
+            throw new RuntimeException("Catalog resolution failed", e);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("getRedirectedURI exit: redirected location: "+ resolvedImportLocation);
+        }
+        return resolvedImportLocation;
+    }
+    
+    /**
+     * As for the resolver the public ID is the target namespace of the
+     * schema and the schemaLocation is the value of the schema location
+     * @param namespace
+     * @param schemaLocation
+     * @param baseUri
+     */
+    public InputSource resolveEntity(String namespace,
+                                     String schemaLocation,
+                                     String baseUri) {
+        if (log.isDebugEnabled()) {
+            log.debug("resolveEntity: ["+ namespace + "]["+ schemaLocation + "][ " + baseUri+ "]");
+        }
+
+        InputSource returnInputSource = null;
+        
+        if (this.catalogResolver != null) {
+            if(log.isDebugEnabled()) {
+                log.debug("catalogResolver found, calling CatalogURIResolver.getRedirectedURI.");
+            }
+            String redirectedURI = getRedirectedURI(namespace, schemaLocation, baseUri);
+            // first make redirectedURI is valid for retrieving an input stream 
+            if (redirectedURI != null) {
+                returnInputSource = getInputSourceFromRedirectedURI(redirectedURI);
+            }
+        } 
+        // If we were able to get an InputSource from the redirectedURI, just return that
+        // else call up to parent to resolve with original location
+        if (returnInputSource != null) {
+            return returnInputSource;
+        } else {
+            return super.resolveEntity(namespace, schemaLocation, baseUri);
+        }
+    }
+    
+    /**
+     * Given a redirecteURI from a static XML catalog, attempt to get the InputSource.
+     * @param redirectedURI URI string from static XML catalog
+     * @return InputSource or null if we were not able to load the resource
+     */
+    private InputSource getInputSourceFromRedirectedURI(String redirectedURI) {
+        InputStream is = null;
+        String validatedURI = null;
+        InputSource returnInputSource = null;
+        // If we have an absolute path, try to get the InputStream directly
+        if (isAbsolute(redirectedURI)) {
+            is = getInputStreamForURI(redirectedURI);
+            if (is != null) {
+                validatedURI = redirectedURI;
+            }
+        }
+        // If we couldn't get the inputstream try using the classloader
+        if (is == null && classLoader != null) {
+            try {
+                is = classLoader
+                        .getResourceAsStream(redirectedURI);
+                if (is != null) {
+                    validatedURI = redirectedURI;
+                }
+            } catch (Throwable t) {
+                if(log.isDebugEnabled()) {
+                    log.debug("Exception occured in validateRedirectedURI, ignoring exception continuing processing: "+t.getMessage());
+                }
+            }
+            // If we failed to get an InputStream using the entire redirectedURI,
+            //  try striping off the protocol.  This may be necessary for some cases
+            //  if a non-standard protocol is used.
+            if (is == null) {
+                redirectedURI = stripProtocol(redirectedURI);
+                if (log.isDebugEnabled()) {
+                    log.debug("getInputSourceFromRedirectedURI: new redirected location: "+ redirectedURI);
+                }
+                try {
+                    is = classLoader
+                            .getResourceAsStream(redirectedURI);
+                    if (is != null) {
+                        validatedURI = redirectedURI;
+                    }
+                } catch (Throwable t) {
+                    if(log.isDebugEnabled()) {
+                        log.debug("Exception occured in validateRedirectedURI, ignoring exception continuing processing: "+t.getMessage());
+                    }                   
+                }
+            }
+        }
+
+        if (is != null) {
+            if(log.isDebugEnabled()) {
+                log.debug("getInputSourceFromRedirectedURI: XSD input stream is not null after resolving import for: " + 
+                        redirectedURI);
+            }
+            returnInputSource = new InputSource(is);
+            // We need to set the systemId. XmlSchema will use this value to
+            // maintain a collection of
+            // imported XSDs that have been read. If this value is null, then
+            // circular XSDs will
+            // cause infinite recursive reads.
+            returnInputSource.setSystemId(validatedURI != null ? validatedURI : redirectedURI);
+
+            if (log.isDebugEnabled()) {
+                log.debug("returnInputSource :" + returnInputSource.getSystemId());
+            }
+        }
+        return returnInputSource;
+    }
+    
+    private String stripProtocol(String uriStr) {
+        String retURI = uriStr.replace('\\', '/');
+        int index = retURI.indexOf("://");
+        if (index != -1) {
+            retURI = retURI.substring(index + 3);
+        }
+        return retURI;
+    }
+    
+
+
+
+}