Author: veithen
Date: Sun May 15 08:23:41 2011
New Revision: 1103295
URL: http://svn.apache.org/viewvc?rev=1103295&view=rev
Log:
XMLSCHEMA-3: Make sure that DefaultURIResolver properly resolves schema
locations relative to JAR style URLs. This is important to be able to load
schemas from the classpath.
Added:
webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/
webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml
(with props)
Modified:
webservices/xmlschema/trunk/xmlschema-core/pom.xml
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ImportTest.java
Modified: webservices/xmlschema/trunk/xmlschema-core/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/pom.xml?rev=1103295&r1=1103294&r2=1103295&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/pom.xml (original)
+++ webservices/xmlschema/trunk/xmlschema-core/pom.xml Sun May 15 08:23:41 2011
@@ -60,6 +60,25 @@
</executions>
</plugin>
<plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-test-zip</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+
<descriptor>src/test/assembly/test-zip.xml</descriptor>
+ </descriptors>
+ <finalName>test-zip</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.0</version>
Modified:
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
URL:
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java?rev=1103295&r1=1103294&r2=1103295&view=diff
==============================================================================
---
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
(original)
+++
webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
Sun May 15 08:23:41 2011
@@ -21,8 +21,6 @@ package org.apache.ws.commons.schema.res
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 org.xml.sax.InputSource;
@@ -56,10 +54,10 @@ public class DefaultURIResolver implemen
}
}
- String ref = new URI(baseUri).resolve(new
URI(schemaLocation)).toString();
+ String ref = new URL(new URL(baseUri),
schemaLocation).toString();
return new InputSource(ref);
- } catch (URISyntaxException e1) {
+ } catch (MalformedURLException e1) {
throw new RuntimeException(e1);
}
Added: webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml
URL:
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml?rev=1103295&view=auto
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml
(added)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml
Sun May 15 08:23:41 2011
@@ -0,0 +1,35 @@
+<?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.
+ -->
+<assembly>
+ <id>test-zip</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>src/test/resources</directory>
+ <outputDirectory>test-dir</outputDirectory>
+ <includes>
+ <include>import*.xsd</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
Propchange:
webservices/xmlschema/trunk/xmlschema-core/src/test/assembly/test-zip.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ImportTest.java
URL:
http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ImportTest.java?rev=1103295&r1=1103294&r2=1103295&view=diff
==============================================================================
---
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ImportTest.java
(original)
+++
webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ImportTest.java
Sun May 15 08:23:41 2011
@@ -20,6 +20,7 @@
package tests;
import java.io.File;
+import java.net.URL;
import java.util.List;
import javax.xml.namespace.QName;
@@ -113,4 +114,23 @@ public class ImportTest extends Assert {
XmlSchema schema2 = schemaImport.getSchema();
assertNotNull(schema2);
}
+
+ /**
+ * Tests that imports are properly resolved when loading a schema from a
JAR (as will generally
+ * be the case when loading a schema from the classpath).
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImportWithJARURL() throws Exception {
+ String basedir = System.getProperty("basedir");
+ if (basedir == null) {
+ basedir = ".";
+ }
+ URL jarUrl = new File(basedir, "target/test-zip.zip").toURL();
+ URL schemaUrl = new URL("jar:" + jarUrl + "!/test-dir/importBase.xsd");
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new
InputSource(schemaUrl.toExternalForm()));
+ assertNotNull(schema);
+ }
}