Examples of OnExceptionDefinition


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 = null;
            UnitOfWork uow = exchange.getUnitOfWork();
            if (uow != null && uow.getRouteContext() != null) {
                String routeId = uow.getRouteContext().getRoute().getId();
                processor = exceptionPolicy.getErrorHandler(routeId);
            } else if (!exceptionPolicy.getErrorHandlers().isEmpty()) {
                // note this should really not happen, but we have this code as a fail safe
                // to be backwards compatible with the old behavior
                log.warn("Cannot determine current route from Exchange with id: {}, will fallback and use first error handler.", exchange.getExchangeId());
                processor = exceptionPolicy.getErrorHandlers().iterator().next();
            }
            if (processor != null) {
                data.failureProcessor = processor;
            }

            // route specific on redelivery?
            processor = exceptionPolicy.getOnRedelivery();
            if (processor != null) {
                data.onRedeliveryProcessor = processor;
            }
        }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

    private OnExceptionDefinition type3;

    private void setupPolicies() {
        strategy = new DefaultExceptionPolicyStrategy();
        policies = new HashMap<ExceptionPolicyKey, OnExceptionDefinition>();
        type1 = new OnExceptionDefinition(CamelExchangeException.class);
        type2 = new OnExceptionDefinition(Exception.class);
        type3 = new OnExceptionDefinition(IOException.class);
        policies.put(ExceptionPolicyKey.newInstance(CamelExchangeException.class), type1);
        policies.put(ExceptionPolicyKey.newInstance(Exception.class), type2);
        policies.put(ExceptionPolicyKey.newInstance(IOException.class), type3);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

    private void setupPoliciesNoTopLevelException() {
        // without the top level exception that can be used as fallback
        strategy = new DefaultExceptionPolicyStrategy();
        policies = new HashMap<ExceptionPolicyKey, OnExceptionDefinition>();
        type1 = new OnExceptionDefinition(CamelExchangeException.class);
        type3 = new OnExceptionDefinition(IOException.class);
        policies.put(ExceptionPolicyKey.newInstance(CamelExchangeException.class), type1);
        policies.put(ExceptionPolicyKey.newInstance(IOException.class), type3);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

    }

    private void setupPoliciesCausedBy() {
        strategy = new DefaultExceptionPolicyStrategy();
        policies = new HashMap<ExceptionPolicyKey, OnExceptionDefinition>();
        type1 = new OnExceptionDefinition(FileNotFoundException.class);
        type2 = new OnExceptionDefinition(ConnectException.class);
        type3 = new OnExceptionDefinition(IOException.class);
        policies.put(ExceptionPolicyKey.newInstance(FileNotFoundException.class), type1);
        policies.put(ExceptionPolicyKey.newInstance(IOException.class), type2);
        policies.put(ExceptionPolicyKey.newInstance(ConnectException.class), type3);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        policies.put(ExceptionPolicyKey.newInstance(ConnectException.class), type3);
    }

    public void testDirectMatch1() {
        setupPolicies();
        OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new CamelExchangeException("", null));
        assertEquals(type1, result);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        assertEquals(type1, result);
    }

    public void testDirectMatch2() {
        setupPolicies();
        OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new Exception(""));
        assertEquals(type2, result);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        assertEquals(type2, result);
    }

    public void testDirectMatch3() {
        setupPolicies();
        OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new IOException(""));
        assertEquals(type3, result);
    }
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        assertEquals(type3, result);
    }

    public void testClosetMatch3() {
        setupPolicies();
        OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new ConnectException(""));
        assertEquals(type3, result);

        result = strategy.getExceptionPolicy(policies, null, new SocketException(""));
        assertEquals(type3, result);
View Full Code Here

Examples of org.apache.camel.model.OnExceptionDefinition

        assertEquals(type3, result);
    }

    public void testClosetMatch2() {
        setupPolicies();
        OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new ClassCastException(""));
        assertEquals(type2, result);

        result = strategy.getExceptionPolicy(policies, null, new NumberFormatException(""));
        assertEquals(type2, result);
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.