camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject camel git commit: [CAMEL-7921]parse wsdl to find the only servicename if there's no one explicitly specified
Date Wed, 09 Sep 2015 05:20:37 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x dc08c76e7 -> 843ef83f8


[CAMEL-7921]parse wsdl to find the only servicename if there's no one explicitly specified


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/843ef83f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/843ef83f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/843ef83f

Branch: refs/heads/camel-2.14.x
Commit: 843ef83f83f0fae7767d8e511573be32a172a660
Parents: dc08c76
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Wed Sep 9 13:20:23 2015 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Wed Sep 9 13:20:23 2015 +0800

----------------------------------------------------------------------
 components/camel-cxf/pom.xml                    |  3 +
 .../apache/camel/component/cxf/CxfEndpoint.java | 23 ++++++
 .../cxf/CxfProducerSoapActionTest.java          | 87 ++++++++++++++++++++
 .../camel-cxf/src/test/resources/order.wsdl     | 75 +++++++++++++++++
 4 files changed, 188 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/843ef83f/components/camel-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/pom.xml b/components/camel-cxf/pom.xml
index ab66d4f..48b4a2d 100644
--- a/components/camel-cxf/pom.xml
+++ b/components/camel-cxf/pom.xml
@@ -367,6 +367,9 @@
                   <wsdl>${basedir}/src/test/resources/person.wsdl</wsdl>
                 </wsdlOption>
                 <wsdlOption>
+                  <wsdl>${basedir}/src/test/resources/order.wsdl</wsdl>
+                </wsdlOption>
+                <wsdlOption>
                   <wsdl>${basedir}/src/test/resources/person-non-wrapper.wsdl</wsdl>
                   <extraargs>
                     <extraarg>-b</extraarg>

http://git-wip-us.apache.org/repos/asf/camel/blob/843ef83f/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
index c116117..635938a 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
@@ -25,6 +25,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
@@ -100,6 +102,7 @@ import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxSource;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.wsdl.WSDLManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -491,6 +494,8 @@ public class CxfEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
         if (getServiceName() != null) {
             factoryBean.setServiceName(getServiceName());
         }
