Permalink
Browse files

SWITCHYARD-1926 WSDLReader in API extensions does not treat import pa…

…ths as relative
  • Loading branch information...
1 parent 77f00e8 commit 73d678fdf595341b4a2982bdf4eebc0f4aff7169 @kcbabo kcbabo committed Jan 10, 2014
@@ -77,6 +77,7 @@
private static final String RESPONSE = "Response";
private Boolean _documentStyle;
+ private String _wsdlURI;
/**
* Read the WSDL document accessible via the specified
@@ -117,8 +118,12 @@
*/
public Element readWSDL(final String wsdlURI) throws WSDLReaderException {
try {
+ // this is a hack, but it's necessary to avoid making breaking changes to
+ // the API by requiring the WSDL URI in the constructor
+ if (_wsdlURI == null) {
+ _wsdlURI = wsdlURI;
+ }
LOGGER.trace("Retrieving document at '" + wsdlURI + "'");
-
URL url = getURL(wsdlURI);
InputStream inputStream = url.openStream();
InputSource inputSource = new InputSource(inputStream);
@@ -491,7 +496,12 @@ private URL getURL(final String path) throws MalformedURLException {
} else {
URL url;
try {
- url = Classes.getResource(path, getClass());
+ if (_wsdlURI.equals(path)) {
+ url = Classes.getResource(path, getClass());
+ } else {
+ // we are loading an imported resource, so use relative path
+ url = Classes.getResource(createRelativePath(_wsdlURI, path), getClass());
+ }
} catch (IOException ioe) {
url = null;
}
@@ -502,4 +512,15 @@ private URL getURL(final String path) throws MalformedURLException {
return url;
}
}
+
+ // This method creates a relative path for an imported WSDL (path) based on the URI for
+ // the importing WSDL (baseURI).
+ String createRelativePath(String baseURI, String path) {
+ int lastPathIdx = baseURI.lastIndexOf('/');
+ if (lastPathIdx > 0) {
+ return baseURI.substring(0, lastPathIdx + 1) + path;
+ } else {
+ return path;
+ }
+ }
}
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors.
+ *
+ * Licensed 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.switchyard.extensions.wsdl;
+
+import java.util.Set;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.switchyard.metadata.ServiceOperation;
+
+public class WSDLReaderTest {
+
+ private static final String ORDER_WSDL = "wsdl/OrderService.wsdl";
+ private WSDLReader reader;
+
+ @Before
+ public void setUp() {
+ reader = new WSDLReader();
+ }
+
+ @Test
+ public void testRelativePaths() {
+ String base1 = "base.wsdl";
+ String base2 = "wsdl/one/base.wsdl";
+ String base3 = "wsdl/one/two/base.wsdl";
+ String wsdl = "example.wsdl";
+
+ Assert.assertEquals("example.wsdl",
+ reader.createRelativePath(base1, wsdl));
+ Assert.assertEquals("wsdl/one/example.wsdl",
+ reader.createRelativePath(base2, wsdl));
+ Assert.assertEquals("wsdl/one/two/example.wsdl",
+ reader.createRelativePath(base3, wsdl));
+ }
+
+ @Test
+ public void importedWSDLs() throws Exception {
+ Assert.assertNotNull(reader.readWSDL(ORDER_WSDL));
+ Set<ServiceOperation> ops = reader.readWSDL(ORDER_WSDL, "OrderService");
+ Assert.assertEquals(1, ops.size());
+ }
+}
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<wsdl:definitions targetNamespace="urn:switchyard-services:common:1.0"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:tns="urn:switchyard-services:common:1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
+
+ <wsdl:types>
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:import schemaLocation="OrderTypes.xsd"
+ namespace="urn:switchyard-services:common:1.0" />
+ </xs:schema>
+ </wsdl:types>
+
+ <wsdl:message name="submitOrder">
+ <wsdl:part name="parameters" element="tns:submitOrder" />
+ </wsdl:message>
+ <wsdl:message name="submitOrderResponse">
+ <wsdl:part name="parameters" element="tns:submitOrderResponse" />
+ </wsdl:message>
+
+</wsdl:definitions>
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<definitions targetNamespace="urn:switchyard-services:orderservice:1.0"
+ xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:switchyard-services:orderservice:1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:common="urn:switchyard-services:common:1.0" >
+
+ <import location="Common.wsdl" namespace="urn:switchyard-services:common:1.0"></import>
+
+ <portType name="OrderService">
+ <operation name="submitOrder">
+ <input message="common:submitOrder" />
+ <output message="common:submitOrderResponse" />
+ </operation>
+ </portType>
+
+ <binding name="OrderServiceBinding" type="tns:OrderService">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <operation name="submitOrder">
+ <soap:operation soapAction="urn:switchyard-services:orderservice:1.0" />
+ <input>
+ <soap:body use="literal" />
+ </input>
+ <output>
+ <soap:body use="literal" />
+ </output>
+ </operation>
+ </binding>
+
+ <service name="OrderService">
+ <port name="OrderServicePort" binding="tns:OrderServiceBinding">
+ <soap:address location="http://127.0.0.1:8080/orderservice/OrderServiceWS" />
+ </port>
+ </service>
+</definitions>
@@ -0,0 +1,33 @@
+<xs:schema
+ targetNamespace="urn:switchyard-services:common:1.0"
+ xmlns:tns="urn:switchyard-services:common:1.0"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="submitOrder" type="tns:submitOrderType"/>
+ <xs:element name="submitOrderResponse" type="tns:submitOrderResponseType"/>
+ <xs:element name="order" type="tns:orderType"/>
+ <xs:element name="orderAck" type="tns:orderAckType"/>
+ <xs:complexType name="submitOrderType">
+ <xs:sequence>
+ <xs:element name="order" type="tns:orderType"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="submitOrderResponseType">
+ <xs:sequence>
+ <xs:element name="orderAck" type="tns:orderAckType"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="orderType">
+ <xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="itemId" type="xs:string"/>
+ <xs:element name="quantity" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="orderAckType">
+ <xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="accepted" type="xs:boolean"/>
+ <xs:element name="status" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>

0 comments on commit 73d678f

Please sign in to comment.