From 80be0842ea7696066c7d570cc537e270d738d503 Mon Sep 17 00:00:00 2001 From: xldai Date: Sat, 10 Feb 2018 14:41:24 +0800 Subject: [PATCH] fix CAMEL-12252 and add test case for it --- .../component/cxf/jaxrs/CxfRsProducer.java | 1 + .../CxfRsProducerAddressOverrideTest.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) 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 fa9978c71b334..b04a6a7be92c9 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 4690778bcd24f..9c5f0083e4bc6 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); + } + } }