Java 类org.apache.camel.builder.ErrorHandlerBuilder 实例源码

项目:Camel    文件:RouteDefinitionHelper.java   
private static void initParentAndErrorHandlerBuilder(ModelCamelContext context, RouteDefinition route,
                                                     List<ProcessorDefinition<?>> abstracts, List<OnExceptionDefinition> onExceptions) {

    if (context != null) {
        // let the route inherit the error handler builder from camel context if none already set

        // must clone to avoid side effects while building routes using multiple RouteBuilders
        ErrorHandlerBuilder builder = context.getErrorHandlerBuilder();
        if (builder != null) {
            builder = builder.cloneBuilder();
            route.setErrorHandlerBuilderIfNull(builder);
        }
    }

    // init parent and error handler builder on the route
    initParentAndErrorHandlerBuilder(route);

    // set the parent and error handler builder on the global on exceptions
    if (onExceptions != null) {
        for (OnExceptionDefinition global : onExceptions) {
            initParentAndErrorHandlerBuilder(global);
        }
    }
}
项目:camel-cdi    文件:XmlErrorHandlerFactoryBean.java   
@Override
public ErrorHandlerBuilder create(CreationalContext<ErrorHandlerBuilder> creationalContext) {
    try {
        ErrorHandlerBuilder builder = handler.getType().getTypeAsClass().newInstance();

        switch (handler.getType()) {
            case DefaultErrorHandler:
            case DeadLetterChannel:
                setProperties((DefaultErrorHandlerBuilder) builder);
                break;
            case LoggingErrorHandler:
                setProperties((LoggingErrorHandlerBuilder) builder);
                break;
            case NoErrorHandler:
                // No configuration required
                break;
            case TransactionErrorHandler:
                break;
        }

        return builder;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
项目:Camel    文件:XmlErrorHandlerFactoryBean.java   
@Override
public ErrorHandlerBuilder create(CreationalContext<ErrorHandlerBuilder> creationalContext) {
    try {
        ErrorHandlerBuilder builder = handler.getType().getTypeAsClass().newInstance();

        switch (handler.getType()) {
        case DefaultErrorHandler:
        case DeadLetterChannel:
            setProperties((DefaultErrorHandlerBuilder) builder);
            break;
        case LoggingErrorHandler:
            setProperties((LoggingErrorHandlerBuilder) builder);
            break;
        case NoErrorHandler:
            // No configuration required
            break;
        case TransactionErrorHandler:
            break;
        default:
            break;
        }

        return builder;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
项目:Camel    文件:SpringTransactionPolicy.java   
protected TransactionErrorHandler createTransactionErrorHandler(RouteContext routeContext, Processor processor, ErrorHandlerBuilder builder) {
    TransactionErrorHandler answer;
    try {
        answer = (TransactionErrorHandler) builder.createErrorHandler(routeContext, processor);
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    return answer;
}
项目:Camel    文件:DummyErrorHandlerBuilder.java   
@Override
public ErrorHandlerBuilder cloneBuilder() {
    DummyErrorHandlerBuilder answer = new DummyErrorHandlerBuilder();
    super.cloneBuilder(answer);
    answer.beanName = beanName;
    return answer;
}
项目:switchyard    文件:DomainCamelContextConfigurationTest.java   
@Test
public void testConfiguration() throws Exception {
    Assert.assertNotNull(_camelContext.getProperty("abc"));
    Assert.assertEquals("xyz", _camelContext.getProperty("abc"));
    Assert.assertEquals("foobar-camel-context", _camelContext.getName());
    Assert.assertEquals(true, _camelContext.isUseMDCLogging());
    Assert.assertEquals(ManagementStatisticsLevel.RoutesOnly
            , _camelContext.getManagementStrategy().getStatisticsLevel());
    Assert.assertEquals(false, _camelContext.isAllowUseOriginalMessage());
    Assert.assertEquals(true, _camelContext.isStreamCaching());
    DataFormatDefinition dfd = _camelContext.getDataFormats().get("transform-json");
    Assert.assertNotNull(dfd);
    Assert.assertEquals("json-jackson", dfd.getDataFormatName());
    Assert.assertTrue(dfd instanceof JsonDataFormat);

    MockEndpoint mock = _camelContext.getEndpoint("mock:output", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("foobar-input");
    _camelContext.createProducerTemplate().sendBody("direct:input", "foobar-input");
    mock.assertIsSatisfied();

    // CamelContext should be able to find CDI beans produced by this class from registry.
    Assert.assertEquals(true, _camelContext.isTracing());
    DefaultTraceFormatter formatter =
            (DefaultTraceFormatter) ((Tracer)_camelContext.getDefaultTracer()).getFormatter();
    Assert.assertEquals(false, formatter.isShowBody());
    Assert.assertEquals(false, formatter.isShowBreadCrumb());
    Assert.assertEquals(100, formatter.getMaxChars());

    @SuppressWarnings("deprecation")
    ErrorHandlerBuilder builder = _camelContext.getErrorHandlerBuilder();
    Assert.assertEquals(ErrorHandlerBuilderRef.class, builder.getClass());
    Assert.assertEquals("foobarErrorHandler", ((ErrorHandlerBuilderRef)builder).getRef());
}
项目:Camel    文件:OnExceptionDefinition.java   
public void addRoutes(RouteContext routeContext, Collection<Route> routes) throws Exception {
    // assign whether this was a route scoped onException or not
    // we need to know this later when setting the parent, as only route scoped should have parent
    // Note: this logic can possible be removed when the Camel routing engine decides at runtime
    // to apply onException in a more dynamic fashion than current code base
    // and therefore is in a better position to decide among context/route scoped OnException at runtime
    if (routeScoped == null) {
        routeScoped = super.getParent() != null;
    }

    setHandledFromExpressionType(routeContext);
    setContinuedFromExpressionType(routeContext);
    setRetryWhileFromExpressionType(routeContext);
    setOnRedeliveryFromRedeliveryRef(routeContext);
    setOnExceptionOccurredFromOnExceptionOccurredRef(routeContext);

    // load exception classes
    if (exceptions != null && !exceptions.isEmpty()) {
        exceptionClasses = createExceptionClasses(routeContext.getCamelContext().getClassResolver());
    }

    // must validate configuration before creating processor
    validateConfiguration();

    if (useOriginalMessagePolicy != null && useOriginalMessagePolicy) {
        // ensure allow original is turned on
        routeContext.setAllowUseOriginalMessage(true);
    }

    // lets attach this on exception to the route error handler
    Processor child = createOutputsProcessor(routeContext);
    if (child != null) {
        // wrap in our special safe fallback error handler if OnException have child output
        Processor errorHandler = new FatalFallbackErrorHandler(child);
        String id = routeContext.getRoute().getId();
        errorHandlers.put(id, errorHandler);
    }
    // lookup the error handler builder
    ErrorHandlerBuilder builder = (ErrorHandlerBuilder)routeContext.getRoute().getErrorHandlerBuilder();
    // and add this as error handlers
    builder.addErrorHandlers(routeContext, this);
}
项目:Camel    文件:DefaultCamelContext.java   
public ErrorHandlerBuilder getErrorHandlerBuilder() {
    return (ErrorHandlerBuilder)errorHandlerBuilder;
}
项目:Camel    文件:CamelErrorHandlerFactoryBean.java   
@Override
public Class<? extends ErrorHandlerBuilder> getObjectType() {
    return type.getTypeAsClass();
}
项目:Camel    文件:XmlErrorHandlerFactoryBean.java   
XmlErrorHandlerFactoryBean(BeanManager manager, SyntheticAnnotated annotated, Class<?> type, Function<Bean<ErrorHandlerBuilder>, String> toString, ErrorHandlerDefinition handler) {
    super(manager, annotated, type, null, toString);
    this.manager = manager;
    this.handler = handler;
}
项目:Camel    文件:XmlErrorHandlerFactoryBean.java   
@Override
public void destroy(ErrorHandlerBuilder instance, CreationalContext<ErrorHandlerBuilder> creationalContext) {
    // NOOP
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
@Deprecated
public ErrorHandlerBuilder getErrorHandlerBuilder() {
  return context.getErrorHandlerBuilder();
}
项目:switchyard    文件:CamelExchangeBusRouteBuilder.java   
@Override
public void configure() throws Exception {
    RouteDefinition definition = from(_endpoint);
    definition.routeId(_endpoint);

    Map<String, ErrorHandlerBuilder> handlers = lookup(ErrorHandlerBuilder.class);
    if (handlers.isEmpty()) {
        definition.errorHandler(loggingErrorHandler());
    } else if (handlers.size() == 1) {
        definition.errorHandler(handlers.values().iterator().next());
    } else {
        throw BusMessages.MESSAGES.maxOneExceptionHandler(handlers.keySet());
    }

    // add default intercept strategy using @Audit annotation
    definition.addInterceptStrategy(new FaultInterceptStrategy());
    definition.addInterceptStrategy(new AuditInterceptStrategy());

    for (Entry<String, InterceptStrategy> interceptEntry : lookup(InterceptStrategy.class).entrySet()) {
        if (log.isDebugEnabled()) {
            log.debug("Adding intercept strategy {} to route {}", interceptEntry.getKey(), _endpoint);
        }
        definition.addInterceptStrategy(interceptEntry.getValue());
    }

    Map<String, ErrorListener> errorListeners = lookup(ErrorListener.class);
    if (errorListeners.isEmpty()) {
        getContext().getWritebleRegistry().put("defaultErrorListener", new DefaultErrorListener());
    }

    // Since camel doesn't support onException closures together with doCatch/doFinal
    // code below is commented because it doesn't work as expected
    // definition.onException(Throwable.class).processRef(FATAL_ERROR.name());

    TryDefinition tryDefinition = definition.doTry();
    addThrottling(tryDefinition);

    tryDefinition
        .processRef(CONSUMER_INTERCEPT.name())
        .processRef(ADDRESSING.name())
        .processRef(TRANSACTION_HANDLER.name())
        .processRef(SECURITY_PROCESS.name())
        .processRef(GENERIC_POLICY.name())
        .processRef(VALIDATION.name())
        .processRef(TRANSFORMATION.name())
        .processRef(VALIDATION.name())
        .processRef(PROVIDER_INTERCEPT.name())
        .processRef(PROVIDER_CALLBACK.name())
        .processRef(PROVIDER_INTERCEPT.name())
        .processRef(SECURITY_CLEANUP.name())
        .processRef(TRANSACTION_HANDLER.name())
        .addOutput(createFilterDefinition());

    tryDefinition
        .doCatch(Exception.class)
        .processRef(ERROR_HANDLING.name())
        .processRef(PROVIDER_INTERCEPT.name())
        .processRef(SECURITY_CLEANUP.name())
        .processRef(TRANSACTION_HANDLER.name())
        .addOutput(createFilterDefinition());

    tryDefinition.doFinally()
        .processRef(CONSUMER_INTERCEPT.name())
        .processRef(CONSUMER_CALLBACK.name());
}
项目:switchyard    文件:DomainCamelContextConfigurationTest.java   
@Produces @Named("foobarErrorHandler")
public ErrorHandlerBuilder getErrorHandler() {
    LOG.info("Creating custom ErrorHandler - " + this);
    return new DefaultErrorHandlerBuilder().disableRedelivery();
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
@Deprecated
public ErrorHandlerBuilder getErrorHandlerBuilder() {
    return context.getErrorHandlerBuilder();
}
项目:camel-cdi    文件:XmlErrorHandlerFactoryBean.java   
XmlErrorHandlerFactoryBean(BeanManager manager, SyntheticAnnotated annotated, Class<?> type, Function<Bean<ErrorHandlerBuilder>, String> toString, ErrorHandlerDefinition handler) {
    super(manager, annotated, type, null, toString);
    this.manager = manager;
    this.handler = handler;
}
项目:camel-cdi    文件:XmlErrorHandlerFactoryBean.java   
@Override
public void destroy(ErrorHandlerBuilder instance, CreationalContext<ErrorHandlerBuilder> creationalContext) {
    // NOOP
}
项目:Camel    文件:CamelContext.java   
/**
 * Gets the default error handler builder which is inherited by the routes
 *
 * @return the builder
 * @deprecated The return type will be switched to {@link ErrorHandlerFactory} in Camel 3.0
 */
@Deprecated
ErrorHandlerBuilder getErrorHandlerBuilder();