I'm trying to implement a custom Grizzly HttpHandler but fail miserably trying to simply extract the path info from the incoming requests. See the minimal example below:
public class PathInfoTest {
public static void main(String[] args) throws IOException {
final HttpServer httpServer = new HttpServer();
final NetworkListener nl = new NetworkListener(
"grizzly", "localhost", 8080);
httpServer.addListener(nl);
httpServer.getServerConfiguration().addHttpHandler(
new HandlerImpl(), "/test");
httpServer.start();
System.in.read();
}
private static class HandlerImpl extends HttpHandler {
@Override
public void service(Request request, Response response)
throws Exception {
System.out.println(request.getPathInfo());
System.out.println(request.getContextPath());
System.out.println(request.getDecodedRequestURI());
System.out.println(request.getHttpHandlerPath());
}
}
I thought this would tell Grizzly that all incoming requests where the URL starts with "/test" should be handled by HandlerImpl
, which seems to work so far. However, when doing a GET to http://localhost:8080/test/foo
, this code prints the following to stdout
:
null
/test
/test/foo
null
My main concern is the first null
, which should be the path info. I expect it to be foo
in this example, not null
. Can someone explain to me:
- why both,
getHttpHandlerPath()
andgetPathInfo()
returnnull
in this example? - Also, I suspect the latter being a consequence of the first, is this right?
- How can I get my hands on the "unrouted" part of the URL in Grizzly?