2

カスタムの Grizzly HttpHandlerを実装しようとしていますが、着信要求からパス情報を単純に抽出しようとして惨めに失敗します。以下の最小限の例を参照してください。

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());
    }
}

これにより、URL が "/test" で始まるすべての着信要求を で処理する必要があることを Grizzly に伝えることができると思いました。これは今のHandlerImplところ機能しているようです。ただし、 に GET を実行するとhttp://localhost:8080/test/foo、このコードは に次を出力しますstdout

null
/test
/test/foo
null

私の主な関心事はnull、パス情報である最初の です。fooではなく、この例にあると思いnullます。誰かが私に説明できますか:

  1. この例では、なぜ両方getHttpHandlerPath()getPathInfo()戻りnullますか?
  2. また、後者は最初の結果であると思われますが、これは正しいですか?
  3. Grizzly で URL の「ルーティングされていない」部分を取得するにはどうすればよいですか?
4

1 に答える 1