사용자 정의 Grizzly HttpHandler을 구현하려고하지만 들어오는 요청에서 경로 정보를 간단하게 추출하는 데 실패했습니다. 아래의 최소한의 예를 참조하십시오 Grizzly의 Request.getPathInfo는 항상 null을 반환합니까?
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로 시작 들어오는 모든 요청을 "/ 테스트"지금까지 작동하는 것 같다
HandlerImpl
에 의해 처리되어야 함을 그리 즐 말할 거라 생각 했어요.
http://localhost:8080/test/foo
에 GET을 수행 할 때 그러나,이 코드는
stdout
에 다음과 같은 인쇄 :
null
/test
/test/foo
null
내 주요 관심사는 경로 정보를해야 첫 null
입니다. 이 예의 경우 foo
이고, null
이 아닙니다. 누군가가 나에게 설명 할 수 :
- 이유는 모두,이 예에서는
getHttpHandlerPath()
및getPathInfo()
반환null
? - 또한 나는 후자가 첫 번째의 결과라고 의심합니다. 맞습니까?
- Grizzly에서 URL의 "라우트되지 않은"부분에 손을 대려면 어떻게해야합니까?
http://stackoverflow.com/questions/3745275/ how-come-request-getpathinfo-in-service-method-returns-null – gavenkoa
@gavenkoa 링크 된 질문은 서블릿에 관한 것이지만,이 질문은 서블릿과 관련이 없습니다. – Waldheinz