Jersey/Grizzly POST fails for large URI

本小妞迷上赌 提交于 2019-12-13 18:50:24

问题


Relevant: this and that

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));

Thank you for your help! Cheers, Daniel


回答1:


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();

Hope that will help.

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




回答2:


Have You tried with shorter URI? Probably Your server is unable to handle so long URI.

You can read more about it here: What is the maximum length of a URL in different browsers?

Why don't You put request data from URL to request body?




回答3:


You can create the grizzly http server without starting it now

public static HttpServer createHttpServer(
     final URI uri, 
     final ResourceConfig configuration, 
     final boolean start)

So basically you create it normally passing false as 3rd argument.

When you get the HttpServer object back you can httpServer.getListener("grizzly").setMaxHttpHeaderSize(Integer.MAX_VALUE); As was said before and don't forget to start the server manually.



来源:https://stackoverflow.com/questions/17857746/jersey-grizzly-post-fails-for-large-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!