如何在现有的 Camel Jetty REST 路由上添加 matchOnUriPrefix?

How to add matchOnUriPrefix on existing Camel Jetty REST routes?

我们现有的 REST 路由可与 Camel 2.23.1 和码头一起使用。我们根据 uri、查询和用户身份验证将传入呼叫重定向到适当的服务器。我们希望更普遍地处理这个问题。

我们如何修改以下代码以处理任何以“/say”为前缀的 uri?

在我们的 RouteBuilder 中:

    RestConfigurationDefinition rConfig = restConfiguration()
            .component("jetty")          
            .port(webserverPort)
            .contextPath("/")
            .bindingMode(RestBindingMode.off)
            .enableCORS(true)
            .dataFormatProperty("prettyPrint", "true");
    rest("/say")
          .get().to("direct:test");
    from("direct:test")
            .bean(RouteRest.class, "getTestURI(*,*)")
            .to("mock:output");

我们已经尝试在restConfiguration中添加一个属性,ala

.componentProperty("matchOnUriPrefix", "true");

我们已尝试将相同的 属性 添加到其余路由定义中,ala

rest("/bye?matchOnUriPrefix=true")

我们已经尝试创建一个新的 from 语句,这似乎打破了一切,ala

from("jetty://0.0.0.0:8123/now?matchOnUriPrefix=true").to("direct:test");

我知道这个问题和答案,但不知道如何将它应用到我的案例中:

此外,是否可以将一些来电与明确定义的 uri 匹配,例如“/admin/status”,并将所有其他 uri 匹配到 "direct:test"?

我们最终完全删除了 restConfiguration() 并单独配置端点,这无论如何都符合我们不断扩展的需求。我们最初的 restConfiguration() 限制了可以到达端点本身的消息。也许我们可以直接修改 restConfiguration 以实现更大的灵活性,包括删除 .contextPath("/")。这直接允许以下代码工作:

from("jetty:http://{{ip}}:{{port}}?matchOnUriPrefix=true")
        .bean(RestForward.class, "checkUserAuth(*)")
        .bean(RestForward.class, "checkDevice(*)")
        .bean(RestForward.class, "forward(*,*)")
        .to("mock:output");