You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by tl...@apache.org on 2006/11/09 06:58:39 UTC

svn commit: r472784 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/resource/ common/common/src/main/java/org/apache/cxf/wsdl4jutils/ common/common/src/test/java/org/apache/cxf/resource/ rt/core/src/test/java/org/apache/cxf/wsdl11...

Author: tli
Date: Wed Nov  8 21:58:38 2006
New Revision: 472784

URL: http://svn.apache.org/viewvc?view=rev&rev=472784
Log:
Add wsdl4jUtils to support WSDL4J WSDLLocator to reuse logic for WS-COMMON XMLSchemaURIResolver

Added:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java   (with props)
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java   (with props)
    incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd   (with props)
Removed:
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
    incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/s5/
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
    incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/schema4.xsd

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java?view=auto&rev=472784
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java Wed Nov  8 21:58:38 2006
@@ -0,0 +1,130 @@
+/**
+ * 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.cxf.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Stack;
+
+import org.xml.sax.InputSource;
+
+
+public class ExtendedURIResolver {
+
+    private Stack<ResolverInfo> stack = new Stack<ResolverInfo>();
+    private org.apache.cxf.resource.URIResolver currentResolver;
+    private Stack<InputStream> resourceOpened = new Stack<InputStream>();
+
+    private class ResolverInfo {
+        String uri;
+        org.apache.cxf.resource.URIResolver resolver;
+        public ResolverInfo(String uri, org.apache.cxf.resource.URIResolver resolver) {
+            this.uri = uri;
+            this.resolver = resolver;
+        }
+        public String getUri() {
+            return uri;
+        }
+        public org.apache.cxf.resource.URIResolver getResolver() {
+            return resolver;
+        }
+    }
+    
+    public InputSource resolve(String schemaLocation, String baseUri) {
+        try {
+            if (baseUri != null) {
+                URI check = null;
+                if (baseUri.startsWith("classpath:")) {
+                    check = new URI(baseUri.substring(10));
+                } else if (baseUri.startsWith("jar:")) {
+                    int i = baseUri.indexOf("!");
+                    if (i != -1) {
+                        String bu = baseUri.substring(i + 1);
+                        check = new URI(bu.startsWith("file:") ? bu : "file:" + bu);
+                    } else {
+                        check = new URI(baseUri);
+                    }
+                } else {
+                    check = new URI(baseUri);
+                }
+                if (check.isAbsolute()) {
+                    currentResolver = new org.apache.cxf.resource.URIResolver();
+                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));            
+                } else {
+                    while (!stack.isEmpty()) {
+                        ResolverInfo ri = stack.pop();
+                        if (ri.getUri().equals(baseUri)) {
+                            currentResolver = ri.getResolver();
+                            stack.addElement(ri);
+                            break;
+                        }
+                    }
+                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));            
+                }
+                if (currentResolver == null) {
+                    throw new RuntimeException("invalidate schema import");
+                }
+            } else {
+                if (currentResolver == null) {
+                    currentResolver = new org.apache.cxf.resource.URIResolver();
+                }
+            }
+            currentResolver.resolveStateful(baseUri, schemaLocation, getClass());
+            if (currentResolver.isResolved()) {
+                if (currentResolver.getURI() != null && currentResolver.getURI().isAbsolute()) {
+                    // When importing a relative file,
+                    // setSystemId with an absolute path so the
+                    // resolver finds any files which that file
+                    // imports with locations relative to it.
+                    schemaLocation = currentResolver.getURI().toString();
+                }
+                InputStream in = currentResolver.getInputStream();
+                resourceOpened.addElement(in);
+                InputSource source = new InputSource(in);
+                source.setSystemId(schemaLocation);
+                return source;
+            }
+
+        } catch (IOException e) {
+            // move on...
+        } catch (URISyntaxException use) {            
+            // move on...
+        }
+        return new InputSource(schemaLocation);
+    }
+    
+    public void close() {
+        try {
+            while (!resourceOpened.isEmpty()) {
+                InputStream in = resourceOpened.pop();
+                in.close();
+            }
+        } catch (IOException ioe) {
+            // move on...
+        }
+    }
+    
+    public String getLatestImportURI() {
+        return currentResolver.getURI().toString();
+    }
+    
+}

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/ExtendedURIResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java?view=diff&rev=472784&r1=472783&r2=472784
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java Wed Nov  8 21:58:38 2006
@@ -162,8 +162,9 @@
         }
         if (finalRelative != null) {
             File targetFile = new File(finalRelative);
-            if (!targetFile.exists() && baseUriStr.startsWith("file:/")) {
-                targetFile = new File(baseUriStr.substring(6));
+            if (!targetFile.exists()) {
+                tryClasspath(finalRelative.toString().substring(5));
+                return;
             }
             URI target;
             if (targetFile.exists()) {

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java?view=diff&rev=472784&r1=472783&r2=472784
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java Wed Nov  8 21:58:38 2006
@@ -18,11 +18,6 @@
  */
 package org.apache.cxf.resource;
 
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Stack;
-
 import org.xml.sax.InputSource;
 
 import org.apache.ws.commons.schema.resolver.URIResolver;