+        
+        
 
         // port name qname
         if (getPortName() != null) {
@@ -754,6 +759,24 @@ public class CxfEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
         if (serviceName == null && serviceNameString != null) {
             serviceName = QName.valueOf(resolvePropertyPlaceholders(serviceNameString));
         }
+        //if not specify the service name and if the wsdlUrl is available,
+        //parse the wsdl to see if only one service in it, if so set the only service
+        //from wsdl to avoid ambiguity
+        if (serviceName == null && getWsdlURL() != null) {
+            // use wsdl manager to parse wsdl or get cached
+            // definition
+            try {
+                Definition definition = getBus().getExtension(WSDLManager.class)
+                        .getDefinition(getWsdlURL());
+                if (definition.getServices().size() == 1) {
+                    serviceName = (QName) definition.getServices().keySet()
+                        .iterator().next();
+                    
+                }
+            } catch (WSDLException e) {
+                throw new RuntimeException(e);
+            }
+        }
         return serviceName;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/843ef83f/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerSoapActionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerSoapActionTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerSoapActionTest.java
new file mode 100644
index 0000000..178a425
--- /dev/null
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerSoapActionTest.java
@@ -0,0 +1,87 @@
+/** 
+* 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.camel.component.cxf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.cxf.binding.soap.SoapBindingConstants;
+import org.junit.Test;
+
+public class CxfProducerSoapActionTest extends CamelTestSupport {
+	
+	private static final String SOAP_ACTION = "http://camel.apache.org/order/Order";
+	private static final String OPERATION_NAMESPACE = "http://camel.apache.org/order";
+	private static final String OPERATION_NAME = "order";
+	private static final String DIRECT_START = "direct:start";
+	private static final String CXF_ENDPOINT = "cxf:http://localhost:9000/order?wsdlURL=classpath:order.wsdl&loggingFeatureEnabled=true";
+	private static final String REQUEST_MESSAGE = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+			+ "<Body/>"
+			+ "</Envelope>";
+
+	@Test
+	public void testSendSoapRequestWithoutSoapActionSet() {
+		template.requestBody(DIRECT_START, REQUEST_MESSAGE, String.class);
+	}
+	
+	
+	protected RouteBuilder createRouteBuilder() {
+		return new RouteBuilder() {
+
+			@Override
+			public void configure() throws Exception {
+				from(DIRECT_START)
+				.setHeader(CxfConstants.OPERATION_NAME, constant(OPERATION_NAME))
+				.setHeader(CxfConstants.OPERATION_NAMESPACE, constant(OPERATION_NAMESPACE))
+				.process(new Processor() {
+
+					@Override
+					public void process(Exchange exchange) throws Exception {
+						
+						final List<Object> params = new ArrayList<Object>();
+						params.add("foo");
+						params.add(10);
+						params.add("bar");
+												
+						exchange.getIn().setBody(params);
+						
+					}
+				})
+				.to("log:org.apache.camel?level=DEBUG")
+				.to(CXF_ENDPOINT + "&serviceClass=org.apache.camel.order.OrderEndpoint");
+				
+				from(CXF_ENDPOINT + "&dataFormat=POJO&serviceClass=org.apache.camel.order.OrderEndpoint")
+				.process(new Processor() {
+					
+					@Override
+					public void process(Exchange exchange) throws Exception {
+						String soapAction = exchange.getIn().getHeader(SoapBindingConstants.SOAP_ACTION, String.class);
+						assertEquals(SOAP_ACTION, soapAction);
+						
+					}
+				});
+			}
+			
+		};
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/843ef83f/components/camel-cxf/src/test/resources/order.wsdl
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/order.wsdl b/components/camel-cxf/src/test/resources/order.wsdl
new file mode 100644
index 0000000..5656b3f
--- /dev/null
+++ b/components/camel-cxf/src/test/resources/order.wsdl
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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://camel.apache.org/order"
+	xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+	targetNamespace="http://camel.apache.org/order">
+
+  <!-- Type definitions for input- and output parameters for webservice -->
+  <wsdl:types>
+    <xs:schema targetNamespace="http://camel.apache.org/order">
+      <xs:element type="xs:string" name="partName" />
+      <xs:element type="xs:int" name="amount" />
+      <xs:element type="xs:string" name="customerName" />
+      <xs:element type="xs:string" name="resultCode" />
+    </xs:schema>
+  </wsdl:types>
+
+  <!-- Message definitions for input and output -->
+  <wsdl:message name="purchaseOrder">
+    <wsdl:part name="partName" element="tns:partName" />
+    <wsdl:part name="amount" element="tns:amount"/>
+    <wsdl:part name="customerName" element="tns:customerName"/>
+  </wsdl:message>
+  <wsdl:message name="orderResult">
+    <wsdl:part name="resultCode" element="tns:resultCode" />
+  </wsdl:message>
+
+  <!-- Port (interface) definitions -->
+  <wsdl:portType name="OrderEndpoint">
+    <wsdl:operation name="order">
+      <wsdl:input message="tns:purchaseOrder" />
+      <wsdl:output message="tns:orderResult" />
+    </wsdl:operation>
+  </wsdl:portType>
+
+  <!-- Port bindings to transports and encoding - HTTP, document literal encoding is used
-->
+  <wsdl:binding name="OrderBinding" type="tns:OrderEndpoint">
+    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
+    <wsdl:operation name="order">
+      <soap:operation soapAction="http://camel.apache.org/order/Order" style="document"
/>
+      <wsdl:input>
+        <soap:body parts="in" use="literal" />
+      </wsdl:input>
+      <wsdl:output>
+        <soap:body parts="out" use="literal" />
+      </wsdl:output>
+    </wsdl:operation>
+  </wsdl:binding>
+
+  <!-- Service definition -->
+  <wsdl:service name="MyOrderEndpointService">
+    <wsdl:port name="OrderService" binding="tns:OrderBinding">
+      <soap:address location="http://localhost:9000/order" />
+    </wsdl:port>
+  </wsdl:service>
+
+</wsdl:definitions>


Mime
View raw message