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 07:34:43 UTC
(camel) branch fix/CAMEL-24176 created (now c474fae4b8a3)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch fix/CAMEL-24176
in repository https://gitbox.apache.org/repos/asf/camel.git
at c474fae4b8a3 CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException
This branch includes the following new commits:
new c474fae4b8a3 CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(camel) 01/01: CAMEL-24176: camel-cxfrs - Fix async producer never mapping HTTP errors to CxfOperationException
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch fix/CAMEL-24176
in repository https://gitbox.apache.org/repos/asf/camel.git
commit c474fae4b8a3da986cef2975c799d73d9494cdc5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 20 09:34:29 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>
Signed-off-by: Claus Ibsen <cl...@gmail.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");
+ }
}