Jeremy Puchta
Jeremy Puchta

Reputation: 87

Apache Camel RouteBuilder does not launch configure()

When I am trying to configure a new direct-Endpoint in Apache Camel, the configure()-Method of my RouteBuilder does not launch and I can not figure out the reason.

I have a Method configureRESTRoute(), which I have implemented in the following way:

private RouteBuilder configureRESTRoute(DataSource ds) {
    RouteBuilder restRoute = new RESTRoute() {
        @Override
        public void configure() throws Exception {
            from("direct:" + ds.getConfig().get("SOURCENAME"))
                    .log("----Configuring new REST Route----: " + "direct:" + ds.getConfig().get("SOURCENAME"))
                    .setHeader(Exchange.HTTP_PATH, simple((String) ds.getConfig().get("HTTP_PATH")))
                    .setHeader(Exchange.HTTP_METHOD, constant("GET"))
                    .to("http4:" + ds.getConfig().get("HTTP_HOST"))
                    .log("----Successfully configured----");
        }
    };
    return restRoute;
}

The DataSource class contains a Map of configuration details for a particular Datasource. In this method I am trying to build a Route which is later on added to the CamelContext. Currently it returns an empty Route, because the configure()-Method is skipped. Unfortunately there is no Exception thrown or any other kind of Error Message.

Upvotes: 1

Views: 2042

Answers (1)

Tom Donohue
Tom Donohue

Reputation: 362

To get Camel to pick up your route, get the CamelContext object, and invoke the addRoutes() method on it:

So define your new routes in a RouteBuilder:

public class RESTRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:...").to("...");
    }
}

then invoke addRoutes() and pass your RouteBuilder:

context.addRoutes(new RESTRoute());

If you're new to Camel, try starting with a Maven archetype, such as camel-archetype-java, as this boilerplate stuff is set up for you.

Upvotes: 1

Related Questions