How to use ProducerTemplate.requestBodyAndHeaders on CamelContext Status < 4?

Viewed 54

in Camel 2.17 it was possible to create a request with ProducerTemplate.requestBodyAndHeaders in a RouteBuilder class method configure. In Camel 3.17 it not working anymore. Because there are a condition in DefaultProducerCache.class:

public Exchange send(Endpoint endpoint, Exchange exchange, Processor resultProcessor) {
    if (this.camelContext.isStopped()) {
        exchange.setException(new RejectedExecutionException("CamelContext is stopped"));
        return exchange;
    }

camelContext.isStopped() is true. But that is not right. BaseService.class:

 public boolean isStopped() {
        return this.status < 4 || this.status >= 9;
    }

but 0,1,2,3 are starting status. And there I am. I start the CamelContext and load some configuration on startup with a request. But this is not working anymore.

Is there another solution?

My code is:

public class defaultRoutes extends RouteBuilder {
    public void configure() throws Exception {
        ProducerTemplate template=this.camelContext.createProducerTemplate();
        Object answer=null;
        Map<String,Object> headers = new HashMap<String, Object>();
        ...
        /// For Debug
        //while (this.camelContext.getStatus() != ServiceStatus.Started) {
        //  System.err.println("Camel Context has Status: " + this.camelContext.getStatus());
        //  //Status is Stopped, never started
        //  sleep(1000);
        //}
        String uri = "http://SomeUrlToGetXMLConfig.html";
        try {
            answer=template.requestBodyAndHeaders(
                    uri,
                    "",
                    headers, String.class);
        } catch (Exception e) {
            ...
        } finally {
            template.stop();
        }
        ...
        for (int i = 0; i < SomeUrlToGetXMLConfig.size(); i++) {
            from("activemq:XYZ" + SomeUrlToGetXMLConfig[i])
                .process(new doSomething())
                .toD("activemq:AABB" + SomeUrlToGetXMLConfig[i]);
        }

Framework is Spring. Not Spring Boot.

Thank you for any help.

0 Answers
Related