use of org.apache.camel.ErrorHandlerFactory in project camel by apache.
the class ProcessorDefinition method wrapInErrorHandler.
/**
* Wraps the given output in an error handler
*
* @param routeContext the route context
* @param output the output
* @return the output wrapped with the error handler
* @throws Exception can be thrown if failed to create error handler builder
*/
protected Processor wrapInErrorHandler(RouteContext routeContext, Processor output) throws Exception {
ErrorHandlerFactory builder = routeContext.getRoute().getErrorHandlerBuilder();
// create error handler
Processor errorHandler = builder.createErrorHandler(routeContext, output);
// invoke lifecycles so we can manage this error handler builder
for (LifecycleStrategy strategy : routeContext.getCamelContext().getLifecycleStrategies()) {
strategy.onErrorHandlerAdd(routeContext, errorHandler, builder);
}
return errorHandler;
}
use of org.apache.camel.ErrorHandlerFactory in project camel by apache.
the class RoutingSlip method createErrorHandler.
protected AsyncProcessor createErrorHandler(RouteContext routeContext, Exchange exchange, AsyncProcessor processor, Endpoint endpoint) {
AsyncProcessor answer = processor;
boolean tryBlock = exchange.getProperty(Exchange.TRY_ROUTE_BLOCK, false, boolean.class);
// do not wrap in error handler if we are inside a try block
if (!tryBlock && routeContext != null) {
// wrap the producer in error handler so we have fine grained error handling on
// the output side instead of the input side
// this is needed to support redelivery on that output alone and not doing redelivery
// for the entire routingslip/dynamic-router block again which will start from scratch again
log.trace("Creating error handler for: {}", processor);
ErrorHandlerFactory builder = routeContext.getRoute().getErrorHandlerBuilder();
// instead of using ProcessorDefinition.wrapInErrorHandler)
try {
answer = (AsyncProcessor) builder.createErrorHandler(routeContext, processor);
// must start the error handler
ServiceHelper.startServices(answer);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
return answer;
}
use of org.apache.camel.ErrorHandlerFactory in project camel by apache.
the class DefaultManagementNamingStrategy method getObjectNameForErrorHandler.
public ObjectName getObjectNameForErrorHandler(RouteContext routeContext, Processor errorHandler, ErrorHandlerFactory builder) throws MalformedObjectNameException {
StringBuilder buffer = new StringBuilder();
buffer.append(domainName).append(":");
buffer.append(KEY_CONTEXT + "=").append(getContextId(routeContext.getCamelContext())).append(",");
buffer.append(KEY_TYPE + "=").append(TYPE_ERRORHANDLER + ",");
// we want to only register one instance of the various error handler types and thus do some lookup
// if its a ErrorHandlerBuildRef. We need a bit of work to do that as there are potential indirection.
String ref = null;
if (builder instanceof ErrorHandlerBuilderRef) {
ErrorHandlerBuilderRef builderRef = (ErrorHandlerBuilderRef) builder;
// it has not then its an indirection and we should do some work to lookup the real builder
ref = builderRef.getRef();
ErrorHandlerFactory refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef(), false);
if (refBuilder != null) {
builder = refBuilder;
}
// complex with indirections for error handler references
if (builder instanceof ErrorHandlerBuilderRef) {
builderRef = (ErrorHandlerBuilderRef) builder;
// does it refer to a non default error handler then do a 2nd lookup
if (!builderRef.getRef().equals(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER)) {
refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef(), false);
if (refBuilder != null) {
ref = builderRef.getRef();
builder = refBuilder;
}
}
}
}
if (ref != null) {
String name = builder.getClass().getSimpleName() + "(ref:" + ref + ")";
buffer.append(KEY_NAME + "=").append(ObjectName.quote(name));
} else {
// create a name based on its instance
buffer.append(KEY_NAME + "=").append(builder.getClass().getSimpleName()).append("(").append(ObjectHelper.getIdentityHashCode(builder)).append(")");
}
return createObjectName(buffer);
}
use of org.apache.camel.ErrorHandlerFactory in project camel by apache.
the class RouteDefinition method isContextScopedErrorHandler.
@SuppressWarnings("deprecation")
public boolean isContextScopedErrorHandler(CamelContext context) {
if (!contextScopedErrorHandler) {
return false;
}
// the XML DSL will configure error handlers using refs, so we need this additional test
if (errorHandlerRef != null) {
ErrorHandlerFactory routeScoped = getErrorHandlerBuilder();
ErrorHandlerFactory contextScoped = context.getErrorHandlerBuilder();
return routeScoped != null && contextScoped != null && routeScoped == contextScoped;
}
return true;
}
use of org.apache.camel.ErrorHandlerFactory in project camel by apache.
the class RoutesDefinition method createRoute.
// Implementation methods
//-------------------------------------------------------------------------
protected RouteDefinition createRoute() {
RouteDefinition route = new RouteDefinition();
ErrorHandlerFactory handler = getErrorHandlerBuilder();
if (handler != null) {
route.setErrorHandlerBuilderIfNull(handler);
}
return route;
}
Aggregations