You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/09/25 09:50:57 UTC
git commit: CAMEL-7845 Provide Configurer for user to configure the
CXF conduit and CXF destination from Java code
Repository: camel
Updated Branches:
refs/heads/master 40a096da9 -> 40bd0d603
CAMEL-7845 Provide Configurer for user to configure the CXF conduit and CXF destination from Java code
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/40bd0d60
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/40bd0d60
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/40bd0d60
Branch: refs/heads/master
Commit: 40bd0d6031edf16eb253311c447c422e84f3d723
Parents: 40a096d
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Sep 25 15:50:40 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Sep 25 15:50:40 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/cxf/CxfConsumer.java | 4 +++
.../component/cxf/CxfEndpointConfigurer.java | 22 +++++++++++-
.../apache/camel/component/cxf/CxfProducer.java | 4 +++
.../camel/component/cxf/CxfEndpointTest.java | 6 ++++
.../camel/component/cxf/CxfTimeoutTest.java | 38 ++++++++++++++++++++
.../component/cxf/GreeterImplWithSleep.java | 2 +-
.../component/cxf/cxfConduitTimeOutContext.xml | 3 ++
7 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
index 20f1209..4198dfb 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
@@ -260,6 +260,10 @@ public class CxfConsumer extends DefaultConsumer {
});
server = svrBean.create();
+ // Apply the server configurer if it is possible
+ if (cxfEndpoint.getCxfEndpointConfigurer() != null) {
+ cxfEndpoint.getCxfEndpointConfigurer().configureServer(server);
+ }
if (ObjectHelper.isNotEmpty(endpoint.getPublishedEndpointUrl())) {
server.getEndpoint().getEndpointInfo().setProperty("publishedEndpointUrl", endpoint.getPublishedEndpointUrl());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointConfigurer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointConfigurer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointConfigurer.java
index 784ab7f..522269d 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointConfigurer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpointConfigurer.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.cxf;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
/**
@@ -23,6 +25,24 @@ import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
*/
public interface CxfEndpointConfigurer {
- void configure(AbstractWSDLBasedEndpointFactory factoryBean);
+ /**
+ * Configure the CXF Server/Client factory bean
+ * @param factoryBean
+ */
+ void configure(AbstractWSDLBasedEndpointFactory factoryBean);
+
+ /**
+ * Configure the CXF Client such as setting some parameters on the client conduit
+ *
+ * @param client the CXF client
+ */
+ void configureClient(Client client);
+
+ /**
+ * Configure the CXF Server such as setting some parameters on the server destination
+ *
+ * @param server the CXF server
+ */
+ void configureServer(Server server);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
index 8246c4f..70df6e2 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
@@ -75,6 +75,10 @@ public class CxfProducer extends DefaultProducer implements AsyncProcessor {
if (client == null) {
client = endpoint.createClient();
}
+ // Apply the server configurer if it is possible
+ if (endpoint.getCxfEndpointConfigurer() != null) {
+ endpoint.getCxfEndpointConfigurer().configureClient(client);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
index 284f7a4..cc28af0 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
@@ -26,6 +26,8 @@ import org.apache.camel.impl.SimpleRegistry;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
import org.easymock.EasyMock;
import org.junit.Assert;
@@ -105,6 +107,8 @@ public class CxfEndpointTest extends Assert {
configurer.configure(EasyMock.isA(AbstractWSDLBasedEndpointFactory.class));
EasyMock.expectLastCall();
+ configurer.configureServer(EasyMock.isA(Server.class));
+ EasyMock.expectLastCall();
EasyMock.replay(configurer);
endpoint.createConsumer(processor);
EasyMock.verify(configurer);
@@ -112,6 +116,8 @@ public class CxfEndpointTest extends Assert {
EasyMock.reset(configurer);
configurer.configure(EasyMock.isA(AbstractWSDLBasedEndpointFactory.class));
EasyMock.expectLastCall();
+ configurer.configureClient(EasyMock.isA(Client.class));
+ EasyMock.expectLastCall();
EasyMock.replay(configurer);
Producer producer = endpoint.createProducer();
producer.start();
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
index f8cc0e8..1e2efe3 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
@@ -27,6 +27,11 @@ import org.apache.camel.Processor;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.hello_world_soap_http.Greeter;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -67,6 +72,14 @@ public class CxfTimeoutTest extends CamelSpringTestSupport {
}
@Test
+ public void testInvokingJaxWsServerWithCxfEndpointWithConfigurer() throws Exception {
+ Exchange reply = sendJaxWsMessage("cxf://bean:springEndpoint?cxfEndpointConfigurer=#myConfigurer");
+ // we don't expect the exception here
+ assertFalse("We don't expect the exception here", reply.isFailed());
+ assertEquals("Get a wrong response", "Greet Hello World!", reply.getOut().getBody(String.class));
+ }
+
+ @Test
public void testInvokingFromCamelRoute() throws Exception {
sendTimeOutMessage("direct:start");
}
@@ -103,5 +116,30 @@ public class CxfTimeoutTest extends CamelSpringTestSupport {
// we can put the http conduit configuration here
return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml");
}
+
+ public static class MyCxfEndpointConfigurer implements CxfEndpointConfigurer {
+
+ @Override
+ public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
+ // Do nothing here
+ }
+
+ @Override
+ public void configureClient(Client client) {
+ // reset the timeout option to override the spring configuration one
+ HTTPConduit conduit = (HTTPConduit) client.getConduit();
+ HTTPClientPolicy policy = new HTTPClientPolicy();
+ policy.setReceiveTimeout(60000);
+ conduit.setClient(policy);
+
+ }
+
+ @Override
+ public void configureServer(Server server) {
+ // Do nothing here
+
+ }
+
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
index c42bf37..554fbfe 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
@@ -28,6 +28,6 @@ public class GreeterImplWithSleep extends GreeterImpl {
} catch (Exception ignore) {
}
- return "";
+ return "Greet " + hi;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/40bd0d60/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
index 60b0de9..3f34b54 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
@@ -35,6 +35,9 @@
<http-conf:conduit name="*.http-conduit">
<http-conf:client ReceiveTimeout="100" />
</http-conf:conduit>
+
+ <!-- setup the CxfEndpointConfigurer bean here -->
+ <bean id="myConfigurer" class="org.apache.camel.component.cxf.CxfTimeoutTest$MyCxfEndpointConfigurer" />
<cxf:cxfEndpoint id="springEndpoint" address="http://localhost:${CXFTestSupport.port1}/CxfTimeoutTest/SoapContext/SoapPort"
serviceClass="org.apache.hello_world_soap_http.Greeter"/>