You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/07/20 09:33:49 UTC

(camel) branch main updated: CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2fd62ddf7c4c CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException
2fd62ddf7c4c is described below

commit 2fd62ddf7c4c9ead4932f5f36ad0efc4be0d1637
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 20 11:33:43 2026 +0200

    CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 .../camel/component/cxf/jaxrs/CxfRsProducer.java   | 28 ++++++++++++----------
 .../cxf/jaxrs/CxfRsAsyncProducerTest.java          | 20 ++++++++++++++++
 2 files changed, 36 insertions(+), 12 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 84c5e7eb7b48..f4abc3f0d2e3 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
@@ -746,17 +746,19 @@ public class CxfRsProducer extends DefaultAsyncProducer {
         }
 
         private void fail(Throwable throwable) {
-            if (throwable.getClass().isInstance(WebApplicationException.class)) {
-                final WebApplicationException cast = WebApplicationException.class.cast(throwable);
-                final Response response = cast.getResponse();
+            if (throwable instanceof WebApplicationException wae) {
+                Response response = wae.getResponse();
                 if (shouldHandleError(response)) {
                     handleError(response);
+                } else {
+                    exchange.setException(throwable);
                 }
-            } else if (throwable.getClass().isInstance(ResponseProcessingException.class)) {
-                final ResponseProcessingException cast = ResponseProcessingException.class.cast(throwable);
-                final Response response = cast.getResponse();
+            } else if (throwable instanceof ResponseProcessingException rpe) {
+                Response response = rpe.getResponse();
                 if (shouldHandleError(response)) {
                     handleError(response);
+                } else {
+                    exchange.setException(throwable);
                 }
             } else {
                 exchange.setException(throwable);
@@ -839,17 +841,19 @@ public class CxfRsProducer extends DefaultAsyncProducer {
         }
 
         private void fail(Throwable throwable) {
-            if (throwable.getClass().isInstance(WebApplicationException.class)) {
-                final WebApplicationException cast = WebApplicationException.class.cast(throwable);
-                final Response response = cast.getResponse();
+            if (throwable instanceof WebApplicationException wae) {
+                Response response = wae.getResponse();
                 if (shouldHandleError(response)) {
                     handleError(response);
+                } else {
+                    exchange.setException(throwable);
                 }
-            } else if (throwable.getClass().isInstance(ResponseProcessingException.class)) {
-                final ResponseProcessingException cast = ResponseProcessingException.class.cast(throwable);
-                final Response response = cast.getResponse();
+            } else if (throwable instanceof ResponseProcessingException rpe) {
+                Response response = rpe.getResponse();
                 if (shouldHandleError(response)) {
                     handleError(response);
+                } else {
+                    exchange.setException(throwable);
                 }
             } else {
                 exchange.setException(throwable);
diff --git a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
index f5c4fe0c8f59..90ffd0c329a2 100644
--- a/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
+++ b/components/camel-cxf/camel-cxf-spring-rest/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsAsyncProducerTest.java
@@ -44,6 +44,7 @@ import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -506,4 +507,23 @@ public class CxfRsAsyncProducerTest extends CamelSpringTestSupport {
 
         assertEquals(422, cxfOperationException.getStatusCode(), "CXF operation exception has correct response code");
     }
+
+    @Test
+    public void testAsyncProxyProducerServerErrorMappedToCxfOperationException() {
+        Exchange exchange = template.send("direct://proxy", newExchange -> {
+            newExchange.setPattern(ExchangePattern.InOut);
+            Message inMessage = newExchange.getIn();
+            inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
+            inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.FALSE);
+            // pass an invalid id that causes NumberFormatException on the server (500 error),
+            // which the proxy client receives as a WebApplicationException through failed()
+            inMessage.setBody("invalid");
+        });
+
+        assertNotNull(exchange.getException(), "Expect an exception on the exchange");
+        assertInstanceOf(CxfOperationException.class, exchange.getException(),
+                "Async proxy producer should map WebApplicationException to CxfOperationException");
+        CxfOperationException coe = (CxfOperationException) exchange.getException();
+        assertEquals(500, coe.getStatusCode(), "Status code should be 500");
+    }
 }