Skip to content

Commit

Permalink
[resolves #1165] Add support for camel-undertow matchOnUriPrefix conf…
Browse files Browse the repository at this point in the history
…iguration option
  • Loading branch information
jamesnetherton committed Apr 11, 2016
1 parent 17477ca commit e8415e8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
Expand Down Expand Up @@ -116,6 +117,33 @@ public void process(Exchange exchange) throws Exception {
}
}

@Test
public void testHttpConsumerPrefixPath() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("undertow:http://localhost/foo/bar?matchOnUriPrefix=true")
.to("mock:result");
}
});
try {
camelctx.start();

MockEndpoint endpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
endpoint.setExpectedMessageCount(3);

HttpRequest.get("http://localhost:8080/foo").throwExceptionOnFailure(false).getResponse();
HttpRequest.get("http://localhost:8080/foo/bar").getResponse();
HttpRequest.get("http://localhost:8080/foo/bar/hello").getResponse();
HttpRequest.get("http://localhost:8080/foo/bar/hello/world").getResponse();

endpoint.assertIsSatisfied();
} finally {
camelctx.stop();
}
}

class CountDownProcessor implements Processor {

private final CountDownLatch latch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.URI;
import java.net.URL;

import org.apache.camel.component.undertow.HttpHandlerRegistrationInfo;
import org.apache.camel.component.undertow.UndertowHost;
import org.jboss.as.network.NetworkUtils;
import org.jboss.as.network.SocketBinding;
Expand Down Expand Up @@ -177,7 +178,9 @@ public void validateEndpointURI(URI httpURI) {
}

@Override
public void registerHandler(String path, HttpHandler handler) {
public void registerHandler(HttpHandlerRegistrationInfo registrationInfo, HttpHandler handler) {
String path = registrationInfo.getUri().getPath();

if (path.contains(REST_PATH_PLACEHOLDER)) {
String pathPrefix = path.substring(0, path.indexOf(REST_PATH_PLACEHOLDER));
String remaining = path.substring(path.indexOf(REST_PATH_PLACEHOLDER));
Expand All @@ -187,13 +190,18 @@ public void registerHandler(String path, HttpHandler handler) {

defaultHost.registerHandler(pathPrefix, pathTemplateHandler);
} else {
defaultHost.registerHandler(path, Handlers.path(handler));
defaultHost.registerHandler(path, handler);
if (registrationInfo.isMatchOnUriPrefix()) {
defaultHost.registerHandler(path, handler);
} else {
defaultHost.registerHandler(path, Handlers.path(handler));
}
}
}

@Override
public void unregisterHandler(String path) {
public void unregisterHandler(HttpHandlerRegistrationInfo registrationInfo) {
String path = registrationInfo.getUri().getPath();

if (path.contains(REST_PATH_PLACEHOLDER)) {
defaultHost.unregisterHandler(path.substring(0, path.indexOf(REST_PATH_PLACEHOLDER)));
} else {
Expand Down

0 comments on commit e8415e8

Please sign in to comment.