apache camel - 拦截端点不起作用

时间:2014-01-08 10:24:54

标签: java unit-testing apache-camel interceptor

我在春天的骆驼环境中有很多路线,如下所示:

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
        <route id="firstRoute">
            <from uri="cxfrs://http://localhost:9876?resourceClasses=com.example.MyResource"/>
            <choice>
                <when>...//condition
                    <to uri="direct:thirdEndpoint"/>
                </when>
                <otherwise>
                    <to uri="direct:secondEndpoint"/>
                </otherwise>
            </choice>
        </route>

        <route id="secondRoute">
            <from uri="direct:secondEndpoint"/> ...
        </route>

        <route id="thirdRoute">
            <from uri="direct:thirdEndpoint"/> ...
        </route>
    </camelContext>

我正在尝试拦截将发送到direct:secondEndpoint上的CamelSpringTestSupport的广告。

所以我有:

@Override
    protected AbstractApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext(
                "my-spring-camel-context.xml");
    }


protected void tryTest() throws Exception {

    context.getRouteDefinitions().get(1).adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("direct:secondEndpoint")
                    .process(new Processor() {
                        @Override
                        public void process(Exchange exchange) throws Exception {
                            logger.info("intercepting ================");
                        }
                    });
        }
    });
      //this doesn't intercept the secondEndpoint
      Exchange result = template.send("http://localhost:9876", new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
    ...
          }
      });
      //intercepts, calling this endpoint directly works but why is it that calling an          
      //endpoint that calls this endpoint doesn't intercept
      Exchange result = template.send("direct:secondEndpoint", new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
    ...
          }
      });
}

非常感谢任何帮助。

0 个答案:

没有答案