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 ga...@apache.org on 2009/01/14 06:55:01 UTC
svn commit: r734338 - in
/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws:
description/impl/EndpointDescriptionImpl.java
description/impl/ServiceDescriptionImpl.java util/CatalogURIResolver.java
Author: gawor
Date: Tue Jan 13 21:55:00 2009
New Revision: 734338
URL: http://svn.apache.org/viewvc?rev=734338&view=rev
Log:
make OASIS catalog resolution work for schema references (AXIS2-4209)
Modified:
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.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/util/CatalogURIResolver.java
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java?rev=734338&r1=734337&r2=734338&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/EndpointDescriptionImpl.java Tue Jan 13 21:55:00 2009
@@ -34,6 +34,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.java.security.AccessController;
import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.catalog.JAXWSCatalogManager;
import org.apache.axis2.jaxws.description.EndpointDescription;
import org.apache.axis2.jaxws.description.EndpointDescriptionJava;
import org.apache.axis2.jaxws.description.EndpointDescriptionWSDL;
@@ -50,6 +51,7 @@
import org.apache.axis2.jaxws.feature.ServerFramework;
import org.apache.axis2.jaxws.i18n.Messages;
import org.apache.axis2.jaxws.registry.ServerConfiguratorRegistry;
+import org.apache.axis2.jaxws.util.CatalogURIResolver;
import org.apache.axis2.jaxws.util.WSDL4JWrapper;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.axis2.wsdl.util.WSDLDefinitionWrapper;
@@ -871,21 +873,16 @@
if (log.isDebugEnabled()) {
log.debug("Building AxisService from wsdl: " + getServiceDescriptionImpl().getWSDLWrapper().getWSDLLocation());
}
-
+
+ ClassLoader classLoader;
if (composite.isServiceProvider()) {
- URIResolverImpl uriResolver =
- new URIResolverImpl(composite.getClassLoader());
- serviceBuilder.setCustomResolver(uriResolver);
+ classLoader = composite.getClassLoader();
} else {
- ClassLoader classLoader = (ClassLoader)AccessController.doPrivileged(new
- PrivilegedAction() {
- public Object run() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- URIResolverImpl uriResolver = new URIResolverImpl(classLoader);
- serviceBuilder.setCustomResolver(uriResolver);
+ classLoader = getContextClassLoader(null);
}
+ JAXWSCatalogManager catalogManager = getServiceDescriptionImpl().getCatalogManager();
+ CatalogURIResolver uriResolver = new CatalogURIResolver(catalogManager, classLoader);
+ serviceBuilder.setCustomResolver(uriResolver);
if (getServiceDescriptionImpl().isServerSide())
serviceBuilder.setServerSide(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=734338&r1=734337&r2=734338&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 Tue Jan 13 21:55:00 2009
@@ -295,6 +295,7 @@
this.dbcMap = dbcMap;
this.isServerSide = true;
this.serviceQName = serviceQName;
+ this.catalogManager = this.composite.getCatalogManager();
// if the ServiceDescriptionImpl was constructed with a specific service QName
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=734338&r1=734337&r2=734338&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 Tue Jan 13 21:55:00 2009
@@ -19,29 +19,21 @@
package org.apache.axis2.jaxws.util;
-import org.apache.axis2.java.security.AccessController;
+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.ws.commons.schema.resolver.URIResolver;
import org.apache.xml.resolver.Catalog;
import org.xml.sax.InputSource;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.PrivilegedAction;
-
-
/**
* 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 implements URIResolver {
+public class CatalogURIResolver extends URIResolverImpl {
private static Log log = LogFactory.getLog(CatalogWSDLLocator.class);
private Catalog catalogResolver;
@@ -51,9 +43,21 @@
* @param catalogManager
* the OASISCatalogManager which will determine the settings for the XML catalog
*/
-
public CatalogURIResolver(JAXWSCatalogManager catalogManager) {
- this.catalogResolver = catalogManager.getCatalog();
+ 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();
+ }
}
/**
@@ -64,15 +68,17 @@
* the importing
* @return the resolved import location, or null if no indirection is performed
*/
- public String getRedirectedURI(String importURI, String parent) {
+ public String getRedirectedURI(String namespace,
+ String schemaLocation,
+ String baseUri) {
String resolvedImportLocation = null;
try {
- resolvedImportLocation = this.catalogResolver.resolveSystem(importURI);
+ resolvedImportLocation = this.catalogResolver.resolveSystem(namespace);
if (resolvedImportLocation == null) {
- resolvedImportLocation = catalogResolver.resolveURI(importURI);
+ resolvedImportLocation = catalogResolver.resolveURI(schemaLocation);
}
if (resolvedImportLocation == null) {
- resolvedImportLocation = catalogResolver.resolvePublic(importURI, parent);
+ resolvedImportLocation = catalogResolver.resolvePublic(namespace, namespace);
}
} catch (IOException e) {
@@ -91,148 +97,17 @@
*/
public InputSource resolveEntity(String namespace,
String schemaLocation,
- String baseUri){
-
- if (baseUri!=null)
- {
- String redirectedURI = getRedirectedURI(namespace, baseUri);
- if (redirectedURI != null)
- schemaLocation = redirectedURI;
- try
- {
- File baseFile = new File(baseUri);
-
-
- if (fileExists(baseFile)) baseUri = baseFile.toURI().toString();
-
- String ref = new URI(baseUri).resolve(new URI(schemaLocation)).toString();
-
- return new InputSource(ref);
- }
- catch (URISyntaxException e1)
- {
- throw new RuntimeException(e1);
- }
-
- }
- return new InputSource(schemaLocation);
-
- }
-
- /**
- * Find whether a given uri is relative or not
- *
- * @param uri
- * @return boolean
- */
- protected boolean isAbsolute(String uri) {
- return uri.startsWith("http://");
- }
-
- /**
- * This is essentially a call to "new URL(contextURL, spec)"
- * with extra handling in case spec is
- * a file.
- *
- * @param contextURL
- * @param spec
- * @throws java.io.IOException
- */
- protected URL getURL(URL contextURL, String spec) throws IOException {
-
- // First, fix the slashes as windows filenames may have backslashes
- // in them, but the URL class wont do the right thing when we later
- // process this URL as the contextURL.
- String path = spec.replace('\\', '/');
-
- // See if we have a good URL.
- URL url;
-
- try {
-
- // first, try to treat spec as a full URL
- url = new URL(contextURL, path);
-
- // if we are deail with files in both cases, create a url
- // by using the directory of the context URL.
- if ((contextURL != null) && url.getProtocol().equals("file")
- && contextURL.getProtocol().equals("file")) {
- url = getFileURL(contextURL, path);
- }
- } catch (MalformedURLException me) {
-
- // try treating is as a file pathname
- url = getFileURL(contextURL, path);
- }
-
- // Everything is OK with this URL, although a file url constructed
- // above may not exist. This will be caught later when the URL is
- // accessed.
- return url;
- } // getURL
-
- /**
- * Method getFileURL
- *
- * @param contextURL
- * @param path
- * @throws IOException
- */
- protected URL getFileURL(URL contextURL, String path)
- throws IOException {
-
- if (contextURL != null) {
-
- // get the parent directory of the contextURL, and append
- // the spec string to the end.
- String contextFileName = contextURL.getFile();
- URL parent = null;
- //the logic for finding the parent file is this.
- //1.if the contextURI represents a file then take the parent file
- //of it
- //2. If the contextURI represents a directory, then take that as
- //the parent
- File parentFile;
- File contextFile = new File(contextFileName);
- if (contextFile.isDirectory()){
- parentFile = contextFile;
- }else{
- parentFile = contextFile.getParentFile();
- }
-
- if (parentFile != null) {
- parent = parentFile.toURL();
- }
- if (parent != null) {
- return new URL(parent, path);
+ String baseUri) {
+ String location = schemaLocation;
+
+ if (this.catalogResolver != null) {
+ String redirectedURI = getRedirectedURI(namespace, schemaLocation, baseUri);
+ if (redirectedURI != null) {
+ location = redirectedURI;
}
}
-
- return new URL("file", "", path);
- } // getFileURL
-
-
- private Boolean fileExists (final File file) {
- Boolean exists = (Boolean) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return new Boolean(file.exists());
- }
- }
- );
- return exists;
- }
-
- private Boolean fileIsDirectory(final File file) {
- Boolean isDir = (Boolean) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- return new Boolean(file.isDirectory());
- }
- }
- );
- return isDir;
+
+ return super.resolveEntity(namespace, location, baseUri);
}
-
}