Author: jkaputin
Date: Thu Jan  3 16:17:34 2008
New Revision: 608682

URL: http://svn.apache.org/viewvc?rev=608682&view=rev
Log:
WODEN-192
Fix to ensure schemaLocation is correctly resolved
against a base URI when the WSDL and XSD files are
packaged in jar files.

Added:
    webservices/woden/trunk/java/test/testcase/resolver/
    webservices/woden/trunk/java/test/testcase/resolver/schemaloc/
    
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java
   (with props)
    webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/
    
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.jar
   (with props)
    
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl
   (with props)
    
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd
   (with props)
Modified:
    
webservices/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
    
webservices/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java

Modified: 
webservices/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java?rev=608682&r1=608681&r2=608682&view=diff
==============================================================================
--- 
webservices/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
 (original)
+++ 
webservices/woden/trunk/java/src/org/apache/woden/internal/resolver/SchemaResolverAdapter.java
 Thu Jan  3 16:17:34 2008
@@ -16,12 +16,14 @@
  */
 package org.apache.woden.internal.resolver;
 
-import java.io.File;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 
 import org.apache.woden.XMLElement;
+import org.apache.woden.internal.util.StringUtils;
 import org.xml.sax.InputSource;
 
 /**
@@ -91,6 +93,7 @@
                        /* IOException
                         * WSDLException
                         * URISyntaxException
+                        * MalformedURLException
                         */
                        throw new RuntimeException(e);
                }
