Java 将驼峰路由限制为HTTP方法

Java 将驼峰路由限制为HTTP方法,java,apache-camel,Java,Apache Camel,我有这样一个骆驼路线定义: @Component public class AggregateRouter extends AbstractRouteBuilder { @Override public void configure() throws Exception { super.configure(); from("{{endpoint.users}}/{id}?matchOnUriPrefix=true") .to("bean:routeUtils

我有这样一个骆驼路线定义:

@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
请求进入集成层时,才能使用此定义。现在的问题是:我还有两个操作(
PUT
DELETE
),但我不想对这两个操作进行“特殊”处理(至少现在是这样)…它们的行为是
GET
,因为此路由定义是“拦截”和处理请求

我不能使用RESTDSL(该项目目前类似)。我还尝试使用
&httpMethodRestrict
{{endpoint.users}/{id}?matchOnUriPrefix=true&httpMethodRestrict=PUT
,但它也不起作用


有什么线索吗?

我也认为httpMethodRestrict是一条路要走。文档中关于参数的信息非常模糊。。。试着像httpMethodRestrict=GET那样使用它(读:限制请求获取)


另一种可能的解决方案可能是使用头信息Exchange.HTTP\U方法一样过滤(头(“Exchange.HTTP\U方法”).isEqualTo(“GET”)-只是为了得到这个想法(我没有尝试过)

是否可以过滤所有未获取的请求?我也可以这样做…并转发它们,但是任何与该URI匹配的
GET
请求都必须由该路由定义处理吗?为什么?你在想什么?在重读你的问题后,我不确定你想要实现什么。。据我所知:{{endpoint.users}}是一个http端点。请求可以通过GET、PUT或DELETE发出。如果请求不是GET请求,则不希望对其进行处理。这是正确的吗?它是一个HTTP端点,我只想在
GET
请求到来时执行该路由(请参见
中的
定义)。如果在同一URL上出现其他内容(
PUT
DELETE
,等等),我不希望该路由定义处理它。考虑一下,就像将路由定义限制为仅获取请求一样。我还认为httpMethodRestrict是一种可行的方法。文档中关于参数的信息非常模糊。。。试着像httpMethodRestrict=GET那样使用它(读:限制要获取的请求)。这有用吗?