カスタムの 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
ます。誰かが私に説明できますか:
- この例では、なぜ両方
getHttpHandlerPath()
とgetPathInfo()
戻りnull
ますか? - また、後者は最初の結果であると思われますが、これは正しいですか?
- Grizzly で URL の「ルーティングされていない」部分を取得するにはどうすればよいですか?