@@ -134,16 +137,14 @@
         */
        private URI buildUri(String targetNamespace,
                String schemaLocation,
-               String baseUri) throws URISyntaxException {
+               String baseUri) throws URISyntaxException, 
MalformedURLException {
                
        if (baseUri != null) 
         {
-
-          File baseFile = new File(baseUri);
-           if (baseFile.exists()) baseUri = baseFile.toURI().toString();
-                
-           return new URI(baseUri).resolve(new URI(schemaLocation));
-
+           URL ctxUrl = new URL(baseUri);
+           URL schemaUrl = StringUtils.getURL(ctxUrl,schemaLocation);
+           URI uri = new URI(schemaUrl.toString());
+           return uri;
         }
         return new URI(schemaLocation);
                

Modified: 
webservices/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java?rev=608682&r1=608681&r2=608682&view=diff
==============================================================================
--- 
webservices/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java 
(original)
+++ 
webservices/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java 
Thu Jan  3 16:17:34 2008
@@ -78,6 +78,7 @@
 import org.apache.woden.xpointer.XPointerTest;
 
 import testcase.extensions.foo.FooBindingExtensionsTest;
+import testcase.resolver.schemaloc.SchemaLocationTest;
 
 public class AllWodenTestsDOM extends TestSuite
 {
@@ -161,6 +162,7 @@
     addTest(ExtensionRegistryTest.suite());
     addTest(FooBindingExtensionsTest.suite());
     addTest(XPointerTest.suite());
+    addTest(SchemaLocationTest.suite());
     //TODO in-progress 30May06 tests for BindingOpExt and BindingMsgRefExt
   }
 

Added: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java?rev=608682&view=auto
==============================================================================
--- 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java
 (added)
+++ 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java
 Thu Jan  3 16:17:34 2008
@@ -0,0 +1,102 @@
+package testcase.resolver.schemaloc;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.internal.resolver.DOMSchemaResolverAdapter;
+import org.apache.woden.internal.resolver.SchemaResolverAdapter;
+import org.apache.woden.internal.resolver.SimpleURIResolver;
+import org.xml.sax.InputSource;
+
+import testcase.extensions.foo.FooBindingExtensionsTest;
+
+public class SchemaLocationTest extends TestCase {
+    
+    private SchemaResolverAdapter fResolver;
+    private String fSchemaTns = "http://example.com/data";;
+    private String fWsdlJarPath = 
"testcase/resolver/schemaloc/resources/SchemaLocationTest.jar";
+    private String fWsdlFilePath = 
"testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl";
+    private String fWsdlFileName = "SchemaLocationTest.wsdl";
+    private String fSchemaFilePath = 
"testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd";
+    private String fSchemaFileName = "SchemaLocationTest.xsd";
+    private String fWsdlWebPath = 
"http://example.com/resources/SchemaLocationTest.wsdl";;
+    private String fSchemaWebPath = 
"http://example.com/resources/SchemaLocationTest.xsd";;
+
+    public static Test suite() {
+        return new TestSuite(SchemaLocationTest.class);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        fResolver = new DOMSchemaResolverAdapter(new SimpleURIResolver(), 
null);
+    }
+    
+    public void testRelativePath_File() {
+        URL baseURL = getClass().getClassLoader().getResource(fWsdlFilePath);
+        String baseURI = baseURL.toString();
+        int i = baseURI.indexOf(fWsdlFileName);
+        String contextPath = baseURI.substring(0,i);
+        String expectedResult = contextPath + fSchemaFileName;
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, fSchemaFileName, 
baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation relative file path not resolved 
correctly", expectedResult, actualResult);
+    }
+
+    public void testAbsolutePath_File() {
+        URL baseURL = getClass().getClassLoader().getResource(fWsdlFilePath);
+        String baseURI = baseURL.toString();
+        URL schemaURL = 
getClass().getClassLoader().getResource(fSchemaFilePath);
+        String absoluteSchemaPath = schemaURL.toString();
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, 
absoluteSchemaPath, baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation absolute file path not resolved 
correctly", absoluteSchemaPath, actualResult);
+    }
+
+    public void testRelativePath_Jar() {
+        URL baseURL = getClass().getClassLoader().getResource(fWsdlJarPath);
+        String contextPath = "jar:" + baseURL.toString() + "!/META-INF/";
+        String baseURI =  contextPath + fWsdlFileName;
+        String expectedResult = contextPath + fSchemaFileName;
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, fSchemaFileName, 
baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation relative path not resolved correctly for 
jar file", expectedResult, actualResult);
+    }
+
+    public void testAbsolutePath_Jar() {
+        URL baseURL = getClass().getClassLoader().getResource(fWsdlJarPath);
+        String contextPath = "jar:" + baseURL.toString() + "!/META-INF/";
+        String baseURI =  contextPath + fWsdlFileName;
+        String absoluteSchemaPath = contextPath + fSchemaFileName;
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, 
absoluteSchemaPath, baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation absolute path not resolved correctly for 
jar file", absoluteSchemaPath, actualResult);
+    }
+
+    public void testRelativePath_Web() {
+        String baseURI = fWsdlWebPath;
+        int i = baseURI.indexOf(fWsdlFileName);
+        String contextPath = baseURI.substring(0,i);
+        String expectedResult = contextPath + fSchemaFileName;
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, fSchemaFileName, 
baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation relative web path not resolved 
correctly", expectedResult, actualResult);
+    }
+
+    public void testAbsolutePath_Web() {
+        String baseURI = fWsdlWebPath;
+        String absoluteSchemaPath = fSchemaWebPath;
+        
+        InputSource is = fResolver.resolveEntity(fSchemaTns, 
absoluteSchemaPath, baseURI);
+        String actualResult = is.getSystemId();
+        assertEquals("schemaLocation absolute web path not resolved 
correctly", absoluteSchemaPath, actualResult);
+    }
+
+}

Propchange: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/SchemaLocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.jar
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.jar?rev=608682&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl?rev=608682&view=auto
==============================================================================
--- 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl
 (added)
+++ 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl
 Thu Jan  3 16:17:34 2008
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!-- 
+ * 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.
+-->
+<description xmlns="http://www.w3.org/ns/wsdl";
+       targetNamespace="http://ws.apache.woden";
+       xmlns:tns="http://ws.apache.woden";
+       xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+
+       <documentation>
+           Used by SchemaLocationTest to test the behaviour of the 
SchemaResolverAdapter class.
+       </documentation>
+       
+       <types>
+           <xs:schema targetNamespace="http://example.com/inline";>
+               <xs:import namespace="http://example.com/data"; 
schemaLocation="dummy" />
+           </xs:schema>
+       </types>
+
+</description>
\ No newline at end of file

Propchange: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd
URL: 
http://svn.apache.org/viewvc/webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd?rev=608682&view=auto
==============================================================================
--- 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd
 (added)
+++ 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd
 Thu Jan  3 16:17:34 2008
@@ -0,0 +1,27 @@
+<!--
+ !
+ ! 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 xmlns:xs='http://www.w3.org/2001/XMLSchema' 
+         targetNamespace="http://example.com/data";>
+ <xs:element name="aardvaark">
+  <xs:complexType>
+   <xs:sequence>
+     <xs:element ref="population" minOccurs='1' maxOccurs='unbounded'/>
+   </xs:sequence>
+  </xs:complexType>
+ </xs:element>
+</xs:schema>

Propchange: 
webservices/woden/trunk/java/test/testcase/resolver/schemaloc/resources/SchemaLocationTest.xsd
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to