package test;

import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.processor.InterceptorProcessor;

public class InterceptorTest {
        
        public static class StringProcessor implements Processor<Exchange> {
                public void process(Exchange e) {
                        System.err.println("process: " + e.getIn());
                }
        }
        
    final InterceptorProcessor<Exchange> interceptor1 = new
InterceptorProcessor<Exchange>() {
        @Override
        public void process(Exchange e) {
                super.process(e);
                System.err.println("interceptor1: " + e.getIn());
        }
    };
    
    final InterceptorProcessor<Exchange> interceptor2 = new
InterceptorProcessor<Exchange>() {
        @Override
        public void process(Exchange e) {
                super.process(e);
                System.err.println("interceptor2: " + e.getIn());
        }
    };

        public InterceptorTest() {
                try {
                        DefaultCamelContext container = new 
DefaultCamelContext();
                        container.addRoutes(new RouteBuilder() {
                    @SuppressWarnings("unchecked")
                                public void configure() { 
                        from("queue:a") 
                         .intercept() 
                                 .add(interceptor1) 
                                 .add(interceptor2) 
                                 .target() 
                                         .to("queue:b"); 

                        from("queue:b").process(new StringProcessor());
                    }
                });
                        container.start();
                        
                        Endpoint<Exchange> endpoint = 
container.resolveEndpoint("queue:a");
                        Exchange exchange = endpoint.createExchange();
                Message m = exchange.getIn();
                m.setBody("test");
                Producer<Exchange> producer = endpoint.createProducer();
                producer.process(exchange);
                Thread.sleep(5000); //let queues clean out
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        public static void main(String[] args) {
                new InterceptorTest();
        }

}

The output is:
interceptor2: Message: test
interceptor1: Message: test
process: Message: test

I'm using camel-core that I checked out about 2 hours ago from svn.

Hiram Chirino wrote:
> 
> It should not be the case.  I just added a test case to verify that
> interceptor1 is being called before interceptor2, and it seems that
> everything is fine.
> 
> see:
> https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
> 
> Did you have a test case that shows this is broken?
> 
> 
> On 4/18/07, dr.jeff <[EMAIL PROTECTED]> wrote:
>>
>> In this example:
>>                 from("queue:a")
>>                 .intercept()
>>                         .add(interceptor1)
>>                         .add(interceptor2)
>>                         .target()
>>                                 .to("queue:b");
>> the interceptors process a passing message in the order:
>> interceptor2.process(), interceptor1.process()
>> Is that the intended behavior?
>> --
>> View this message in context:
>> http://www.nabble.com/-camel--InterceptorProcessor-tf3604072s2354.html#a10069237
>> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Regards,
> Hiram
> 
> Blog: http://hiramchirino.com
> 
> 

-- 
View this message in context: 
http://www.nabble.com/-camel--InterceptorProcessor-tf3604072s2354.html#a10082302
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Reply via email to