diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java index 674aad332bf99..a0b716b7e1ba1 100644 --- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java +++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java @@ -87,11 +87,8 @@ protected void doInit() throws Exception { super.doInit(); final PlatformHttpEndpoint endpoint = getEndpoint(); - final String path = endpoint.getPath(); - - // Transform from the Camel path param syntax /path/{key} to vert.x web's /path/:key - final String vertxPathParamPath = PATH_PARAMETER_PATTERN.matcher(path).replaceAll(":$1"); - final Route newRoute = router.route(vertxPathParamPath); + final String path = configureEndpointPath(endpoint); + final Route newRoute = router.route(path); final Set methods = Method.parseList(endpoint.getHttpMethodRestrict()); if (!methods.equals(Method.getAll())) { @@ -117,7 +114,7 @@ protected void doInit() throws Exception { doneSync -> writeResponse(ctx, exchange, getEndpoint().getHeaderFilterStrategy())); } catch (Exception e) { ctx.fail(e); - getExceptionHandler().handleException("Failed handling platform-http endpoint " + path, exchg, e); + getExceptionHandler().handleException("Failed handling platform-http endpoint " + endpoint.getPath(), exchg, e); } finally { if (exchg != null) { doneUoW(exchg); @@ -153,6 +150,15 @@ protected void doResume() throws Exception { super.doResume(); } + private String configureEndpointPath(PlatformHttpEndpoint endpoint) { + String path = endpoint.getPath(); + if (endpoint.isMatchOnUriPrefix()) { + path += "*"; + } + // Transform from the Camel path param syntax /path/{key} to vert.x web's /path/:key + return PATH_PARAMETER_PATTERN.matcher(path).replaceAll(":$1"); + } + private Exchange toExchange(RoutingContext ctx) { final Exchange exchange = getEndpoint().createExchange(); Message in = toCamelMessage(ctx, exchange); diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java index dfa344e7db86c..075cf52d03593 100644 --- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java +++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java @@ -237,4 +237,50 @@ public void configure() throws Exception { context.stop(); } } + + @Test + public void testMatchOnUriPrefix() throws Exception { + VertxPlatformHttpServerConfiguration conf = new VertxPlatformHttpServerConfiguration(); + conf.setBindPort(AvailablePortFinder.getNextAvailable()); + + CamelContext context = new DefaultCamelContext(); + try { + final String greeting = "Hello Camel"; + context.addService(new VertxPlatformHttpServer(context, conf), true, true); + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("platform-http:/greeting/{name}?matchOnUriPrefix=true") + .transform().simple("Hello ${header.name}"); + } + }); + + context.start(); + + given() + .port(conf.getBindPort()) + .when() + .get("/greeting") + .then() + .statusCode(404); + + given() + .port(conf.getBindPort()) + .when() + .get("/greeting/Camel") + .then() + .statusCode(200) + .body(equalTo(greeting)); + + given() + .port(conf.getBindPort()) + .when() + .get("/greeting/Camel/other/path/") + .then() + .statusCode(200) + .body(equalTo(greeting)); + } finally { + context.stop(); + } + } }