Jostein Gogstad created CAMEL-9680:
--------------------------------------
Summary: Stream caching is broken under Spring Boot
Key: CAMEL-9680
URL: https://issues.apache.org/jira/browse/CAMEL-9680
Project: Camel
Issue Type: Bug
Components: camel-spring-boot
Affects Versions: 2.16.2
Reporter: Jostein Gogstad
As documented in the [camel-spring-boot
documentation|https://camel.apache.org/spring-boot.html], camel-spring-boot
will delegate type conversion to Spring by default (see
{{org.apache.camel.spring.boot.TypeConversionConfiguration}}). Whenever the
body of a route changes to a List, Spring believes it can convert it and fails.
See the supplied test.
The runs correctly if the {{SpringTypeConverter}} is removed.
{code:java|title=StreamCachingTest.java}
package com.example.bugs;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.boot.SpringTypeConverter;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import static java.util.Arrays.asList;
public class StreamCachingTest extends CamelTestSupport {
public static final String URI_END_OF_ROUTE = "mock:end_of_route";
@EndpointInject(uri = URI_END_OF_ROUTE)
private MockEndpoint endOfRoute;
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
context.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter(context,
new ConversionService[]{new DefaultConversionService()}), true);
from("direct:foo")
.streamCaching()
.bean(MyBean.class)
.to(URI_END_OF_ROUTE);
}
};
}
@Test
public void stream_caching_with_spring() throws Exception {
endOfRoute.expectedMessageCount(1);
template.sendBody("direct:foo", new FileInputStream(new
File("src/main/resources/banner.txt")));
endOfRoute.assertIsSatisfied();
}
public static class MyBean {
public List<Integer> someNumbers() {
return asList(1, 2, 3);
}
}
/**
* Copied from org.apache.camel.spring.boot.TypeConversionConfiguration
(they are package protected)
**/
@Bean
SpringTypeConverter springTypeConverter(CamelContext camelContext,
ConversionService[] conversionServices) {
SpringTypeConverter springTypeConverter = new
SpringTypeConverter(asList(conversionServices));
camelContext.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter,
true);
return springTypeConverter;
}
@ConditionalOnMissingBean
@Bean
ConversionService defaultCamelConversionService(ApplicationContext
applicationContext) {
DefaultConversionService service = new DefaultConversionService();
for (Converter converter :
applicationContext.getBeansOfType(Converter.class).values()) {
service.addConverter(converter);
}
return service;
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)