使用Context集合时,doPost不会被嵌入式Jetty调用

时间:2011-06-29 07:07:56

标签: servlets jetty embedded-jetty

我在嵌入模式下使用Jetty 6。我在ContextHandlerCollection中有许多servlet。除了这个问题,servlet在不同的URL上运行良好。

ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
HandlerContainer mainhandler = contexts;

    Context qxrpc = new Context(contexts,"/api",Context.SESSIONS);

    ServletHolder rpcServHolder = new ServletHolder(new FrzRpcServlet()); 
    rpcServHolder.setInitParameter("referrerCheck", "public"); 
            // allows cross-domain calls
    qxrpc.addServlet( rpcServHolder, "*.qxrpc");

    Context statscontext =new Context(contexts,"/stats",Context.SESSIONS);
    ServletHolder statsHolder = new ServletHolder(new FrzStatsServlet());
    statsHolder.setInitParameter("restrictToLocalhost", "false"); 
                // allows cross-domain calls        
    statscontext.addServlet(statsHolder, "/*");

    Context hellocontext = new Context(contexts,"/hello", Context.SESSIONS);        
    hellocontext.addServlet(new ServletHolder(new HelloServlet("HELLO TEST: ")),
                                          "/*");

    Context zdbcontext = new Context(contexts,"/zdb", Context.ALL);     
    ServletHolder zdbHolder = new ServletHolder(new FrzZdbServlet());
    statsHolder.setInitParameter("restrictToLocalhost", "false");
            // allows cross-domain calls        

    zdbcontext.addServlet(zdbHolder, "/*");

    Context root = new Context(mainhandler,"/",Context.SESSIONS);
    root.setResourceBase(docroot);
    root.addServlet(DefaultServlet.class, "/");  

我知道POST请求正在进入我的服务器。这是一些ngrep输出:

T 127.0.0.1:51634 -> 127.0.0.1:8080 [AP]
GET /zdb/test.123:1.1.local1.stringtest HTTP/1.1..Host: 127.0.0.1:8080..Connection: keep-alive..Referer: http://127.0.0.1:8888/GWT_ZDB_editor.html?gwt.codesvr=127.0.0.1:9997..Origin: http://127.0.0.1:8888..User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24..Content-Type: text/plain; charset=utf-8..Accept: */*..Accept-Encoding: gzip,deflate,sdch..Accept-Language: en-US,en;q=0.8..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3....      
##
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
  HTTP/1.1 200 OK..Access-Control-Allow-Origin: *..Content-Type: application/json; charset=ISO-8859-1..Content-Length: 124..Server: Jetty(6.1.15)....                                                     
##
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
  { "r":0,"D":"test.123:1.1.local1.stringtest","m":"OK","t":0,"p": {"ztype": "STRING", "dat" : { "cp":0, "v": "test12131" }}}                                                                            
##

POST不成功 - 报告200 OK - 但永远不会进入servlet

T 127.0.0.1:51634 -> 127.0.0.1:8080 [AP]
OPTIONS /zdb/test.123:1.1.local1.stringtest/put HTTP/1.1..Host: 127.0.0.1:8080..Connection: keep-alive..Referer: http://127.0.0.1:8888/GWT_ZDB_editor.html?gwt.codesvr=127.0.0.1:9997..Access-Control-Request-Method: POST..Origin: http://127.0.0.1:8888..User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24..Access-Control-Request-Headers: content-type..Accept: */*..Accept-Encoding: gzip,deflate,sdch..Accept-Language: en-US,en;q=0.8..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3....                                                        
#
T 127.0.0.1:8080 -> 127.0.0.1:51634 [AP]
  HTTP/1.1 200 OK..Allow: GET, HEAD, POST, TRACE, OPTIONS..Content-Length: 0..Server: Jetty(6.1.15)...
  .                

我无法弄清楚为什么doPost()没有被调用,而doGet()是。有问题的servlet是FrzZdbServlet。

在Google上发现了许多线程,但Jetty人员只回到示例中,而这些示例仅为Context示例实现do doGet()。与here

中一样

另外,我是从GWT代码发布的,我正在使用内容类型的application / json。这可能是问题吗?任何指针将不胜感激。

1 个答案:

答案 0 :(得分:0)

My Context显然不接受内容类型为的POST:application / json。在我的客户端代码上删除它修复它。如果有其他人有意见,请欣赏它。