How to add matchOnUriPrefix on existing Camel Jetty REST routes?

Jonathan Parker :

We have existing REST routes working with Camel 2.23.1 and jetty. We redirect incoming calls to an appropriate server based on the uri, query, and the user's authentication. We want to handle this more generally.

How can we modify the following code to handle any uri with "/say" as the prefix?

In our 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");

We have tried adding a property to the restConfiguration, ala

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

We have tried adding the same property to the rest route definition, ala

rest("/bye?matchOnUriPrefix=true")

We have tried creating a new from statement, which seems to break everything, ala

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

I am aware of this question and answer, but don't know how to apply it to my case: stackoverflow.com/questions/39341784

Further, is it possible to match some incoming calls with explicitly defined uri's, like "/admin/status", and all other uri's to "direct:test"?

Jonathan Parker :

We ended up taking out the restConfiguration() entirely and configuring endpoints individually, which fit our expanding requirements anyway. Our oritinal restConfiguration() was limiting the messages that could get to the endpoints themselves. Perhaps we could have modified the restConfiguration directly to enable greater flexibility, including removal of .contextPath("/"). This directly allowed the following code to work:

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=418149&siteId=1