Wildcard routing and PathTemplate
by Christian Krampenschiesser
I added those 2 tests to RoutingHandlerTestCase:
@Test
public void testWildCardRoutingTemplateHandler2() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL()
+ "/wilder/test/card");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK,
result.getStatusLine().getStatusCode());
Assert.assertEquals("wilder:[/test/card]",
HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
@Test
public void testWildCardRoutingTemplateHandler3() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL()
+ "/wildestBeast");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK,
result.getStatusLine().getStatusCode());
Assert.assertEquals("wildest:[Beast]",
HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
Additional routes are:
.add(Methods.GET, "/wilder/*", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("wilder:" +
exchange.getQueryParameters().get("*"));
}
})
.add(Methods.GET, "/wildest*", new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getResponseSender().send("wildest:" +
exchange.getQueryParameters().get("*"));
}
})
Now the problem is that without a part representing the wildcard at
the pathtemplate the *PathTemplateMatcher* doesn't work, and therefore
the routing doesn't too.
However when I try to fix the *PathTemplate* the actual matching doesn't work.
I have no problem digging a bit and fixing this issue, I just want to
know which class should be the preferred class to fix it.
Enhance the *PathTemplateMatcher#match* to handle the index of c
correctly(which is complicated because wrong base in pathTemplates)
or fix *PathTemplate#matches *and *PathTemplate#create*
I would be really happy to get some feedback, right now I feel more
like mangling with the PathTemplate because it seems to be
called only at creation/instantiation time instead of the Matcher
which is called with every request.