You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2007/06/05 21:18:29 UTC
svn commit: r544600 - in
/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2:
AxisServiceGenerator.java util/ util/SimpleURIResolver.java
util/SimpleWSDLLocator.java
Author: gawor
Date: Tue Jun 5 12:18:28 2007
New Revision: 544600
URL: http://svn.apache.org/viewvc?view=rev&rev=544600
Log:
resolve wsdl and schema files in jar files properly
Added:
geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/
geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java (with props)
geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java (with props)
Modified:
geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java
Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java?view=diff&rev=544600&r1=544599&r2=544600
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java (original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/AxisServiceGenerator.java Tue Jun 5 12:18:28 2007
@@ -57,10 +57,12 @@
import org.apache.axis2.jaxws.description.builder.WsdlComposite;
import org.apache.axis2.jaxws.description.builder.WsdlGenerator;
import org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter;
+import org.apache.axis2.jaxws.description.impl.URIResolverImpl;
import org.apache.axis2.jaxws.server.JAXWSMessageReceiver;
import org.apache.axis2.wsdl.WSDLUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.axis2.util.SimpleWSDLLocator;
import org.apache.geronimo.jaxws.PortInfo;
//TODO: Handle RPC Style Messaging
@@ -84,7 +86,11 @@
}
public AxisService getServiceFromWSDL(PortInfo portInfo, String endpointClassName, URL configurationBaseUrl, ClassLoader classLoader) throws Exception {
- Definition wsdlDefinition = getWSDLDefinition(portInfo, configurationBaseUrl, classLoader);
+ String wsdlFile = portInfo.getWsdlFile();
+ if (wsdlFile == null || wsdlFile.equals("")) {
+ throw new Exception("WSDL file is required.");
+ }
+ Definition wsdlDefinition = readWSDL(wsdlFile, configurationBaseUrl, classLoader);
Map<QName, Service> serviceMap = wsdlDefinition.getServices();
Service wsdlService = serviceMap.values().iterator().next();
@@ -121,7 +127,8 @@
QName serviceQName = portInfo.getWsdlService() == null ? wsdlService.getQName() : portInfo.getWsdlService();
WSDLToAxisServiceBuilder wsdlBuilder = new WSDL11ToAxisServiceBuilder(wsdlDefinition, serviceQName , portName);
-
+ wsdlBuilder.setCustomResolver(new URIResolverImpl(classLoader));
+
//populate with axis2 objects
AxisService service = wsdlBuilder.populateService();
service.addParameter(new Parameter(Constants.SERVICE_CLASS, endpointClassName));
@@ -202,17 +209,12 @@
}
}
- protected Definition getWSDLDefinition(PortInfo portInfo,
- URL configurationBaseUrl,
- ClassLoader classLoader)
+ protected Definition readWSDL(String wsdlLocation,
+ URL configurationBaseUrl,
+ ClassLoader classLoader)
throws IOException, WSDLException {
- String wsdlFile = portInfo.getWsdlFile();
- if (wsdlFile == null || wsdlFile.equals("")) {
- throw new IOException("WSDL file was not supplied.");
- }
-
Definition wsdlDefinition = null;
- URL wsdlURL = getWsdlURL(wsdlFile, configurationBaseUrl, classLoader);
+ URL wsdlURL = getWsdlURL(wsdlLocation, configurationBaseUrl, classLoader);
InputStream wsdlStream = null;
try {
wsdlStream = wsdlURL.openStream();
@@ -220,16 +222,14 @@
WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.importDocuments", true);
reader.setFeature("javax.wsdl.verbose", false);
- wsdlDefinition = reader.readWSDL(wsdlURL.toString());
- } catch (RuntimeException e) {
- throw new RuntimeException("invalid WSDL provided " + wsdlURL);
+ SimpleWSDLLocator wsdlLocator = new SimpleWSDLLocator(wsdlURL.toString());
+ wsdlDefinition = reader.readWSDL(wsdlLocator);
} finally {
if (wsdlStream != null) {
wsdlStream.close();
}
}
return wsdlDefinition;
-
}
public static URL getWsdlURL(String wsdlFile, URL configurationBaseUrl, ClassLoader classLoader) {
@@ -254,6 +254,5 @@
}
return wsdlURL;
}
-
-
+
}
Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java?view=auto&rev=544600
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java (added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java Tue Jun 5 12:18:28 2007
@@ -0,0 +1,169 @@
+/**
+ * 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.geronimo.axis2.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ */
+public class SimpleURIResolver {
+
+ private URI uri;
+ private URL url;
+ private InputStream is;
+
+ public SimpleURIResolver() {
+ }
+
+ public SimpleURIResolver(String path) throws IOException {
+ this("", path);
+ }
+
+ public SimpleURIResolver(String baseUriStr, String uriStr) throws IOException {
+ if (baseUriStr != null && baseUriStr.startsWith("jar:")) {
+ tryJar(baseUriStr, uriStr);
+ } else if (uriStr.startsWith("jar:")) {
+ tryJar(uriStr);
+ } else {
+ tryFileSystem(baseUriStr, uriStr);
+ }
+ }
+
+ public void resolve(String baseUriStr, String uriStr) throws IOException {
+ this.uri = null;
+ this.url = null;
+ this.is = null;
+
+ if (baseUriStr != null && baseUriStr.startsWith("jar:")) {
+ tryJar(baseUriStr, uriStr);
+ } else if (uriStr.startsWith("jar:")) {
+ tryJar(uriStr);
+ } else {
+ tryFileSystem(baseUriStr, uriStr);
+ }
+ }
+
+ private void tryFileSystem(String baseUriStr, String uriStr) throws IOException {
+ try {
+ URI relative;
+ File uriFile = new File(uriStr);
+ uriFile = new File(uriFile.getAbsolutePath());
+
+ if (uriFile.exists()) {
+ relative = uriFile.toURI();
+ } else {
+ relative = new URI(uriStr.replaceAll(" ", "%20"));
+ }
+
+ if (relative.isAbsolute()) {
+ uri = relative;
+ url = relative.toURL();
+ is = url.openStream();
+ } else if (baseUriStr != null) {
+ URI base;
+ File baseFile = new File(baseUriStr);
+
+ if (!baseFile.exists() && baseUriStr.startsWith("file:/")) {
+ baseFile = new File(baseUriStr.substring(6));
+ }
+
+ if (baseFile.exists()) {
+ base = baseFile.toURI();
+ } else {
+ base = new URI(baseUriStr);
+ }
+
+ base = base.resolve(relative);
+ if (base.isAbsolute()) {
+ uri = base;
+ url = base.toURL();
+ is = url.openStream();
+ }
+ }
+ } catch (URISyntaxException e) {
+ // do nothing
+ }
+ }
+
+ private void tryJar(String baseStr, String uriStr) throws IOException {
+ int i = baseStr.indexOf('!');
+ if (i == -1) {
+ tryFileSystem(baseStr, uriStr);
+ }
+
+ String jarBase = baseStr.substring(0, i + 1);
+ String jarEntry = baseStr.substring(i + 1);
+ try {
+ URI u = new URI(jarEntry).resolve(uriStr);
+
+ tryJar(jarBase + u.toString());
+
+ if (is != null) {
+ if (u.isAbsolute()) {
+ url = u.toURL();
+ }
+ return;
+ }
+ } catch (URISyntaxException e) {
+ // do nothing
+ }
+
+ tryFileSystem("", uriStr);
+ }
+
+ private void tryJar(String uriStr) throws IOException {
+ int i = uriStr.indexOf('!');
+ if (i == -1) {
+ return;
+ }
+
+ url = new URL(uriStr);
+ try {
+ is = url.openStream();
+ try {
+ uri = url.toURI();
+ } catch (URISyntaxException ex) {
+ // ignore
+ }
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
+
+ public URI getURI() {
+ return uri;
+ }
+
+ public URL getURL() {
+ return url;
+ }
+
+ public InputStream getInputStream() {
+ return is;
+ }
+
+ public boolean isResolved() {
+ return is != null;
+ }
+}
Propchange: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleURIResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java?view=auto&rev=544600
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java (added)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java Tue Jun 5 12:18:28 2007
@@ -0,0 +1,82 @@
+/**
+ * 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.geronimo.axis2.util;
+
+import java.io.IOException;
+
+import javax.wsdl.xml.WSDLLocator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.InputSource;
+
+public class SimpleWSDLLocator implements WSDLLocator {
+
+ private static final Log LOG = LogFactory.getLog(SimpleWSDLLocator.class);
+
+ private String baseURI;
+ private String lastImportLocation;
+ private SimpleURIResolver resolver;
+
+ public SimpleWSDLLocator(String baseURI) {
+ this.baseURI = baseURI;
+ this.resolver = new SimpleURIResolver();
+ }
+
+ public InputSource getBaseInputSource() {
+ return resolve("", this.baseURI);
+ }
+
+ public String getBaseURI() {
+ return this.baseURI;
+ }
+
+ public InputSource getImportInputSource(String parentLocation, String importLocation) {
+ return resolve(parentLocation, importLocation);
+ }
+
+ protected InputSource resolve(String parentLocation, String importLocation) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Resolving '" + importLocation + "' relative to '" + parentLocation + "'");
+ }
+ try {
+ this.resolver.resolve(parentLocation, importLocation);
+ if (this.resolver.isResolved()) {
+ this.lastImportLocation = this.resolver.getURI().toString();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Resolved location '" + this.lastImportLocation + "'");
+ }
+ return new InputSource(this.resolver.getInputStream());
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ return null;
+ }
+
+ public String getLatestImportURI() {
+ return this.lastImportLocation;
+ }
+
+ public void close() {
+ }
+
+
+}
Propchange: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/util/SimpleWSDLLocator.java
------------------------------------------------------------------------------
svn:eol-style = native