Repository: camel Updated Branches: refs/heads/master a0909f8f7 -> f5849f000
Added the holder of soap header unit test into camel-cxf module Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f5849f00 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5849f00 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5849f00 Branch: refs/heads/master Commit: f5849f0002b25ad252ba752da8fab2aa2f716229 Parents: a0909f8 Author: Willem Jiang <[email protected]> Authored: Sun May 4 10:49:58 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Sun May 4 10:50:14 2014 +0800 ---------------------------------------------------------------------- .../cxf/holder/CXFHolderRouteTest.java | 23 +-------- .../cxf/holder/CxfHolderConsumerTest.java | 43 ++++++++-------- .../component/cxf/holder/MyOrderEndpoint.java | 10 ++++ .../camel/component/cxf/holder/MyOrderType.java | 27 ++++++++++ .../camel/component/cxf/holder/MyProcessor.java | 53 ++++++++++++++++++++ 5 files changed, 114 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f5849f00/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CXFHolderRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CXFHolderRouteTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CXFHolderRouteTest.java index 6dc12e7..8c9c0a7 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CXFHolderRouteTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CXFHolderRouteTest.java @@ -16,13 +16,6 @@ */ package org.apache.camel.component.cxf.holder; -import java.util.List; - -import javax.xml.ws.Holder; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; public class CXFHolderRouteTest extends CxfHolderConsumerTest { @@ -30,20 +23,8 @@ public class CXFHolderRouteTest extends CxfHolderConsumerTest { protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { - from(CXF_ENDPOINT_URI).wireTap("seda:tap").process(new Processor() { - @SuppressWarnings("unchecked") - public void process(Exchange exchange) throws Exception { - Message in = exchange.getIn(); - List<Object> parameters = in.getBody(List.class); - int amount = (Integer) parameters.remove(1); - Holder<String> customer = (Holder<String>)parameters.get(1); - if (customer.value.length() == 0) { - customer.value = "newCustomer"; - } - parameters.add(0, "Ordered ammount " + amount); - exchange.getOut().setBody(parameters); - } - }); + from(CXF_ENDPOINT_URI).wireTap("seda:tap").process(new MyProcessor()); + from("seda:tap").to("log:myEndpoint"); } }; http://git-wip-us.apache.org/repos/asf/camel/blob/f5849f00/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CxfHolderConsumerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CxfHolderConsumerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CxfHolderConsumerTest.java index e413c71..dca697a 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CxfHolderConsumerTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/CxfHolderConsumerTest.java @@ -16,13 +16,8 @@ */ package org.apache.camel.component.cxf.holder; -import java.util.List; - import javax.xml.ws.Holder; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.cxf.CXFTestSupport; import org.apache.camel.test.junit4.CamelTestSupport; @@ -34,27 +29,14 @@ public class CxfHolderConsumerTest extends CamelTestSupport { protected static final String ADDRESS = "http://localhost:" + CXFTestSupport.getPort1() + "/CxfHolderConsumerTest/test"; protected static final String CXF_ENDPOINT_URI = "cxf://" + ADDRESS - + "?serviceClass=org.apache.camel.component.cxf.holder.MyOrderEndpoint"; + + "?serviceClass=org.apache.camel.component.cxf.holder.MyOrderEndpoint" + + "&loggingFeatureEnabled=true"; protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { - from(CXF_ENDPOINT_URI).process(new Processor() { - @SuppressWarnings("unchecked") - public void process(Exchange exchange) throws Exception { - Message in = exchange.getIn(); - List<Object> parameters = in.getBody(List.class); - int amount = (Integer) parameters.remove(1); - Holder<String> customer = (Holder<String>)parameters.get(1); - if (customer.value.length() == 0) { - customer.value = "newCustomer"; - } - parameters.add(0, "Ordered ammount " + amount); - //reuse the MessageContentList at this time to test CAMEL-4113 - exchange.getOut().setBody(parameters); - } - }); + from(CXF_ENDPOINT_URI).process(new MyProcessor()); } }; } @@ -79,5 +61,24 @@ public class CxfHolderConsumerTest extends CamelTestSupport { assertEquals("Get a wrong parts", "parts", strPart.value); assertEquals("Get a wrong customer", "newCustomer", strCustomer.value); } + + + @Test + public void testInvokingServiceWithSoapHeaderFromCXFClient() throws Exception { + JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); + ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean(); + clientBean.setAddress(ADDRESS); + clientBean.setServiceClass(MyOrderEndpoint.class); + + MyOrderEndpoint client = (MyOrderEndpoint) proxyFactory.create(); + + Holder<String> header = new Holder<String>(); + header.value = "parts"; + + String result = client.mySecureOrder(1, header); + assertEquals("Get a wrong order result", "Ordered ammount 1", result); + assertEquals("Get a wrong parts", "secureParts", header.value); + + } } http://git-wip-us.apache.org/repos/asf/camel/blob/f5849f00/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderEndpoint.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderEndpoint.java index f96668e..9c0d77a 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderEndpoint.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderEndpoint.java @@ -16,10 +16,20 @@ */ package org.apache.camel.component.cxf.holder; +import javax.jws.WebParam; import javax.jws.WebService; +import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.ws.Holder; +import javax.xml.ws.RequestWrapper; @WebService +@XmlSeeAlso({MyOrderType.class}) public interface MyOrderEndpoint { String myOrder(Holder<String> strPart, int iAmount, Holder<String> strCustomer); + @RequestWrapper(className = "org.apache.camel.component.cxf.holder.MyOrderType") + String mySecureOrder( + @WebParam(name = "iAmount") + int iAmount, + @WebParam(mode = WebParam.Mode.INOUT, name = "ENVELOPE_HEADER", header = true) + Holder<String> envelopeHeader); } http://git-wip-us.apache.org/repos/asf/camel/blob/f5849f00/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderType.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderType.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderType.java new file mode 100644 index 0000000..1c4d85d --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyOrderType.java @@ -0,0 +1,27 @@ +/** + * 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.holder; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +@XmlAccessorType(XmlAccessType.FIELD) +public class MyOrderType { + @XmlElement(required = true) + protected int iAmount; +} http://git-wip-us.apache.org/repos/asf/camel/blob/f5849f00/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyProcessor.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyProcessor.java new file mode 100644 index 0000000..94989b6 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/holder/MyProcessor.java @@ -0,0 +1,53 @@ +/** + * 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.holder; + +import java.util.List; + +import javax.xml.ws.Holder; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.component.cxf.common.message.CxfConstants; + +public class MyProcessor implements Processor { + @SuppressWarnings("unchecked") + public void process(Exchange exchange) throws Exception { + Message in = exchange.getIn(); + if (in.getHeader(CxfConstants.OPERATION_NAME).equals("myOrder")) { + List<Object> parameters = in.getBody(List.class); + int amount = (Integer) parameters.remove(1); + Holder<String> customer = (Holder<String>)parameters.get(1); + if (customer.value.length() == 0) { + customer.value = "newCustomer"; + } + parameters.add(0, "Ordered ammount " + amount); + //reuse the MessageContentList at this time to test CAMEL-4113 + exchange.getOut().setBody(parameters); + } else { + List<Object> parameters = in.getBody(List.class); + System.out.println(parameters); + int amount = (Integer) parameters.remove(0); + Holder<String> securityOrder = (Holder<String>)parameters.get(0); + securityOrder.value = "secureParts"; + parameters.add(0, "Ordered ammount " + amount); + //reuse the MessageContentList at this time to test CAMEL-4113 + exchange.getOut().setBody(parameters); + } + } +}
