[ 
https://issues.apache.org/jira/browse/CAMEL-12252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16403569#comment-16403569
 ] 

ASF GitHub Bot commented on CAMEL-12252:
----------------------------------------

aldettinger closed pull request #2218: fix CAMEL-12252 and add test case for it
URL: https://github.com/apache/camel/pull/2218
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index fa9978c71b3..b04a6a7be92 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -865,6 +865,7 @@ public JAXRSClientFactoryBean get(String address) throws 
Exception {
                     LOG.trace("Created client factory bean and add to cache 
for address '{}'", address);
                     
                 } else {
+                    retVal.setAddress(address);
                     LOG.trace("Retrieved client factory bean from cache for 
address '{}'", address);
                 }
             }
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 4690778bcd2..9c5f0083e4b 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
@@ -149,4 +149,47 @@ public void process(Exchange exchange) throws Exception {
         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 = (Customer) exchange.getOut().getBody();
+        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
+        exchange = template.send("direct://http",
+            new SendProcessor("http://localhost:"; + getPort1() + 
"/CxfRsProducerAddressOverrideTest"));
+        // get the response message
+        response = (Customer) exchange.getOut().getBody();
+        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);
+        }
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Dynamic setting the DESTINATION_OVERRIDE_URL doesn't work on CXFRS producer
> ---------------------------------------------------------------------------
>
>                 Key: CAMEL-12252
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12252
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-cxfrs
>    Affects Versions: 2.17.0, 2.18.5, 2.19.4, 2.20.2
>         Environment: Java 8
>            Reporter: Xilai Dai
>            Assignee: Alex Dettinger
>            Priority: Major
>
> Given the sample MyProcessor, setting the DESTINATION_OVERRIDE_URL 
> dynamically during the invoke:
> {code}
> public void process(Exchange exchange) throws Exception {
>     String env = (String)exchange.getIn().getHeader("Environnement");
>     if (env.equalsIgnoreCase("DEV")) {
>         exchange.getIn().setHeader(exchange.DESTINATION_OVERRIDE_URL,
>             "http://esbdev11.local:8080/server1/metaServlet";);
>     } else {
>         exchange.getIn().setHeader(exchange.DESTINATION_OVERRIDE_URL,
>             "http://esblab11.local:8080/server2/metaServlet";);
>     }
> }
> {code}
> Given the sample Route:
> {code}
>         from("cxfrs:bean:MyREST")
>         .process(new HeaderProcessor())
>         .setHeader("Environnement")
>         .simple("${header.http_query[env][0]}")
>         .process(new MyProcessor())
>         .setHeader(org.apache.camel.Exchange.HTTP_METHOD, constant("GET"))
>         .setHeader(org.apache.camel.Exchange.ACCEPT_CONTENT_TYPE, 
> constant("*/*"))
>         .setHeader(org.apache.camel.Exchange.HTTP_PATH, constant("/"))
>         .to("cxfrs:bean:restClient?maxClientCacheSize=5");
> {code}
> Send request to cxfrs:bean:MyREST with different http header "dev", then the 
> cxfrs:bean:restClient always make call to the last setting Address.
> (Only it works as expected when setting maxClientCacheSize=0 on the 
> cxfrs:bean:restClient)
> There is no this issue on Camel 2.16.x, but start problem from Camel 2.17.x 
> and later versions. Investigations show that the CxfRsEndpoint becoming 
> Singleton after CAMEL-9628, that explain why the last Address setting always 
> applied.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to