You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2011/09/08 16:12:28 UTC

Re: redeliveryPolicyProfile and onException@redeliveryPolicyRef

Hi

You may have to reorder the xml files, so the policies is read first

eg try to swap the order here, to see if that works.
 return new ClassPathXmlApplicationContext("main-context.xml",
"test-policies-context.xml");



On Fri, Aug 26, 2011 at 5:34 PM, RavshanKos <ra...@db.com> wrote:
> Hello.
>
> I'm trying to store redelivery policies in separate spring context.
>
> Here context files that I'm using to test my approach:
>
> main-context.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:camel="http://camel.apache.org/schema/spring"
>    xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>    <camel:camelContext id="camelContext" trace="true">
>        <camel:route id="main" errorHandlerRef="defaultErrorHandler">
>            <camel:from ref="input" />
>            <camel:onException redeliveryPolicyRef="redeliveryPolicy"
> onRedeliveryRef="onRedeliveryBean">
>                <camel:exception>java.lang.Exception</camel:exception>
>
>
> <camel:handled><camel:constant>true</camel:constant></camel:handled>
>            </camel:onException>
>            <camel:bean ref="exceptionThrowingBean" />
>            <camel:to ref="output" />
>        </camel:route>
>    </camel:camelContext>
> </beans>
>
> test-policies-context.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xmlns:camel="http://camel.apache.org/schema/spring"
>    xsi:schemaLocation="
>            http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>            http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>    <camel:endpoint id="input" uri="direct:input" />
>    <camel:endpoint id="output" uri="mock:output" />
>    <camel:redeliveryPolicyProfile id="redeliveryPolicy"
> maximumRedeliveries="5" disableRedelivery="false" />
>    <camel:errorHandler id="defaultErrorHandler" type="DeadLetterChannel"
> deadLetterUri="mock:deadLetterChannel" />
>    <bean id="onRedeliveryBean"
> class="RedeliveryPoliciesTest.OnRedeliveryBean" />
>    <bean id="exceptionThrowingBean"
> class="RedeliveryPoliciesTest.ExceptionThrowingBean" />
> </beans>
>
> Test class:
> public class RedeliveryPoliciesTest extends CamelSpringTestSupport {
>    public static class ExceptionThrowingBean implements Processor {
>        public void process(Exchange exchange) throws Exception {
>            throw new Exception("RedeliveryPoliciesTest");
>        }
>    }
>
>    public static class OnRedeliveryBean implements Processor {
>        private Counter counter;
>
>        public void setCounter(Counter counter) {
>            this.counter = counter;
>        }
>
>        public void process(Exchange exchange) throws Exception {
>            counter.inc();
>        }
>    }
>
>    public static interface Counter {
>        void inc();
>    }
>
>    protected AbstractApplicationContext createApplicationContext() {
>        return new ClassPathXmlApplicationContext("main-context.xml",
> "test-policies-context.xml");
>    }
>
>    @Test
>    public void testEnsureTharRedeliveryPolicyIsWorking() {
>        Counter counter = Mockito.mock(Counter.class);
>        getMandatoryBean(OnRedeliveryBean.class,
> "onRedeliveryBean").setCounter(counter);
>        template.sendBody("direct:input", new Object());
>        Mockito.verify(counter, Mockito.times(5)).inc();
>    }
> }
>
> If I run this test it fail with:
> java.lang.IllegalArgumentException: Defensive copy of Exchange is null must
> be specified on:
>
> If I uncomment  it starts to work.
> Is it correct behaviour?
>
> I'm using camel 2.8.0.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/redeliveryPolicyProfile-and-onException-redeliveryPolicyRef-tp4738408p4738408.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: redeliveryPolicyProfile and onException@redeliveryPolicyRef

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have reproduce this issue and created a ticket to track this bug
https://issues.apache.org/jira/browse/CAMEL-4438

