I upgraded Camel components and code from 2.X.X to 3.7.3
Also, I recompiled sources in Java 11 before they worked in Java 8.
Example of the route:
from(direct:xyz)
.to(URL_A)
.transform()
...
The issue arrives because after to
, I get null
.
I moved from camel-http4
to camel-http
, checked properties of the libs but still cannot get what is wrong?
The error I am getting:
CaughtExceptionType: org.apache.camel.FailedToCreateProducerException CaughtExceptionMessage: Failed to create Producer for endpoint: direct:xyz1616073923650. Reason: java.lang.NullPointerException StackTrace: org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: direct:xyz1616073923650. Reason: java.lang.NullPointerException
at org.apache.camel.support.cache.DefaultProducerCache.acquireProducer(DefaultProducerCache.java:154)
at org.apache.camel.processor.RecipientListProcessor.createProcessorExchangePairs(RecipientListProcessor.java:219)
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:276)
at org.apache.camel.processor.RecipientList.sendToRecipientList(RecipientList.java:222)
at org.apache.camel.processor.RecipientList.process(RecipientList.java:185)
at org.apache.camel.processor.Pipeline$PipelineTask.run(Pipeline.java:90)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:147)
at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:312)
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:84)
at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:218)
at org.apache.camel.impl.engine.SharedCamelInternalProcessor$1.process(SharedCamelInternalProcessor.java:112)
at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83)
at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:109)
at org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:189)
at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176)
at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172)
at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:153)
at org.apache.camel.impl.engine.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:187)
at org.apache.camel.impl.engine.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:457)
Comment: I cannot even find a further way out of here, so any suggestions are welcome.
UPDATE:
After debugging further, I understood that the bug was further in the route.
from(direct:xyz)
.to(URL_A)
.transform()
...
.recipientList(exchangeProperty("event"))
UPDATE 2:
I posted a question/bug into the Camel Jira board.
UPDATE 3:
I add an example of my test classes, the route under test looks like the one above.
Spring Boot app that starts route, context:
@SpringBootApplication
@PropertySource("classpath:application-test.properties")
class TestApp {
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
}
Test itself:
@RunWith(SpringRunner.class)
@TestPropertySource(locations = "application-test.properties")
@SpringBootTest(classes = TestApp.class, webEnvironment = DEFINED_PORT)
public class FunctionalTest {
@Autowired
private EventConsumeCreator eventConsumerCreator;
private List<Endpoint> consumers;
private static final MockComponent MOCK_COMPONENT = new MockComponent();
@Before
public void before() {
// Setting Wiremock and LogAsserts
consumers = eventConsumerCreator.getConsumers();
consumers.clear();
consumers.add(new MockEndpoint("direct:xyz", MOCK_COMPONENT));
}
@Test
public checkNumEvents() {
// Make requests to endpoints
// Verify logs
// Check wiremock asserts
assertThat(numEvents(consumers), is(1));
}
}
Utility class for creating consumers:
@Component
public class EventConsumerCreator {
private List<Endpoint> consumers = new LinkedList<>();
private CamelContext camelContext;
@Autowired
public EventConsumerCreator(CamelContext camelContext) {
this.camelContext = camelContext;
}
public List<Endpoint> getConsumers() {
return consumers;
}
public Endpoint createConsumer(String identifier) {
Endpoint endpoint = createEndpoint(identifier);
consumers.add(endpoint);
return endpoint;
}
private Endpoint createEndpoint(String identifier) {
DirectComponent component = camelContext.getComponent("direct", DirectComponent.class);
try {
return component.createEndpoint("direct://" + identifier);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Thanks to @Claus Ibsen's response in Jira, I solved this issue.
The solution was to:
@Autowired private CamelContext camelContext
in FunctionalTest
@Before
iterate over all endpoints and docamelContext.addEndpoint(endpoint.getEndpointUri(), endpoint);
endpoint.start();
@After
statement, stop running endpointsendpoint.stop();
camelContext.removeEndpoint(endpoint);
Comment: If you get in a situation like this, think if you can rely on Spring/Camel auto-configurations. If not, try to recreate Camel-ish steps manually.