Author: ningjiang
Date: Mon Mar 22 08:28:44 2010
New Revision: 925995
URL: http://svn.apache.org/viewvc?rev=925995&view=rev
Log:
CXF-2724 applied patch with thanks to William
Added:
cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
(with props)
cxf/trunk/common/common/src/test/resources/wsdl/
cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl (with props)
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java?rev=925995&r1=925994&r2=925995&view=diff
==============================================================================
---
cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
(original)
+++
cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
Mon Mar 22 08:28:44 2010
@@ -167,9 +167,9 @@ public class URIResolver {
} else if (!StringUtils.isEmpty(baseUriStr)) {
URI base;
File baseFile = new File(baseUriStr);
-
- if (!baseFile.exists() && baseUriStr.startsWith("file:/")) {
- baseFile = new File(baseUriStr.substring(6));
+
+ if (!baseFile.exists() && baseUriStr.startsWith("file:")) {
+ baseFile = new File(getFilePathFromUri(baseUriStr));
}
if (baseFile.exists()) {
@@ -232,6 +232,30 @@ public class URIResolver {
}
}
+ /**
+ * Assumption: URI scheme is "file"
+ */
+ private String getFilePathFromUri(String uriString) {
+ String path = null;
+
+ try {
+ path = new URL(uriString).getPath();
+ } catch (MalformedURLException e) {
+ // ignore
+ }
+
+ if (path == null) {
+ if (uriString.startsWith("file:/")) {
+ path = uriString.substring(6);
+ } else if (uriString.startsWith("file:")) {
+ // handle Windows file URI such as "file:C:/foo/bar"
+ path = uriString.substring(5);
+ }
+ }
+
+ return path;
+ }
+
private void tryArchive(String baseStr, String uriStr) throws IOException {
int i = baseStr.indexOf('!');
if (i == -1) {
Modified:
cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java?rev=925995&r1=925994&r2=925995&view=diff
==============================================================================
---
cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
(original)
+++
cxf/trunk/common/common/src/test/java/org/apache/cxf/resource/URIResolverTest.java
Mon Mar 22 08:28:44 2010
@@ -85,5 +85,30 @@ public class URIResolverTest extends Ass
InputStream is3 = uriResolver.getInputStream();
assertNotNull(is3);
}
+
+
+ @Test
+ public void testResolveRelativeFile() throws Exception {
+ URIResolver wsdlResolver = new URIResolver();
+
+ // resolve the wsdl
+ wsdlResolver.resolve(null, "wsdl/foo.wsdl", this.getClass());
+ assertTrue(wsdlResolver.isResolved());
+
+ // get the base uri from the resolved wsdl location
+ String baseUri = wsdlResolver.getURI().toString();
+
+ // resolve the schema using relative location
+ String schemaLocation = "../schemas/configuration/bar.xsd";
+ URIResolver xsdResolver = new URIResolver();
+ xsdResolver.resolve(baseUri, schemaLocation, this.getClass());
+ assertNotNull(xsdResolver.getInputStream());
+
+ // resolve the schema using relative location with base uri fragment
+ xsdResolver = new URIResolver();
+ xsdResolver.resolve(baseUri + "#type2", schemaLocation,
this.getClass());
+ assertNotNull(xsdResolver.getInputStream());
+
+ }
}
Added: cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd?rev=925995&view=auto
==============================================================================
--- cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
(added)
+++ cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
Mon Mar 22 08:28:44 2010
@@ -0,0 +1,37 @@
+<?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.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="urn:RelPath" xmlns:RP="urn:RelPath"
+ elementFormDefault="qualified">
+ <xs:complexType name="RPTest1CT_In">
+ <xs:sequence>
+ <xs:element name="RPTest1_CT_String" type="xs:string">
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="RPTest1CT_Out">
+ <xs:sequence>
+ <xs:element name="RPTest1_Ele_String" type="xs:string">
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
Propchange:
cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/common/common/src/test/resources/schemas/configuration/bar.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl?rev=925995&view=auto
==============================================================================
--- cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl (added)
+++ cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl Mon Mar 22
08:28:44 2010
@@ -0,0 +1,76 @@
+<?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.
+-->
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://www.example.org/RelPathDocLit/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RelPathDocLit"
+ targetNamespace="http://www.example.org/RelPathDocLit/"
xmlns:xsd1="urn:RelPath">
+ <wsdl:types>
+ <xsd:schema
targetNamespace="http://www.example.org/RelPathDocLit/">
+ <xsd:element name="NewOperation">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="in"
type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="NewOperationResponse">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="out"
type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:import namespace="urn:RelPath"
schemaLocation="../schemas/configuration/bar.xsd">
+ </xsd:import>
+ </xsd:schema>
+ </wsdl:types>
+ <wsdl:message name="RelPathOperationRequest">
+ <wsdl:part name="parameters" type="xsd1:RPTest1CT_In" />
+ </wsdl:message>
+ <wsdl:message name="RelPathOperationResponse">
+ <wsdl:part name="parameters" type="xsd1:RPTest1CT_Out" />
+ </wsdl:message>
+ <wsdl:portType name="RelPathDocLit">
+ <wsdl:operation name="RelPathOperation">
+ <wsdl:input message="tns:RelPathOperationRequest" />
+ <wsdl:output message="tns:RelPathOperationResponse" />
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="RelPathDocLitSOAP" type="tns:RelPathDocLit">
+ <soap:binding style="document"
+ transport="http://schemas.xmlsoap.org/soap/http" />
+ <wsdl:operation name="RelPathOperation">
+ <soap:operation
soapAction="http://www.example.org/RelPathDocLit/RelPathOperation" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="RelPathDocLit">
+ <wsdl:port binding="tns:RelPathDocLitSOAP"
name="RelPathDocLitSOAP">
+ <soap:address
location="http://localhost:2580/process/RelPathDocLit" />
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
Propchange: cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/common/common/src/test/resources/wsdl/foo.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml