[undertow-dev] Wildcard routing and PathTemplate

Christian Krampenschiesser krampenschiesser at gmail.com
Sat Dec 10 06:30:56 EST 2016


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20161210/7169e194/attachment.html 


More information about the undertow-dev mailing list