You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Dave Riseley (Jira)" <ji...@apache.org> on 2026/03/25 15:28:00 UTC
[jira] [Updated] (CAMEL-23249) CXF RS Rest service loses content-type with stream caching enabled
[ https://issues.apache.org/jira/browse/CAMEL-23249?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Dave Riseley updated CAMEL-23249:
---------------------------------
Description:
When Camel is used to host a CXF JaxRS rest service and stream caching is enabled, the content-type is lost from the jaxrs Response object.
This has happened since CAMEL-22414 implemented support for stream caching jakarta.ws.rs.core.Response objects.
This can be demonstrated with the following test:
{code:java}
@Autowired
ProducerTemplate producerTemplate;
@Configuration
static class TestConfig {
@Bean
SpringJAXRSServerFactoryBean restServer(Bus bus) {
SpringJAXRSServerFactoryBean restServer = new SpringJAXRSServerFactoryBean();
restServer.setBus(bus);
restServer.setAddress("http://localhost:8001/rs");
restServer.setServiceClass(EchoService.class);
return restServer;
}
@Bean
EchoService echoService() {
return new EchoServiceImpl();
}
@Bean
RoutesBuilder echoRoute() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("cxfrs:bean:restServer")
.streamCache(true)
.bean(EchoService.class)
.log(LoggingLevel.INFO, "Logging body: ${body}");
}
};
}
}
private interface EchoService {
@GET
@Path("/echoVariable")
public Response echoVariable(@QueryParam("say") String say);
}
private static class EchoServiceImpl implements EchoService {
@Override
public Response echoVariable(String say) {
return Response
.status(Status.OK)
.type(MediaType.APPLICATION_JSON)
.entity("{ \"message\":\""+ say +"\" }")
.build();
}
}
@Test
void testEchoVariable() {
Exchange responseExchange = producerTemplate.send("http://localhost:8001/rs/echoVariable?throwExceptionOnFailure=false&say=hello", e -> {});
assertNull(responseExchange.getException());
assertEquals(200, responseExchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class));
assertEquals("application/json", responseExchange.getMessage().getHeader(Exchange.CONTENT_TYPE, String.class));
assertEquals("{ \"message\":\"hello\" }", responseExchange.getMessage().getBody(String.class));
}
{code}
This test fails with Camel 4.14.2 (or later) - the content type of "application/octet-stream" is returned instead of the expected "application/json". It passes with Camel 4.14.1, or if stream caching is disabled (".streamCache(false)") .
A full reproducer is here, which can just be run with mvn clean install:
https://github.com/driseley/cxf-responsecaching-test
was:
When Camel is used to host a CXF JaxRS rest service and stream caching is enabled, the content-type is lost from the jaxrs Response object.
This has happened since CAMEL-22414 implemented support for stream caching jakarta.ws.rs.core.Response objects.
This can be demonstrated with the following test:
{code:java}
@Autowired
ProducerTemplate producerTemplate;
@Configuration
static class TestConfig {
@Bean
SpringJAXRSServerFactoryBean restServer(Bus bus) {
SpringJAXRSServerFactoryBean restServer = new SpringJAXRSServerFactoryBean();
restServer.setBus(bus);
restServer.setAddress("http://localhost:8001/rs");
restServer.setServiceClass(EchoService.class);
return restServer;
}
@Bean
EchoService echoService() {
return new EchoServiceImpl();
}
@Bean
RoutesBuilder echoRoute() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("cxfrs:bean:restServer")
.streamCache(true)
.bean(EchoService.class)
.log(LoggingLevel.INFO, "Logging body: ${body}");
}
};
}
}
private interface EchoService {
@GET
@Path("/echoVariable")
public Response echoVariable(@QueryParam("say") String say);
}
private static class EchoServiceImpl implements EchoService {
@Override
public Response echoVariable(String say) {
return Response
.status(Status.OK)
.type(MediaType.APPLICATION_JSON)
.entity("{ \"message\":\""+ say +"\" }")
.build();
}
}
@Test
void testEchoVariable() {
Exchange responseExchange = producerTemplate.send("http://localhost:8001/rs/echoVariable?throwExceptionOnFailure=false&say=hello", e -> {});
assertNull(responseExchange.getException());
assertEquals(200, responseExchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class));
assertEquals("application/json", responseExchange.getMessage().getHeader(Exchange.CONTENT_TYPE, String.class));
assertEquals("{ \"message\":\"hello\" }", responseExchange.getMessage().getBody(String.class));
}
{code}
This test fails with Camel 4.14.2 (or later) - the content type of "application/octet-stream" is returned instead of the expected "application/json". It passes with Camel 4.14.1, or if stream caching is disabled.
A full reproducer is here, which can just be run with mvn clean install:
https://github.com/driseley/cxf-responsecaching-test
> CXF RS Rest service loses content-type with stream caching enabled
> ------------------------------------------------------------------
>
> Key: CAMEL-23249
> URL: https://issues.apache.org/jira/browse/CAMEL-23249
> Project: Camel
> Issue Type: Bug
> Components: camel-cxfrs
> Affects Versions: 4.14.5
> Reporter: Dave Riseley
> Priority: Minor
>
> When Camel is used to host a CXF JaxRS rest service and stream caching is enabled, the content-type is lost from the jaxrs Response object.
> This has happened since CAMEL-22414 implemented support for stream caching jakarta.ws.rs.core.Response objects.
> This can be demonstrated with the following test:
> {code:java}
> @Autowired
> ProducerTemplate producerTemplate;
> @Configuration
> static class TestConfig {
> @Bean
> SpringJAXRSServerFactoryBean restServer(Bus bus) {
> SpringJAXRSServerFactoryBean restServer = new SpringJAXRSServerFactoryBean();
> restServer.setBus(bus);
> restServer.setAddress("http://localhost:8001/rs");
> restServer.setServiceClass(EchoService.class);
> return restServer;
> }
> @Bean
> EchoService echoService() {
> return new EchoServiceImpl();
> }
> @Bean
> RoutesBuilder echoRoute() {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> from("cxfrs:bean:restServer")
> .streamCache(true)
> .bean(EchoService.class)
> .log(LoggingLevel.INFO, "Logging body: ${body}");
> }
> };
> }
> }
> private interface EchoService {
> @GET
> @Path("/echoVariable")
> public Response echoVariable(@QueryParam("say") String say);
> }
> private static class EchoServiceImpl implements EchoService {
> @Override
> public Response echoVariable(String say) {
> return Response
> .status(Status.OK)
> .type(MediaType.APPLICATION_JSON)
> .entity("{ \"message\":\""+ say +"\" }")
> .build();
> }
> }
> @Test
> void testEchoVariable() {
> Exchange responseExchange = producerTemplate.send("http://localhost:8001/rs/echoVariable?throwExceptionOnFailure=false&say=hello", e -> {});
> assertNull(responseExchange.getException());
> assertEquals(200, responseExchange.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class));
> assertEquals("application/json", responseExchange.getMessage().getHeader(Exchange.CONTENT_TYPE, String.class));
> assertEquals("{ \"message\":\"hello\" }", responseExchange.getMessage().getBody(String.class));
> }
> {code}
> This test fails with Camel 4.14.2 (or later) - the content type of "application/octet-stream" is returned instead of the expected "application/json". It passes with Camel 4.14.1, or if stream caching is disabled (".streamCache(false)") .
> A full reproducer is here, which can just be run with mvn clean install:
> https://github.com/driseley/cxf-responsecaching-test
--
This message was sent by Atlassian Jira
(v8.20.10#820010)