Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Method> methods = Method.parseList(endpoint.getHttpMethodRestrict());
if (!methods.equals(Method.getAll())) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}