This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch cxf-sync in repository https://gitbox.apache.org/repos/asf/camel.git
commit 75d31ea4029665c3611f6864eb34381af8c7cd94 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Oct 3 08:40:37 2024 +0200 CAMEL-21309: camel-cxf - Force using sync client when using tracing/opentelemetry as otherwise spans are not working correctly. --- .../apache/camel/component/cxf/jaxrs/CxfRsProducer.java | 12 ++++++++++++ .../org/apache/camel/component/cxf/jaxws/CxfProducer.java | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java index d03dfcee08f..5f3f4bb1adf 100644 --- a/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java +++ b/components/camel-cxf/camel-cxf-rest/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java @@ -59,6 +59,8 @@ import org.apache.cxf.jaxrs.client.WebClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.camel.Exchange.ACTIVE_SPAN; + /** * CxfRsProducer binds a Camel exchange to a CXF exchange, acts as a CXF JAXRS client, it will turn the normal Object * invocation to a RESTful request according to resource annotation. Any response will be bound to Camel exchange. @@ -108,6 +110,16 @@ public class CxfRsProducer extends DefaultAsyncProducer { @Override public boolean process(Exchange exchange, AsyncCallback callback) { + // if using camel-tracer then execute this synchronously due to CXF-9063 + if (exchange.getProperty(ACTIVE_SPAN) != null) { + try { + process(exchange); + } catch (Exception e) { + exchange.setException(e); + } + return true; + } + try { Message inMessage = exchange.getIn(); Boolean httpClientAPI = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.class); diff --git a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java index ca713e0ebe9..56416d955e7 100644 --- a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java +++ b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/CxfProducer.java @@ -51,6 +51,8 @@ import org.apache.cxf.service.model.BindingOperationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.camel.Exchange.ACTIVE_SPAN; + /** * CxfProducer binds a Camel exchange to a CXF exchange, acts as a CXF client, and sends the request to a CXF to a * server. Any response will be bound to Camel exchange. @@ -99,8 +101,17 @@ public class CxfProducer extends DefaultAsyncProducer { // so we don't delegate the sync process call to the async process @Override public boolean process(Exchange camelExchange, AsyncCallback callback) { - LOG.trace("Process exchange: {} in an async way.", camelExchange); + // if using camel-tracer then execute this synchronously due to CXF-9063 + if (camelExchange.getProperty(ACTIVE_SPAN) != null) { + try { + process(camelExchange); + } catch (Exception e) { + camelExchange.setException(e); + } + return true; + } + LOG.trace("Process exchange: {} (asynchronously)", camelExchange); try { // create CXF exchange ExchangeImpl cxfExchange = new ExchangeImpl(); @@ -137,7 +148,7 @@ public class CxfProducer extends DefaultAsyncProducer { */ @Override public void process(Exchange camelExchange) throws Exception { - LOG.trace("Process exchange: {} in sync way.", camelExchange); + LOG.trace("Process exchange: {} (synchronously)", camelExchange); // create CXF exchange ExchangeImpl cxfExchange = new ExchangeImpl();