use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class ContextTestSupport method setUp.
@Override
protected void setUp() throws Exception {
// make SEDA testing faster
System.setProperty("CamelSedaPollTimeout", "10");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext) c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
assertValidContext(context);
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(10);
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
// create a default notifier when 1 exchange is done which is the most common case
oneExchangeDone = event().whenDone(1).create();
if (isUseRouteBuilder()) {
RouteBuilder[] builders = createRouteBuilders();
for (RouteBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
startCamelContext();
} else {
log.debug("isUseRouteBuilder() is false");
}
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class RouteBuilder method populateRests.
protected void populateRests() throws Exception {
ModelCamelContext camelContext = getContext();
if (camelContext == null) {
throw new IllegalArgumentException("CamelContext has not been injected!");
}
getRestCollection().setCamelContext(camelContext);
// setup rest configuration before adding the rests
if (getRestConfigurations() != null) {
for (Map.Entry<String, RestConfigurationDefinition> entry : getRestConfigurations().entrySet()) {
RestConfiguration config = entry.getValue().asRestConfiguration(getContext());
if ("".equals(entry.getKey())) {
camelContext.setRestConfiguration(config);
} else {
camelContext.addRestConfiguration(config);
}
}
}
camelContext.addRestDefinitions(getRestCollection().getRests());
// convert rests into routes so we they are routes for runtime
List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
for (RestDefinition rest : getRestCollection().getRests()) {
List<RouteDefinition> list = rest.asRouteDefinition(getContext());
routes.addAll(list);
}
// convert rests api-doc into routes so they are routes for runtime
for (RestConfiguration config : camelContext.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 : camelContext.getRouteDefinitions()) {
FromDefinition from = route.getInputs().get(0);
if (from.getUri() != null && from.getUri().startsWith("rest-api:")) {
hasRestApi = true;
}
}
if (!hasRestApi) {
RouteDefinition route = RestDefinition.asRouteApiDefinition(camelContext, config);
log.debug("Adding routeId: {} as rest-api route", route.getId());
routes.add(route);
}
}
}
// add the rest routes
for (RouteDefinition route : routes) {
getRouteCollection().route(route);
}
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class RouteBuilder method populateRoutes.
protected void populateRoutes() throws Exception {
ModelCamelContext camelContext = getContext();
if (camelContext == null) {
throw new IllegalArgumentException("CamelContext has not been injected!");
}
getRouteCollection().setCamelContext(camelContext);
camelContext.addRouteDefinitions(getRouteCollection().getRoutes());
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class RouteBuilder method checkInitialized.
// Implementation methods
// -----------------------------------------------------------------------
@SuppressWarnings("deprecation")
protected void checkInitialized() throws Exception {
if (initialized.compareAndSet(false, true)) {
// Set the CamelContext ErrorHandler here
ModelCamelContext camelContext = getContext();
if (camelContext.getErrorHandlerBuilder() != null) {
setErrorHandlerBuilder(camelContext.getErrorHandlerBuilder());
}
configure();
// a route builder prepares the route definitions correctly already
for (RouteDefinition route : getRouteCollection().getRoutes()) {
route.markPrepared();
}
}
}
Aggregations