2015-11-30 111 views
0

继之前执行的过程是我所创建的路线 -Apache的骆驼 - 每个路由

from("jetty:http://localhost:8181/abc").routeId("abc").choice() 
      // Authenticate the request 
      .when(authenticator).endChoice() 
      // Authorize the request 
      .when(authorizer).endChoice() 
      // Validate the request 
      .when(abcValidator).endChoice() 
      .otherwise() 
      .process(abcRequestProcessor).process(storeFeatureRequestDetails).process(featureRequestApproverUpdater).split(body()).process(abcApproverMailer).to("direct:toMail"); 

上述路线的功能,但我不想认证和授权的步骤添加到每一个路线。有没有一种方法可以将它们配置为在每条路线之前运行。

我尝试以下 -

from("jetty:http://localhost:8181/*").process(new Processor() { 
     @Override 
     public void process(Exchange exchange) throws Exception { 
      System.out.println("Triggered"); 
     } 
    }); 

但它看起来完全匹配。

回答

1

你可以使用这个骆驼interceptor API ...

// intercept all incoming routes and log it 
interceptFrom().process(new Processor() { 
    @Override 
    public void process(Exchange exchange) throws Exception { 
     System.out.println("Triggered"); 
    } 
}); 
0

如果你不想把AAA放在每一条路径上,为什么不提取它们的功能并把它们放在不同的路由中并在路由中调用它们?示例代码:

from("jetty:http://localhost:8181/abc").routeId("abc").choice() 
      // Authenticate the request 
      .to("direct:authenticator") 
      // Authorize the request 
      .to("direct:authorizer") 
      // Validate the request 
      .to("direct:abcValidator")    
      .process(abcRequestProcessor).process(storeFeatureRequestDetails).process(featureRequestApproverUpdater).split(body()).process(abcApproverMailer).to("direct:toMail"); 

基本上验证器现在处于单独的路由。你可以通过“direct:authenticator”来调用它。授权和验证也是如此。

这样,如果您有其他需要使用此功能的路由,则只需调用AAA路由。

+0

或多或少相同。我们仍然需要添加to的。不要我们有像struts中可用的拦截器。 – user1305398

+0

搜索网站,你可以找到有关拦截器的信息 - 骆驼头版上有一个搜索框。 –