开发者

doPost not getting called by embedded Jetty, when using Context collection

开发者 https://www.devze.com 2023-03-16 06:33 出处:网络
I am using Jetty 6 in embedded mode. I have a number of servlets in a ContextHandlerCollection. Beyond this problem, the servlets work fine on their different URLs.

I am using Jetty 6 in embedded mode. I have a number of servlets in a ContextHandlerCollection. Beyond this problem, the servlets work fine on their different URLs.

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 cros开发者_如何学运维s-domain calls        

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

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

I know the POST request is coming across to my server. Here is some ngrep output:

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" }}}                                                                            
##

Unsuccessful POST - reports 200 OK - but never gets to 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)...
  .                

What I can't figure out is why the doPost() is not getting called, while the doGet() is. The servlet in question is the FrzZdbServlet.

Found a number of threads on Google, but the Jetty folks only point back to examples, which in turn only implement do doGet() for the Context examples. As in here

Also, I am posting from GWT code, and I am using content-type application/json. Could this be the issue? Any pointers would be appreciated.


My Context apparently did not accept POSTs with content-type: application/json. Removing this on my client code fixed it. If anyone else has input appreciate it.

0

精彩评论

暂无评论...
验证码 换一张
取 消