Java 类org.apache.camel.model.TryDefinition 实例源码

项目:Camel    文件:ValidationFinallyBlockTest.java   
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() {
            TryDefinition tryType = from("direct:start").doTry().
                    process(validator).
                    to("mock:valid");
            tryType.doCatch(ValidationException.class).to("mock:invalid");
            tryType.doFinally().to("mock:all");
        }
    };
}
项目:switchyard    文件:CamelExchangeBusRouteBuilder.java   
private void addThrottling(TryDefinition route) {
    Throttling throttling = _reference.getServiceMetadata().getThrottling();
    long timePeriodMS = throttling != null ? throttling.getTimePeriod() : Throttling.DEFAULT_TIME_PERIOD;
    route.filter(THROTTLE_CHECK)
        .throttle(header(Throttling.MAX_REQUESTS)).timePeriodMillis(timePeriodMS)
        // throttle needs a child process, so we'll just remove the header
        // using an empty process definition causes some of the interceptors
        // to blow chunks, specifically audit interceptors
        .removeHeader(Throttling.MAX_REQUESTS)
        .end().end();
}
项目:Camel    文件:CamelGroovyMethods.java   
public static TryDefinition onWhen(TryDefinition self, Closure<?> predicate) {
    return self.onWhen(toExpression(predicate));
}
项目: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());
}