On Thu, Sep 8, 2011 at 4:12 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> You may have to reorder the xml files, so the policies is read first
>
> eg try to swap the order here, to see if that works.
>  return new ClassPathXmlApplicationContext("main-context.xml",
> "test-policies-context.xml");
>
>
>
> On Fri, Aug 26, 2011 at 5:34 PM, RavshanKos <ra...@db.com> wrote:
>> Hello.
>>
>> I'm trying to store redelivery policies in separate spring context.
>>
>> Here context files that I'm using to test my approach:
>>
>> main-context.xml:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>    xmlns:camel="http://camel.apache.org/schema/spring"
>>    xsi:schemaLocation="
>>        http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>        http://camel.apache.org/schema/spring
>> http://camel.apache.org/schema/spring/camel-spring.xsd">
>>    <camel:camelContext id="camelContext" trace="true">
>>        <camel:route id="main" errorHandlerRef="defaultErrorHandler">
>>            <camel:from ref="input" />
>>            <camel:onException redeliveryPolicyRef="redeliveryPolicy"
>> onRedeliveryRef="onRedeliveryBean">
>>                <camel:exception>java.lang.Exception</camel:exception>
>>
>>
>> <camel:handled><camel:constant>true</camel:constant></camel:handled>
>>            </camel:onException>
>>            <camel:bean ref="exceptionThrowingBean" />
>>            <camel:to ref="output" />
>>        </camel:route>
>>    </camel:camelContext>
>> </beans>
>>
>> test-policies-context.xml:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>    xmlns:camel="http://camel.apache.org/schema/spring"
>>    xsi:schemaLocation="
>>            http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>            http://camel.apache.org/schema/spring
>> http://camel.apache.org/schema/spring/camel-spring.xsd">
>>    <camel:endpoint id="input" uri="direct:input" />
>>    <camel:endpoint id="output" uri="mock:output" />
>>    <camel:redeliveryPolicyProfile id="redeliveryPolicy"
>> maximumRedeliveries="5" disableRedelivery="false" />
>>    <camel:errorHandler id="defaultErrorHandler" type="DeadLetterChannel"
>> deadLetterUri="mock:deadLetterChannel" />
>>    <bean id="onRedeliveryBean"
>> class="RedeliveryPoliciesTest.OnRedeliveryBean" />
>>    <bean id="exceptionThrowingBean"
>> class="RedeliveryPoliciesTest.ExceptionThrowingBean" />
>> </beans>
>>
>> Test class:
>> public class RedeliveryPoliciesTest extends CamelSpringTestSupport {
>>    public static class ExceptionThrowingBean implements Processor {
>>        public void process(Exchange exchange) throws Exception {
>>            throw new Exception("RedeliveryPoliciesTest");
>>        }
>>    }
>>
>>    public static class OnRedeliveryBean implements Processor {
>>        private Counter counter;
>>
>>        public void setCounter(Counter counter) {
>>            this.counter = counter;
>>        }
>>
>>        public void process(Exchange exchange) throws Exception {
>>            counter.inc();
>>        }
>>    }
>>
>>    public static interface Counter {
>>        void inc();
>>    }
>>
>>    protected AbstractApplicationContext createApplicationContext() {
>>        return new ClassPathXmlApplicationContext("main-context.xml",
>> "test-policies-context.xml");
>>    }
>>
>>    @Test
>>    public void testEnsureTharRedeliveryPolicyIsWorking() {
>>        Counter counter = Mockito.mock(Counter.class);
>>        getMandatoryBean(OnRedeliveryBean.class,
>> "onRedeliveryBean").setCounter(counter);
>>        template.sendBody("direct:input", new Object());
>>        Mockito.verify(counter, Mockito.times(5)).inc();
>>    }
>> }
>>
>> If I run this test it fail with:
>> java.lang.IllegalArgumentException: Defensive copy of Exchange is null must
>> be specified on:
>>
>> If I uncomment  it starts to work.
>> Is it correct behaviour?
>>
>> I'm using camel 2.8.0.
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/redeliveryPolicyProfile-and-onException-redeliveryPolicyRef-tp4738408p4738408.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/