You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2018/03/18 22:14:33 UTC
[camel] branch camel-2.21.x updated: CAMEL-12252: Corrected a bug
in the URL override mechanism
This is an automated email from the ASF dual-hosted git repository.
aldettinger 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 603852f CAMEL-12252: Corrected a bug in the URL override mechanism
603852f is described below
commit 603852f5638d5ad5a0ef46bb25f27c6d2a278964
Author: aldettinger <al...@gmail.com>
AuthorDate: Thu Mar 15 20:19:02 2018 +0100
CAMEL-12252: Corrected a bug in the URL override mechanism
(cherry picked from commit c71744c21aa2df50b49a4dac69e04bbee99c26da)
---
.../component/cxf/jaxrs/CxfRsSpringEndpoint.java | 39 +++++++++----
.../jaxrs/CxfRsProducerAddressOverrideTest.java | 65 ++++++++++++++++++----
2 files changed, 81 insertions(+), 23 deletions(-)
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 fa96d3c..d10d6c5 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
@@ -18,25 +18,31 @@
package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.Component;
+import org.apache.camel.component.cxf.spring.SpringJAXRSClientFactoryBean;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.cxf.configuration.spring.ConfigurerImpl;
import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.springframework.context.ApplicationContext;
public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware {
private AbstractJAXRSFactoryBean bean;
+ private ConfigurerImpl configurer;
private String beanId;
-
- @Deprecated
+
+ @Deprecated
/**
* It will be removed in Camel 3.0
+ *
* @param comp
* @param bean
*/
public CxfRsSpringEndpoint(Component component, AbstractJAXRSFactoryBean bean) throws Exception {
- super(bean.getAddress(), component);
+ super(bean.getAddress(), component);
init(bean);
}
-
+
public CxfRsSpringEndpoint(Component component, String uri, AbstractJAXRSFactoryBean bean) throws Exception {
super(uri, component);
setAddress(bean.getAddress());
@@ -44,31 +50,40 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware {
bean.setAddress(getAddress());
init(bean);
}
-
+
private void init(AbstractJAXRSFactoryBean bean) {
this.bean = bean;
if (bean instanceof BeanIdAware) {
setBeanId(((BeanIdAware)bean).getBeanId());
}
+
+ ApplicationContext applicationContext = ((SpringCamelContext)getCamelContext()).getApplicationContext();
+ configurer = new ConfigurerImpl(applicationContext);
}
-
+
@Override
protected JAXRSServerFactoryBean newJAXRSServerFactoryBean() {
checkBeanType(bean, JAXRSServerFactoryBean.class);
return (JAXRSServerFactoryBean)bean;
}
-
+
@Override
protected JAXRSClientFactoryBean newJAXRSClientFactoryBean() {
- checkBeanType(bean, JAXRSClientFactoryBean.class);
- return (JAXRSClientFactoryBean)bean;
+ return new SpringJAXRSClientFactoryBean();
}
-
+
+ @Override
+ protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) {
+ configurer.configureBean(beanId, cfb);
+ cfb.setAddress(address);
+ cfb.setThreadSafe(true);
+ }
+
public String getBeanId() {
return beanId;
}
-
- public void setBeanId(String id) {
+
+ public void setBeanId(String id) {
this.beanId = id;
}
}
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
index 4690778..9f9d5c3 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerAddressOverrideTest.java
@@ -30,7 +30,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
private static int port1 = CXFTestSupport.getPort1();
- private static int port2 = CXFTestSupport.getPort("CxfRsProducerAddressOverrideTest.jetty");
+ private static int port2 = CXFTestSupport.getPort("CxfRsProducerAddressOverrideTest.jetty");
public int getPort1() {
return port1;
}
@@ -39,7 +39,7 @@ public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
}
@Override
- protected AbstractXmlApplicationContext createApplicationContext() {
+ protected AbstractXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml");
}
@@ -84,7 +84,7 @@ public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
// set the Http method
inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
// set the relative path
- inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
// Specify the response class , cxfrs will use InputStream as the response object type
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
setupDestinationURL(inMessage);
@@ -115,7 +115,7 @@ public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
setupDestinationURL(inMessage);
}
});
-
+
// get the response message
Customer response = (Customer) exchange.getOut().getBody();
@@ -123,7 +123,7 @@ public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
assertEquals("Get a wrong customer id ", 123, response.getId());
assertEquals("Get a wrong customer name", "John", response.getName());
}
-
+
@Test
public void testGetCustomerWithAsyncHttpAPIByOverrideDest() {
Exchange exchange = template.send("cxfrs:bean:rsClientHttp", new Processor() {
@@ -135,18 +135,61 @@ public class CxfRsProducerAddressOverrideTest extends CamelSpringTestSupport {
// set the Http method
inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
// set the relative path
- inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
- // Specify the response class , cxfrs will use InputStream as the response object type
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
+ // Specify the response class , cxfrs will use InputStream as
+ // the response object type
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
setupDestinationURL(inMessage);
}
});
-
- // get the response message
- Customer response = (Customer) exchange.getOut().getBody();
-
+
+ // get the response message
+ Customer response = (Customer)exchange.getOut().getBody();
+
assertNotNull("The response should not be null", response);
assertEquals("Get a wrong customer id ", 123, response.getId());
assertEquals("Get a wrong customer name", "John", response.getName());
}
+
+ @Test
+ public void testAddressMultiOverride() {
+ // First call with override url
+ Exchange exchange = template.send("direct://http", new SendProcessor("http://localhost:" + getPort1() + "/CxfRsProducerAddressOverrideTest"));
+ // get the response message
+ Customer response = exchange.getOut().getBody(Customer.class);
+ assertNotNull("The response should not be null ", response);
+
+ // Second call with override url
+ exchange = template.send("direct://http", new SendProcessor("http://localhost:" + getPort1() + "/CxfRsProducerNonExistingAddressOverrideTest"));
+
+ // Third call with override url ( we reuse the first url there )
+ exchange = template.send("direct://http", new SendProcessor("http://localhost:" + getPort1() + "/CxfRsProducerAddressOverrideTest"));
+ // get the response message
+ response = exchange.getOut().getBody(Customer.class);
+ assertNotNull("The response should not be null ", response);
+ }
+
+ class SendProcessor implements Processor {
+ private String address;
+
+ public SendProcessor(String address) {
+ this.address = address;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ Message inMessage = exchange.getIn();
+
+ // using the http central client API
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
+ // set the Http method
+ inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
+ // set the relative path
+ inMessage.setHeader(Exchange.HTTP_PATH, "/customerservice/customers/123");
+ // Specify the response class , cxfrs will use InputStream as the
+ // response object type
+ inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
+ inMessage.setHeader(Exchange.DESTINATION_OVERRIDE_URL, address);
+ }
+ }
}
--
To stop receiving notification emails like this one, please contact
aldettinger@apache.org.