use of org.apache.camel.spi.RestConfiguration in project camel by apache.
the class AbstractCamelContextFactoryBean method setupRoutes.
/**
* Setup all the routes which must be done prior starting {@link CamelContext}.
*/
protected void setupRoutes() throws Exception {
if (routesSetupDone.compareAndSet(false, true)) {
LOG.debug("Setting up routes");
// mark that we are setting up routes
getContext().setupRoutes(false);
// must init route refs before we prepare the routes below
initRouteRefs();
// must init rest refs before we add the rests
initRestRefs();
// and add the rests
getContext().addRestDefinitions(getRests());
// convert rests into routes so we reuse routes for runtime
for (RestDefinition rest : getRests()) {
List<RouteDefinition> routes = rest.asRouteDefinition(getContext());
for (RouteDefinition route : routes) {
getRoutes().add(route);
}
}
// convert rests api-doc into routes so they are routes for runtime
for (RestConfiguration config : getContext().getRestConfigurations()) {
if (config.getApiContextPath() != null) {
// avoid adding rest-api multiple times, in case multiple RouteBuilder classes is added
// to the CamelContext, as we only want to setup rest-api once
// so we check all existing routes if they have rest-api route already added
boolean hasRestApi = false;
for (RouteDefinition route : getContext().getRouteDefinitions()) {
FromDefinition from = route.getInputs().get(0);
if (from.getUri() != null && from.getUri().startsWith("rest-api:")) {
hasRestApi = true;
}
}
if (!hasRestApi) {
RouteDefinition route = RestDefinition.asRouteApiDefinition(getContext(), config);
LOG.debug("Adding routeId: {} as rest-api route", route.getId());
getRoutes().add(route);
}
}
}
// do special preparation for some concepts such as interceptors and policies
// this is needed as JAXB does not build exactly the same model definition as Spring DSL would do
// using route builders. So we have here a little custom code to fix the JAXB gaps
prepareRoutes();
// and add the routes
getContext().addRouteDefinitions(getRoutes());
LOG.debug("Found JAXB created routes: {}", getRoutes());
findRouteBuilders();
installRoutes();
// and we are now finished setting up the routes
getContext().setupRoutes(true);
}
}
Aggregations