This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 0b86595 CAMEL-14961: Handle matchOnUriPrefix URI param in
camel-platform-http-vertx
0b86595 is described below
commit 0b86595bc4f9e497236ca574cc85153d3532cfca
Author: James Netherton <[email protected]>
AuthorDate: Fri Apr 24 10:51:45 2020 +0100
CAMEL-14961: Handle matchOnUriPrefix URI param in camel-platform-http-vertx
---
.../http/vertx/VertxPlatformHttpConsumer.java | 18 ++++++---
.../http/vertx/VertxPlatformHttpEngineTest.java | 46 ++++++++++++++++++++++
2 files changed, 58 insertions(+), 6 deletions(-)
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 674aad3..a0b716b 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 @@ public class VertxPlatformHttpConsumer extends
DefaultConsumer {
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<Method> methods =
Method.parseList(endpoint.getHttpMethodRestrict());
if (!methods.equals(Method.getAll())) {
@@ -117,7 +114,7 @@ public class VertxPlatformHttpConsumer extends
DefaultConsumer {
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 @@ public class VertxPlatformHttpConsumer extends
DefaultConsumer {
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 dfa344e..075cf52 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 class VertxPlatformHttpEngineTest {
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();
+ }
+ }
}