@@ -34,85 +29,12 @@
  */
 public class XmlSchemaURIResolver implements URIResolver {
 
-    private Stack<ResolverInfo> stack = new Stack<ResolverInfo>();
-    private org.apache.cxf.resource.URIResolver currentResolver;
+    private ExtendedURIResolver resolver;
     
-    private class ResolverInfo {
-        String uri;
-        org.apache.cxf.resource.URIResolver resolver;
-        public ResolverInfo(String uri, org.apache.cxf.resource.URIResolver resolver) {
-            this.uri = uri;
-            this.resolver = resolver;
-        }
-        public String getUri() {
-            return uri;
-        }
-        public org.apache.cxf.resource.URIResolver getResolver() {
-            return resolver;
-        }
+    public XmlSchemaURIResolver() {
+        resolver = new ExtendedURIResolver();
     }
     public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
-        try {
-            if (baseUri != null) {
-                URI check = null;
-                if (baseUri.startsWith("classpath:")) {
-                    check = new URI(baseUri.substring(10));
-                } else if (baseUri.startsWith("jar:")) {
-                    int i = baseUri.indexOf("!");
-                    if (i != -1) {
-                        String bu = baseUri.substring(i + 1);
-                        check = new URI(bu.startsWith("file:") ? bu : "file:" + bu);
-                    } else {
-                        check = new URI(baseUri);
-                    }
-                } else {
-                    check = new URI(baseUri);
-                }
-                if (check.isAbsolute()) {
-                    currentResolver = new org.apache.cxf.resource.URIResolver();
-                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));            
-                } else {
-                    while (!stack.isEmpty()) {
-                        ResolverInfo ri = stack.pop();
-                        if (ri.getUri().equals(baseUri)) {
-                            currentResolver = ri.getResolver();
-                            stack.addElement(ri);
-                            break;
-                        }
-                    }
-                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));            
-                }
-                if (currentResolver == null) {
-                    throw new RuntimeException("invalidate schema import");
-                }
-            } else {
-                if (currentResolver == null) {
-                    currentResolver = new org.apache.cxf.resource.URIResolver();
-                }
-            }
-            currentResolver.resolveStateful(baseUri, schemaLocation, getClass());
-            if (currentResolver.isResolved()) {
-                if (currentResolver.getURI() != null && currentResolver.getURI().isAbsolute()) {
-                    // When importing a relative file,
-                    // setSystemId with an absolute path so the
-                    // resolver finds any files which that file
-                    // imports with locations relative to it.
-                    schemaLocation = currentResolver.getURI().toString();
-                }
-                InputSource source = new InputSource(currentResolver.getInputStream());
-                source.setSystemId(schemaLocation);
-                return source;
-            }
-
-        } catch (IOException e) {
-            // move on...
-        } catch (URISyntaxException use) {            
-            // move on...
-        }
-
-        return new InputSource(schemaLocation);
-
+        return resolver.resolve(schemaLocation, baseUri);
     }
