2016-11-09 78 views
1

我有一個駱駝路由定義像這樣的:限制駱駝路線HTTP方法

@Component 
public class AggregateRouter extends AbstractRouteBuilder { 
    @Override 
    public void configure() throws Exception { 
    super.configure(); 

    from("{{endpoint.users}}/{id}?matchOnUriPrefix=true") 
     .to("bean:routeUtils?method=validateQueryParams")) 
     .to("bean:routeUtils?method=loadRouteProperties")) 
     .to("{{uri.api.users}}") 
     .unmarshal().json(JsonLibrary.Jackson, Map.class) 
     .to("bean:routeUtils?method=extractAndAddToProperty")) 
     .to("bean:routeUtils?method=prepareAggregateRestCalls")) 
     .multicast() 
     .stopOnException() 
     .to("seda:operation1") 
     .to("seda:operation2") 
     .end() 
     .setBody(simple("${property.result}")) 
     .marshal().json(JsonLibrary.Jackson) 
     .setHeader(Exchange.HTTP_METHOD, constant("GET")) 
     .setHeader(Exchange.CONTENT_TYPE, constant("application/json")); 

    from("seda:operation2") 
     .toD("{{uri.api.users.operation2}}") 
     .unmarshal() 
     .json(JsonLibrary.Jackson, List.class) 
     .to("bean:userService?method=addOp2")); 

    from("seda:operation1") 
     .toD("{{uri.api.users.operation1}}") 
     .choice() 
     .when(AbstractHelper::isOk) 
      .unmarshal() 
      .json(JsonLibrary.Jackson, List.class) 
      .to("bean:userService?method=addOp1")) 
     .otherwise() 
      .unmarshal() 
      .json(JsonLibrary.Jackson, Map.class) 
      .to("bean:userService?method=handleRouteSubscriptionException")) 
     .end(); 
    } 
} 

我希望能夠在HTTP請求進入集成層爲GET請求只能用這個定義。現在的問題是:我還有兩個操作PUTDELETE),但我不想爲這兩個(至少現在)進行「特殊」處理...並且它們的行爲爲GET,因爲此路線定義是「攔截」和處理請求。

我不能使用其餘DSL(該項目目前像)。我也嘗試使用&httpMethodRestrict,如{{endpoint.users}}/{id}?matchOnUriPrefix=true&httpMethodRestrict=PUT,但它也不起作用。

任何線索?

+0

是否有可能過濾所有非GET請求? –

+0

我也可以這麼做......並且我向他們提供了一個前進方向,但是任何匹配該URI的GET請求必須由該路由定義處理?爲什麼?你有什麼考慮? –

+0

重新閱讀您的問題後,我不確定您想要實現什麼。據我所知:{{endpoint.users}}是一個http端點。請求可以通過GET,PUT或DELETE發出。如果請求不是GET請求,則不希望對它們進行處理。它是否正確? –

回答

1

我也認爲httpMethodRestrict是要走的路。該文檔是非常含糊的參數...嘗試使用它像httpMethodRestrict = GET(讀:限制請求GET)

另一種可能的解決方案可能會使用的標題信息Exchange.HTTP_METHOD.filter (標題(「Exchange.HTTP_METHOD」)。isEqualTo(「GET」)) - 只是爲了得到這個想法(我沒有嘗試)