use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class ErrorHandlerBuilderRef method lookupErrorHandlerBuilder.
/**
* Lookup the error handler by the given ref
*
* @param routeContext the route context
* @param ref reference id for the error handler
* @param mandatory whether the error handler must exists, if not a {@link org.apache.camel.NoSuchBeanException} is thrown
* @return the error handler
*/
public static ErrorHandlerFactory lookupErrorHandlerBuilder(RouteContext routeContext, String ref, boolean mandatory) {
ErrorHandlerFactory answer;
// the transacted error handler could have been configured on the route so we should use that one
if (!isErrorHandlerBuilderConfigured(ref)) {
// see if there has been configured a route builder on the route
answer = routeContext.getRoute().getErrorHandlerBuilder();
if (answer == null && routeContext.getRoute().getErrorHandlerRef() != null) {
answer = routeContext.lookup(routeContext.getRoute().getErrorHandlerRef(), ErrorHandlerBuilder.class);
}
if (answer == null) {
// fallback to the default error handler if none configured on the route
answer = new DefaultErrorHandlerBuilder();
}
// check if its also a ref with no error handler configuration like me
if (answer instanceof ErrorHandlerBuilderRef) {
ErrorHandlerBuilderRef other = (ErrorHandlerBuilderRef) answer;
String otherRef = other.getRef();
if (!isErrorHandlerBuilderConfigured(otherRef)) {
// the other has also no explicit error handler configured then fallback to the handler
// configured on the parent camel context
answer = lookupErrorHandlerBuilder((ModelCamelContext) routeContext.getCamelContext());
}
if (answer == null) {
// the other has also no explicit error handler configured then fallback to the default error handler
// otherwise we could recursive loop forever (triggered by createErrorHandler method)
answer = new DefaultErrorHandlerBuilder();
}
// inherit the error handlers from the other as they are to be shared
// this is needed by camel-spring when none error handler has been explicit configured
((ErrorHandlerBuilder) answer).setErrorHandlers(routeContext, other.getErrorHandlers(routeContext));
}
} else {
// use specific configured error handler
if (mandatory) {
answer = routeContext.mandatoryLookup(ref, ErrorHandlerBuilder.class);
} else {
answer = routeContext.lookup(ref, ErrorHandlerBuilder.class);
}
}
return answer;
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class RouteBuilder method getContext.
// Properties
// -----------------------------------------------------------------------
public ModelCamelContext getContext() {
ModelCamelContext context = super.getContext();
if (context == null) {
context = createContainer();
setContext(context);
}
return context;
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class DefaultManagementObjectStrategy method getManagedObjectForRoute.
public Object getManagedObjectForRoute(CamelContext context, Route route) {
ManagedRoute mr;
if (route.supportsSuspension()) {
mr = new ManagedSuspendableRoute((ModelCamelContext) context, route);
} else {
mr = new ManagedRoute((ModelCamelContext) context, route);
}
mr.init(context.getManagementStrategy());
return mr;
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class SpringScheduledRoutePolicyTest method startRouteWithPolicy.
@SuppressWarnings("unchecked")
private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
CamelContext context = new DefaultCamelContext();
List<RouteDefinition> routes = (List<RouteDefinition>) applicationContext.getBean("testRouteContext");
RoutePolicy policy = applicationContext.getBean(policyBeanName, RoutePolicy.class);
assertTrue(getTestType() == TestType.SIMPLE ? policy instanceof SimpleScheduledRoutePolicy : policy instanceof CronScheduledRoutePolicy);
routes.get(0).routePolicy(policy);
((ModelCamelContext) context).addRouteDefinitions(routes);
context.start();
return context;
}
use of org.apache.camel.model.ModelCamelContext in project camel by apache.
the class CamelTestSupport method doSetUp.
private void doSetUp() throws Exception {
log.debug("setUp test");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext) c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
threadCamelContext.set(context);
assertNotNull(context, "No context found!");
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(getShutdownTimeout());
// set debugger if enabled
if (isUseDebugger()) {
context.setDebugger(new DefaultDebugger());
context.getDebugger().addBreakpoint(breakpoint);
// note: when stopping CamelContext it will automatic remove the breakpoint
}
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
threadTemplate.set(template);
threadConsumer.set(consumer);
// enable auto mocking if enabled
String pattern = isMockEndpoints();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
}
pattern = isMockEndpointsAndSkip();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true));
}
// configure properties component (mandatory for testing)
context.getComponent("properties", PropertiesComponent.class);
postProcessTest();
if (isUseRouteBuilder()) {
RoutesBuilder[] builders = createRouteBuilders();
for (RoutesBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
} else if (isUseAdviceWith()) {
log.info("Skipping starting CamelContext as isUseAdviceWith is set to true.");
} else {
startCamelContext();
}
} else {
log.debug("Using route builder from the created context: " + context);
}
log.debug("Routing Rules are: " + context.getRoutes());
assertValidContext(context);
INIT.set(true);
}
Aggregations