相关:thisthat

我正在开发POST网络服务(球衣/灰熊,仅用于研究目的),该服务应该能够处理较大的URI。但是,如果URI超过8000个字符,我将得到400错误的请求异常,而没有进一步的解释。我调试/跟踪到了灰熊的maxHttpHeaderSize属性。我尝试设置此属性,但失败了。这是我启动服务器和请求的方式:

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

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


谢谢您的帮助!
干杯,
丹尼尔

最佳答案

问题在于GrizzlyServerFactory返回已经启动的HttpServer,这就是为什么您不能即时重新配置它的原因。
在这里[1]我创建了GrizzlyServerFactory的副本,该副本不会启动HttpServer,因此代码如下:

    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

关于java - 大型URI的Jersey/Grizzly POST失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17857746/

10-16 22:19