使用 Context 集合时,嵌入式 Jetty 不会调用 doPost
我在嵌入式模式下使用 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" }}}
##
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)...
.
我不明白的是为什么 doPost() 没有被调用,而 doGet() 被调用。有问题的 servlet 是 FrzZdbServlet。
在 Google 上找到了许多线程,但 Jetty 人员只返回示例,而这些示例又只为 Context 示例实现 do doGet() 。如此处
另外,我从 GWT 代码发布,并且使用内容类型 application/json。这可能是问题所在吗?任何指示将不胜感激。
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 cross-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的上下文显然不接受内容类型为 application/json 的 POST。在我的客户端代码上删除它可以修复它。如果其他人有意见,请感激不尽。
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.