Jersey / Grizzly POST因大URI而失败 [英] Jersey/Grizzly POST fails for large URI

查看:232
本文介绍了Jersey / Grizzly POST因大URI而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关:

我正在开发一个POST webservice(jersey / grizzly,仅用于研究目的),它应该能够处理大型URI。但是如果一个URI超过8000个字符,我得到一个400 Bad Request Exception,没有进一步的解释。我调试/跟踪了grezzly maxHttpHeaderSize属性。我试图设置此属性但失败了。以下是我启动服务器和请求的方法:

I'm developing a POST webservice (jersey/grizzly, for research purposes only) which should be able to handle large URIs. But if a URI exceeds above 8000 characters I get a 400 Bad Request Exception with no further explanation. I debugged/tracked it down to the grizzly maxHttpHeaderSize attribute. I tried to set this attribute but failed. Here is how I start the server and the request:

GrizzlyServerFactory.createHttpServer(BASE_URI, new PackagesResourceConfig("org.test"));

JSONObject s = new JSONObject(webResource.queryParams(queryParams).post(String.class));

感谢您的帮助!
干杯,
Daniel

Thank you for your help! Cheers, Daniel

推荐答案

问题是GrizzlyServerFactory返回已启动的HttpServer,这就是为什么你可以不要在运行中重新配置它。
这里[1]我创建了GrizzlyServerFactory的副本,它不启动HttpServer,所以代码如下:

The problem is that GrizzlyServerFactory returns already started HttpServer, that's why you can not reconfigure it on the fly. Here [1] I've created a copy of the GrizzlyServerFactory , which doesn't start HttpServer, so the code like:

    HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    httpServer.getListener("grizzly").setMaxHttpHeaderSize(Integer.MAX_VALUE);

    // don't forget to start the server explicitly
    httpServer.start();

希望这会有所帮助。

[ 1] https://github.com/oleksiys/samples/blob/master/jersey-grizzly2-ext/src/main/java/com/sun/jersey/api/container/grizzly2/ext /GrizzlyServerFactory.java

这篇关于Jersey / Grizzly POST因大URI而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