[camel] branch master updated: Updated the code snipet for camel-cxfrs component
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git The following commit(s) were added to refs/heads/master by this push: new 39c0d63 Updated the code snipet for camel-cxfrs component 39c0d63 is described below commit 39c0d63d923bfe9236834ecb1c4470bb7e9e7eaa Author: Willem JiangAuthorDate: Sun May 27 15:23:11 2018 +0800 Updated the code snipet for camel-cxfrs component --- .../camel-cxf/src/main/docs/cxfrs-component.adoc | 143 ++--- 1 file changed, 128 insertions(+), 15 deletions(-) diff --git a/components/camel-cxf/src/main/docs/cxfrs-component.adoc b/components/camel-cxf/src/main/docs/cxfrs-component.adoc index 31af57c..1307bde 100644 --- a/components/camel-cxf/src/main/docs/cxfrs-component.adoc +++ b/components/camel-cxf/src/main/docs/cxfrs-component.adoc @@ -244,21 +244,21 @@ Given a JAX-RS resource class with this method: [source,java] -@POST @Path("/customers/{type}") -public Response newCustomer(Customer customer, @PathParam("type") String type, @QueryParam("active") @DefaultValue("true") boolean active) { -return null; -} +@POST @Path("/customers/{type}") +public Response newCustomer(Customer customer, @PathParam("type") String type, @QueryParam("active") @DefaultValue("true") boolean active) { +return null; +} Serviced by the following route: [source,java] -from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer") -.recipientList(simple("direct:${header.operationName}")); +from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer") +.recipientList(simple("direct:${header.operationName}")); -from("direct:newCustomer") -.log("Request: type=${header.type}, active=${header.active}, customerData=${body}"); +from("direct:newCustomer") +.log("Request: type=${header.type}, active=${header.active}, customerData=${body}"); The following HTTP request with XML payload (given that the Customer DTO @@ -294,7 +294,7 @@ implements the https://javaee.github.io/jsr311/[JAX-RS (JSR-311) API], so we can export the resources classes as a REST service. And we leverage the http://cxf.apache.org/docs/invokers.html[CXF Invoker API] to turn a REST request into a normal Java object method -invocation. + +invocation. Unlike the < > component, you don't need to specify the URI template within your endpoint, CXF takes care of the REST request URI to resource class method mapping according to the @@ -302,6 +302,39 @@ JSR-311 specification. All you need to do in Camel is delegate this method request to a right processor or endpoint. Here is an example of a CXFRS route... +[source,java] + +private static final String CXF_RS_ENDPOINT_URI = +"cxfrs://http://localhost:; + CXT + "/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource"; +private static final String CXF_RS_ENDPOINT_URI2 = +"cxfrs://http://localhost:; + CXT + "/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService"; +private static final String CXF_RS_ENDPOINT_URI3 = +"cxfrs://http://localhost:; + CXT + "/rest3?" ++ "resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceNoAnnotations&" ++ "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceModel.xml"; +private static final String CXF_RS_ENDPOINT_URI4 = +"cxfrs://http://localhost:; + CXT + "/rest4?" ++ "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml"; +private static final String CXF_RS_ENDPOINT_URI5 = +"cxfrs://http://localhost:; + CXT + "/rest5?" ++ "propagateContexts=true&" ++ "modelRef=classpath:/org/apache/camel/component/cxf/jaxrs/CustomerServiceDefaultHandlerModel.xml"; +protected RouteBuilder createRouteBuilder() throws Exception { +final Processor testProcessor = new TestProcessor(); +final Processor testProcessor2 = new TestProcessor2(); +final Processor testProcessor3 = new TestProcessor3(); +return new RouteBuilder() { +public void configure() { +errorHandler(new NoErrorHandlerBuilder()); +from(CXF_RS_ENDPOINT_URI).process(testProcessor); +from(CXF_RS_ENDPOINT_URI2).process(testProcessor); +
[camel] branch camel-2.21.x updated: CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch camel-2.21.x in repository https://gitbox.apache.org/repos/asf/camel.git The following commit(s) were added to refs/heads/camel-2.21.x by this push: new 2efdb01 CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer 2efdb01 is described below commit 2efdb0149f0e9eb39ac605f57dbae06650c3cd36 Author: Willem JiangAuthorDate: Sun May 27 13:58:47 2018 +0800 CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer --- .../camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java | 1 + .../org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java| 10 +- .../apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java | 2 ++ .../cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java | 4 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java index e9cd9b9..d6a3d50 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java @@ -91,6 +91,7 @@ public class CxfRsBlueprintEndpoint extends CxfRsEndpoint { @Override protected JAXRSClientFactoryBean newJAXRSClientFactoryBean() { checkBeanType(bean, JAXRSClientFactoryBean.class); +// TODO Need to find a way to setup the JAXRSClientFactory Bean, as the JAXRSClientFactoryBean properties could be changed by the configurer return (RsClientBlueprintBean)bean; } diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java index 015918a..69e2471 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java @@ -266,7 +266,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate getNullSafeCxfRsEndpointConfigurer().configure(sfb); } -private CxfRsEndpointConfigurer getNullSafeCxfRsEndpointConfigurer() { +protected CxfRsEndpointConfigurer getNullSafeCxfRsEndpointConfigurer() { if (cxfRsEndpointConfigurer == null) { return new ChainedCxfRsEndpointConfigurer.NullCxfRsEndpointConfigurer(); } @@ -304,10 +304,6 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate } protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) { -// address -if (address != null) { -cfb.setAddress(address); -} if (modelRef != null) { cfb.setModelRef(modelRef); } @@ -318,6 +314,10 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate setupCommonFactoryProperties(cfb); cfb.setThreadSafe(true); getNullSafeCxfRsEndpointConfigurer().configure(cfb); +// Add the address could be override by message header +if (address != null) { +cfb.setAddress(address); +} } protected void setupCommonFactoryProperties(AbstractJAXRSFactoryBean factory) { diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java index d10d6c5..954d984 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java @@ -75,6 +75,8 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware { @Override protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) { configurer.configureBean(beanId, cfb); +// support to call the configurer here +getNullSafeCxfRsEndpointConfigurer().configure(cfb); cfb.setAddress(address); cfb.setThreadSafe(true); } diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java index dbca65a..46dbc2f 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java
[camel] branch master updated: CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer
This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git The following commit(s) were added to refs/heads/master by this push: new fad1385 CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer fad1385 is described below commit fad138527a0e4dd7947c7cc7ee1ae1861cd4bc59 Author: Willem JiangAuthorDate: Sun May 27 13:58:47 2018 +0800 CAMEL-12540 Avoid the address setting of CxfRsEndpointConfigurer --- .../camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java | 1 + .../org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java| 10 +- .../apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java | 2 ++ .../cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java | 4 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java index e9cd9b9..d6a3d50 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsBlueprintEndpoint.java @@ -91,6 +91,7 @@ public class CxfRsBlueprintEndpoint extends CxfRsEndpoint { @Override protected JAXRSClientFactoryBean newJAXRSClientFactoryBean() { checkBeanType(bean, JAXRSClientFactoryBean.class); +// TODO Need to find a way to setup the JAXRSClientFactory Bean, as the JAXRSClientFactoryBean properties could be changed by the configurer return (RsClientBlueprintBean)bean; } diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java index 1daa8d1..803b8f3 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java @@ -266,7 +266,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate getNullSafeCxfRsEndpointConfigurer().configure(sfb); } -private CxfRsEndpointConfigurer getNullSafeCxfRsEndpointConfigurer() { +protected CxfRsEndpointConfigurer getNullSafeCxfRsEndpointConfigurer() { if (cxfRsEndpointConfigurer == null) { return new ChainedCxfRsEndpointConfigurer.NullCxfRsEndpointConfigurer(); } @@ -304,10 +304,6 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate } protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) { -// address -if (address != null) { -cfb.setAddress(address); -} if (modelRef != null) { cfb.setModelRef(modelRef); } @@ -318,6 +314,10 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate setupCommonFactoryProperties(cfb); cfb.setThreadSafe(true); getNullSafeCxfRsEndpointConfigurer().configure(cfb); +// Add the address could be override by message header +if (address != null) { +cfb.setAddress(address); +} } protected void setupCommonFactoryProperties(AbstractJAXRSFactoryBean factory) { diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java index d10d6c5..954d984 100644 --- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java +++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java @@ -75,6 +75,8 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware { @Override protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) { configurer.configureBean(beanId, cfb); +// support to call the configurer here +getNullSafeCxfRsEndpointConfigurer().configure(cfb); cfb.setAddress(address); cfb.setThreadSafe(true); } diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java index 7f821f5..94c26d4 100644 --- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerEndpointConfigurerTest.java @@ -67,6