You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/05/15 09:43:20 UTC
[camel] branch camel-2.23.x updated: CAMEL-13513 Test and fix
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.23.x by this push:
new c710131 CAMEL-13513 Test and fix
c710131 is described below
commit c7101312015645575bbdb9ec71fb004ec484774a
Author: Antonio Gagliardi <ag...@agagliar.remote.csb>
AuthorDate: Mon May 13 18:11:57 2019 +0200
CAMEL-13513 Test and fix
---
.../cxf/jaxrs/CxfRsBlueprintEndpoint.java | 15 +++++--
.../test/cxf/blueprint/CxfRsEndpointBeansTest.java | 49 +++++++++++++++++++++-
.../test/cxf/blueprint/CxfRsEndpointBeans.xml | 19 +++++++++
3 files changed, 79 insertions(+), 4 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 d6a3d50..cfb7811 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
@@ -26,6 +26,7 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.osgi.framework.BundleContext;
import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.springframework.util.ReflectionUtils;
public class CxfRsBlueprintEndpoint extends CxfRsEndpoint {
private AbstractJAXRSFactoryBean bean;
@@ -91,9 +92,17 @@ 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;
+ return (RsClientBlueprintBean)newInstanceWithCommonProperties();
+ }
+
+ private RsClientBlueprintBean newInstanceWithCommonProperties() {
+ RsClientBlueprintBean cfb = new RsClientBlueprintBean();
+
+ if (bean instanceof RsClientBlueprintBean) {
+ ReflectionUtils.shallowCopyFieldState(bean, cfb);
+ }
+
+ return cfb;
}
-
}
diff --git a/tests/camel-blueprint-cxf-test/src/test/java/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeansTest.java b/tests/camel-blueprint-cxf-test/src/test/java/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeansTest.java
index 7f2131d..bf6d752 100644
--- a/tests/camel-blueprint-cxf-test/src/test/java/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeansTest.java
+++ b/tests/camel-blueprint-cxf-test/src/test/java/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeansTest.java
@@ -16,14 +16,28 @@
*/
package org.apache.camel.test.cxf.blueprint;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.ws.rs.ProcessingException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.jaxrs.CxfRsEndpoint;
+import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.junit.Assert;
import org.junit.Test;
public class CxfRsEndpointBeansTest extends CamelBlueprintTestSupport {
+ @Produce(uri = "direct:startURLOverride")
+ private ProducerTemplate pT;
+
@Override
protected String getBlueprintDescriptor() {
return "org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeans.xml";
@@ -43,7 +57,40 @@ public class CxfRsEndpointBeansTest extends CamelBlueprintTestSupport {
JAXRSClientFactoryBean client = serviceEndpoint.createJAXRSClientFactoryBean();
assertEquals("These cxfrs endpoints don't share the same bus", server.getBus().getId(), client.getBus().getId());
}
-
+ @Test
+ public void testDestinationOverrideURLHandling() {
+
+ try {
+ context.getRouteController().startRoute("url-override-route");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ List<String> expected = Arrays.asList(
+ "foo1",
+ "foo2",
+ "foo1",
+ "foo2",
+ "foo1");
+
+ expected.forEach(host -> pT.send(exchange -> {
+ Message in = exchange.getIn();
+ in.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, false);
+ in.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
+ in.setBody("Scott");
+ in.setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
+ in.setHeader(Exchange.DESTINATION_OVERRIDE_URL, "http://" + host);
+ in.setHeader(Exchange.HTTP_METHOD, "GET");
+ }));
+
+ MockEndpoint mockEndpoint = getMockEndpoint("mock:resultURLOverride");
+ Assert.assertArrayEquals(expected.toArray(),
+ mockEndpoint.getExchanges().stream()
+ .map(exchange -> exchange.getProperty(Exchange.EXCEPTION_CAUGHT, ProcessingException.class).getCause().toString())
+ .map(exceptionMessage -> exceptionMessage.split("\\: ")[1])
+ .collect(Collectors.toList()).toArray());
+
+ }
}
diff --git a/tests/camel-blueprint-cxf-test/src/test/resources/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeans.xml b/tests/camel-blueprint-cxf-test/src/test/resources/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeans.xml
index 592cdc8..71da6c8 100644
--- a/tests/camel-blueprint-cxf-test/src/test/resources/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeans.xml
+++ b/tests/camel-blueprint-cxf-test/src/test/resources/org/apache/camel/test/cxf/blueprint/CxfRsEndpointBeans.xml
@@ -45,6 +45,13 @@
</cxf:providers>
</cxf:rsClient>
+ <cxf:rsClient id="restClient" address="http://foo"
+ serviceClass="org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource"
+ loggingFeatureEnabled="true">
+ <cxf:providers>
+ <ref component-id="jsonProvider" />
+ </cxf:providers>
+ </cxf:rsClient>
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider" />
@@ -55,6 +62,18 @@
<camel:to uri="mock:result" />
</camel:route>
+
+ <camel:route autostart="false" id="url-override-route">
+
+ <camel:onException>
+ <camel:exception>javax.ws.rs.ProcessingException</camel:exception>
+ <camel:to uri="mock:resultURLOverride" />
+ </camel:onException>
+
+ <camel:from uri="direct:startURLOverride" />
+ <camel:to uri="cxfrs:bean:restClient" />
+ </camel:route>
+
</camel:camelContext>
</blueprint>