Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 58D2717BDF for ; Wed, 9 Sep 2015 05:20:38 +0000 (UTC) Received: (qmail 48484 invoked by uid 500); 9 Sep 2015 05:20:38 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 48429 invoked by uid 500); 9 Sep 2015 05:20:37 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 48420 invoked by uid 99); 9 Sep 2015 05:20:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Sep 2015 05:20:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AA65AE01F5; Wed, 9 Sep 2015 05:20:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ffang@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: [CAMEL-7921]parse wsdl to find the only servicename if there's no one explicitly specified Date: Wed, 9 Sep 2015 05:20:37 +0000 (UTC) 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 Authored: Wed Sep 9 13:20:23 2015 +0800 Committer: Freeman Fang 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 @@ ${basedir}/src/test/resources/person.wsdl + ${basedir}/src/test/resources/order.wsdl + + ${basedir}/src/test/resources/person-non-wrapper.wsdl -b 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 = "" + + "" + + ""; + + @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 params = new ArrayList(); + 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +