You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/03/03 10:45:04 UTC
[2/2] git commit: CAMEL-7229 Fixed the issue of CxfRsProducer
override bean bus
CAMEL-7229 Fixed the issue of CxfRsProducer override bean bus
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/789f0921
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/789f0921
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/789f0921
Branch: refs/heads/camel-2.11.x
Commit: 789f0921cd773b03194dce2d82c2c2ae48a80719
Parents: e4f93fc
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Mar 3 16:40:28 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Mar 3 17:44:44 2014 +0800
----------------------------------------------------------------------
.../camel/component/cxf/jaxrs/CxfRsConsumer.java | 6 ++++++
.../camel/component/cxf/jaxrs/CxfRsEndpoint.java | 17 +++++------------
.../camel/component/cxf/jaxrs/CxfRsProducer.java | 16 +++++++++++-----
.../CxfRsProducerClientFactoryCache2Test.java | 1 +
.../jaxrs/CxfRsProducerClientFactoryCacheTest2.xml | 11 +++++++----
5 files changed, 30 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/789f0921/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumer.java
index f1039e2..b2272d0 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumer.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.cxf.jaxrs;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultConsumer;
+import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
@@ -34,6 +35,11 @@ public class CxfRsConsumer extends DefaultConsumer {
super(endpoint, processor);
CxfRsInvoker cxfRsInvoker = new CxfRsInvoker(endpoint, this);
JAXRSServerFactoryBean svrBean = endpoint.createJAXRSServerFactoryBean();
+ Bus bus = ((CxfRsEndpoint)getEndpoint()).getBus();
+ // We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
+ if (bus != null) {
+ svrBean.setBus(bus);
+ }
svrBean.setInvoker(cxfRsInvoker);
server = svrBean.create();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/789f0921/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
----------------------------------------------------------------------
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 0b4c816..85ac7a0 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
@@ -84,9 +84,7 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
private int loggingSizeLimit;
private boolean skipFaultLogging;
private BindingStyle bindingStyle = BindingStyle.Default;
-
- private AtomicBoolean getBusHasBeenCalled = new AtomicBoolean(false);
-
+
private boolean isSetDefaultBus;
@@ -362,18 +360,13 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
public void setBus(Bus bus) {
this.bus = bus;
- }
-
- public Bus getBus() {
- if (bus == null) {
- bus = CxfEndpointUtils.createBus(getCamelContext());
- LOG.debug("Using DefaultBus {}", bus);
- }
-
- if (!getBusHasBeenCalled.getAndSet(true) && isSetDefaultBus) {
+ if (isSetDefaultBus) {
BusFactory.setDefaultBus(bus);
LOG.debug("Set bus {} as thread default bus", bus);
}
+ }
+
+ public Bus getBus() {
return bus;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/789f0921/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
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 30b487c..d6f0ee5 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
@@ -38,6 +38,7 @@ import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.LRUSoftCache;
+import org.apache.cxf.Bus;
import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
import org.apache.cxf.jaxrs.client.Client;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -95,8 +96,11 @@ public class CxfRsProducer extends DefaultProducer {
Message inMessage = exchange.getIn();
JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils
.getEffectiveAddress(exchange, ((CxfRsEndpoint)getEndpoint()).getAddress()));
-
- cfb.setBus(((CxfRsEndpoint)getEndpoint()).getBus());
+ Bus bus = ((CxfRsEndpoint)getEndpoint()).getBus();
+ // We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
+ if (bus != null) {
+ cfb.setBus(bus);
+ }
WebClient client = cfb.createWebClient();
String httpMethod = inMessage.getHeader(Exchange.HTTP_METHOD, String.class);
Class<?> responseClass = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Class.class);
@@ -196,9 +200,11 @@ public class CxfRsProducer extends DefaultProducer {
JAXRSClientFactoryBean cfb = clientFactoryBeanCache.get(CxfEndpointUtils
.getEffectiveAddress(exchange, ((CxfRsEndpoint)getEndpoint()).getAddress()));
-
- cfb.setBus(((CxfRsEndpoint)getEndpoint()).getBus());
-
+ Bus bus = ((CxfRsEndpoint)getEndpoint()).getBus();
+ // We need to apply the bus setting from the CxfRsEndpoint which is not use the default bus
+ if (bus != null) {
+ cfb.setBus(bus);
+ }
if (varValues == null) {
target = cfb.create();
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/789f0921/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java
index 03d1565..f6c7d23 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCache2Test.java
@@ -26,6 +26,7 @@ import org.apache.camel.component.cxf.CXFTestSupport;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.spring.SpringCamelContext;
+import org.apache.cxf.BusFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/camel/blob/789f0921/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml
index 33031c7..370160d 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryCacheTest2.xml
@@ -17,6 +17,7 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:cxfcore="http://cxf.apache.org/core"
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:http="http://cxf.apache.org/transports/http/configuration" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
@@ -25,9 +26,10 @@
http://camel.apache.org/schema/spring/camel-spring.xsd http://cxf.apache.org/transports/http-jetty/configuration
http://cxf.apache.org/schemas/configuration/http-jetty.xsd http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/transports/http/configuration
- http://cxf.apache.org/schemas/configuration/http-conf.xsd ">
+ http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
+
<jaxrs:server id="restService" address="https://localhost:${mySecurePort}/CxfRsProducerTest/"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
@@ -41,12 +43,13 @@
<route>
<from uri="direct://http"/>
<recipientList>
- <simple>cxfrs://https://localhost:${header.clientPort}/CxfRsProducerTest/</simple>
+ <!-- need to pass the spring http conduit setting the CxfProducer, as we don't create a default bus for the CxfRsEndpoint anymore -->
+ <simple>cxfrs://https://localhost:${header.clientPort}/CxfRsProducerTest/?bus=#cxf</simple>
</recipientList>
</route>
</camelContext>
- <httpj:engine-factory id="tls-config">
+ <httpj:engine-factory id="tls-config" >
<httpj:engine port="${mySecurePort}">
<httpj:tlsServerParameters>
<sec:keyManagers keyPassword="password">