-
-    
 }

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java?view=auto&rev=472784
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java Wed Nov  8 21:58:38 2006
@@ -0,0 +1,58 @@
+/**
+ * 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.cxf.wsdl4jutils;
+
+import javax.wsdl.xml.WSDLLocator;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.resource.ExtendedURIResolver;
+
+public class WSDLLocatorImpl implements WSDLLocator {
+
+    private String wsdlUrl;
+    private ExtendedURIResolver resolver;
+    
+    private String baseUri;
+    private String importedUri;
+    
+    public WSDLLocatorImpl(String wsdlUrl) {
+        this.wsdlUrl = wsdlUrl;
+        this.baseUri = this.wsdlUrl;
+        resolver = new ExtendedURIResolver();
+    }
+    public InputSource getBaseInputSource() {
+        return resolver.resolve(baseUri, null);
+    }
+    public String getBaseURI() {
+        return baseUri;
+    }
+    public String getLatestImportURI() {
+        return resolver.getLatestImportURI();
+    }
+    public InputSource getImportInputSource(String parent, String importLocation) {
+        this.baseUri = parent;
+        this.importedUri = importLocation;
+        return resolver.resolve(this.importedUri, this.baseUri);        
+    }
+    public void close() {
+        resolver.close();
+    }
+}

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/wsdl4jutils/WSDLLocatorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java?view=diff&rev=472784&r1=472783&r2=472784
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/WSDLServiceBuilderTest.java Wed Nov  8 21:58:38 2006
@@ -56,6 +56,7 @@
 import org.apache.cxf.service.model.TypeInfo;
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
+import org.apache.cxf.wsdl4jutils.WSDLLocatorImpl;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.easymock.classextension.EasyMock;
@@ -89,13 +90,16 @@
         setUpWSDL(WSDL_PATH);
     }
 
+
+    
     private void setUpWSDL(String wsdl) throws Exception {
         String wsdlUrl = getClass().getResource(wsdl).toString();
         LOG.info("the path of wsdl file is " + wsdlUrl);
         WSDLFactory wsdlFactory = WSDLFactory.newInstance();
         WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
         wsdlReader.setFeature("javax.wsdl.verbose", false);
-        def = wsdlReader.readWSDL(wsdlUrl);
+        
+        def = wsdlReader.readWSDL(new WSDLLocatorImpl(wsdlUrl));
 
         WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
         for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {

Modified: incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/schema4.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/schema4.xsd?view=diff&rev=472784&r1=472783&r2=472784
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/schema4.xsd (original)
+++ incubator/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/s1/s2/s4/schema4.xsd Wed Nov  8 21:58:38 2006
@@ -19,7 +19,7 @@
 -->
 <xs:schema version="1.0" targetNamespace="http://apache.org/hello_world_soap_http/types/s4" xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
-  <xs:import namespace="http://apache.org/hello_world_soap_http/types/s5" schemaLocation="./s5/schema5.xsd"/>
+  <xs:import namespace="http://apache.org/hello_world_soap_http/types/s5" schemaLocation="/schema5.xsd"/>
 
   <xs:element name="greetMeOneWay">
     <xs:complexType>

Added: incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd?view=auto&rev=472784
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd (added)
+++ incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd Wed Nov  8 21:58:38 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  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.
+-->
+<xs:schema version="1.0" targetNamespace="http://apache.org/hello_world_soap_http/types/s5" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:element name="sayHi">
+    <xs:complexType/>
+  </xs:element>
+
+</xs:schema>
+

Propchange: incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/core/src/test/resources/schema5.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml