Examples of OnExceptionDefinition


Examples of org.apache.camel.model.OnExceptionDefinition

        }

        // the goal is to find the exception with the same/closet inheritance level as the target exception being thrown
        int targetLevel = getInheritanceLevel(exception.getClass());
        // candidate is the best candidate found so far to return
        OnExceptionDefinition candidate = null;
        // difference in inheritance level between the current candidate and the thrown exception (target level)
        int candidateDiff = Integer.MAX_VALUE;

        // loop through all the entries and find the best candidates to use
        Set<Map.Entry<ExceptionPolicyKey, OnExceptionDefinition>> entries = exceptionPolicies.entrySet();
        for (Map.Entry<ExceptionPolicyKey, OnExceptionDefinition> entry : entries) {
            Class<?> clazz = entry.getKey().getExceptionClass();
            OnExceptionDefinition type = entry.getValue();

            // if OnException is route scoped then the current route (Exchange) must match
            // so we will not pick an OnException from another route
            if (exchange != null && exchange.getUnitOfWork() != null && type.isRouteScoped()) {
                RouteDefinition route = exchange.getUnitOfWork().getRouteContext() != null ? exchange.getUnitOfWork().getRouteContext().getRoute() : null;
                RouteDefinition typeRoute = ProcessorDefinitionHelper.getRoute(type);
                if (route != null && typeRoute != null && route != typeRoute) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("The type is scoped for route: {} however Exchange is at route: {}", typeRoute.getId(), route.getId());
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        boolean notGlobal = buffer.toString().endsWith(")");
        if (notGlobal) {
            buffer.append(".");
        }

        OnExceptionDefinition onException = (OnExceptionDefinition)processor;
        buffer.append(processor.getShortName()).append("(");
        List<Class> exceptions = onException.getExceptionClasses();
        for (Class excep : exceptions) {
            buffer.append(excep.getSimpleName()).append(".class");
            if (excep != exceptions.get(exceptions.size() - 1)) {
                buffer.append(", ");
            }
        }
        buffer.append(")");

        // render the redelivery policy
        if (onException.getRedeliveryPolicy() != null) {
            RedeliveryPolicyDefinition redelivery = onException.getRedeliveryPolicy();
            if (redelivery.getMaximumRedeliveries() != null) {
                int maxRedeliveries = redelivery.getMaximumRedeliveries();
                if (maxRedeliveries != 0) {
                    buffer.append(".maximumRedeliveries(").append(maxRedeliveries).append(")");
                }
            }
            if (redelivery.getRedeliveryDelay() != null) {
                long redeliverDelay = redelivery.getRedeliveryDelay();
                if (redeliverDelay != 1000) {
                    buffer.append(".redeliverDelay(").append(redeliverDelay).append(")");
                }
            }
            if (redelivery.getLogStackTrace() != null) {
                if (redelivery.getLogStackTrace()) {
                    buffer.append(".logStackTrace(true)");
                }
            }
        }

        // render the handled policy
        if (onException.getHandledPolicy() != null) {
            String handledPolicy = onException.getHandledPolicy().toString();
            if (handledPolicy.equals("false")) {
                buffer.append(".handled(").append(handledPolicy).append(")");
            }
        }

        List<ProcessorDefinition> branches = onException.getOutputs();
        for (ProcessorDefinition branch : branches) {
            SendDefinitionRenderer.render(buffer, branch);
        }
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

     *
     * @param exceptions list of exceptions to catch
     * @return the builder
     */
    public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
        OnExceptionDefinition last = null;
        for (Class<? extends Throwable> ex : exceptions) {
            last = last == null ? onException(ex) : last.onException(ex);
        }
        return last != null ? last : onException(Exception.class);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

     *
     * @param exceptions list of exceptions to catch
     * @return the builder
     */
    public OnExceptionDefinition onException(Class... exceptions) {
        OnExceptionDefinition last = null;
        for (Class ex : exceptions) {
            last = last == null ? onException(ex) : last.onException(ex);
        }
        return last != null ? last : onException(Exception.class);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

                                                    Exchange exchange, Throwable exception) {

        // recursive up the tree using the iterator
        Iterator<Throwable> it = createExceptionIterator(exception);
        while (it.hasNext()) {
            OnExceptionDefinition type = findMatchedExceptionPolicy(exceptionPolicices, exchange, it.next());
            if (type != null) {
                return type;
            }
        }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        }

        // the goal is to find the exception with the same/closet inheritance level as the target exception being thrown
        int targetLevel = getInheritanceLevel(exception.getClass());
        // candidate is the best candidate found so far to return
        OnExceptionDefinition candidate = null;
        // difference in inheritance level between the current candidate and the thrown exception (target level)
        int candidateDiff = Integer.MAX_VALUE;

        // loop through all the entries and find the best candidates to use
        Set<Map.Entry<ExceptionPolicyKey, OnExceptionDefinition>> entries = exceptionPolicices.entrySet();
        for (Map.Entry<ExceptionPolicyKey, OnExceptionDefinition> entry : entries) {
            Class clazz = entry.getKey().getExceptionClass();
            OnExceptionDefinition type = entry.getValue();

            if (filter(type, clazz, exception)) {

                // must match
                if (!matchesWhen(type, exchange)) {
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        boolean notGlobal = buffer.toString().endsWith(")");
        if (notGlobal) {
            buffer.append(".");
        }

        OnExceptionDefinition onException = (OnExceptionDefinition)processor;
        buffer.append(processor.getShortName()).append("(");
        List<Class> exceptions = onException.getExceptionClasses();
        for (Class excep : exceptions) {
            buffer.append(excep.getSimpleName()).append(".class");
            if (excep != exceptions.get(exceptions.size() - 1)) {
                buffer.append(", ");
            }
        }
        buffer.append(")");

        // render handled() dsl
        if (onException.getHandledPolicy() != null) {
            String handled = onException.getHandledPolicy().toString();
            buffer.append(".handled(").append(handled).append(")");
        }

        List<ProcessorDefinition> branches = onException.getOutputs();
        for (ProcessorDefinition branch : branches) {
            SendDefinitionRenderer.render(buffer, branch);
        }
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        // store the original caused exception in a property, so we can restore it later
        exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);

        // find the error handler to use (if any)
        OnExceptionDefinition exceptionPolicy = getExceptionPolicy(exchange, e);
        if (exceptionPolicy != null) {
            data.currentRedeliveryPolicy = exceptionPolicy.createRedeliveryPolicy(exchange.getContext(), data.currentRedeliveryPolicy);
            data.handledPredicate = exceptionPolicy.getHandledPolicy();
            data.retryUntilPredicate = exceptionPolicy.getRetryUntilPolicy();
            data.useOriginalInMessage = exceptionPolicy.getUseOriginalMessagePolicy();

            // route specific failure handler?
            Processor processor = exceptionPolicy.getErrorHandler();
            if (processor != null) {
                data.failureProcessor = processor;
            }
            // route specific on redelivey?
            processor = exceptionPolicy.getOnRedelivery();
            if (processor != null) {
                data.onRedeliveryProcessor = processor;
            }
        }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

    /**
     * Attempts to invoke the handler for this particular exception if one is available
     */
    protected boolean customProcessorForException(Exchange exchange, Throwable exception) throws Exception {
        OnExceptionDefinition policy = getExceptionPolicy(exchange, exception);
        if (policy != null) {
            Processor processor = policy.getErrorHandler();
            if (processor != null) {
                processor.process(exchange);
                return true;
            }
        }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        // store the original caused exception in a property, so we can restore it later
        exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);

        // find the error handler to use (if any)
        OnExceptionDefinition exceptionPolicy = getExceptionPolicy(exchange, e);
        if (exceptionPolicy != null) {
            data.currentRedeliveryPolicy = exceptionPolicy.createRedeliveryPolicy(exchange.getContext(), data.currentRedeliveryPolicy);
            data.handledPredicate = exceptionPolicy.getHandledPolicy();
            data.continuedPredicate = exceptionPolicy.getContinuedPolicy();
            data.retryWhilePredicate = exceptionPolicy.getRetryWhilePolicy();
            data.useOriginalInMessage = exceptionPolicy.isUseOriginalMessage();
            data.asyncDelayedRedelivery = exceptionPolicy.isAsyncDelayedRedelivery(exchange.getContext());

            // route specific failure handler?
            Processor processor = exceptionPolicy.getErrorHandler();
            if (processor != null) {
                data.failureProcessor = processor;
            }
            // route specific on redelivery?
            processor = exceptionPolicy.getOnRedelivery();
            if (processor != null) {
                data.onRedeliveryProcessor = processor;
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.