Jersey Client POST结果-标头已满:java.lang.RuntimeException:标头> 6144 [英] Jersey Client POST results in - header full: java.lang.RuntimeException: Header>6144
问题描述
以Jersey 2.4作为REST servlet的Got Jetty 8.1:
Got Jetty 8.1 with Jersey 2.4 as the REST servlet:
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.foo.rest;org.bar.rest</param-value>
</init-param>
GET响应工作正常,但是当我尝试POST时,从Jetty看到了这个奇怪的错误:
The GET responses work just fine, but when I try a POST, this strange error is seen from Jetty:
WARN o.e.j.server.AbstractHttpConnection-标头已满: java.lang.RuntimeException:标头> 6144
WARN o.e.j.server.AbstractHttpConnection - header full: java.lang.RuntimeException: Header>6144
客户端只能看到没有详细信息的HTTP 500响应:
The client sees only an HTTP 500 response with no details:
INFO:1 * LoggingFilter-在主线程上收到请求
1>放置http://localhost:8080/rest/doPOST
1>接受:application/json
1> 内容类型:application/json
{"name":"Kris Kringle," trkNbr:" 585802240942," rptDt:null," reqType:" detail}
INFO: 1 * LoggingFilter - Request received on thread main
1 > PUThttp://localhost:8080/rest/doPOST
1 > Accept: application/json
1 > Content-Type: application/json
{"name":"Kris Kringle","trkNbr":"585802240942","rptDt":null,"reqType":"detail"}
2013年11月19日,下午org.glassfish.jersey.filter.LoggingFilter日志
信息:2 * LoggingFilter-在线程main
上收到响应
2 < 500
2 <
内容长度:0
2 <服务器:Jetty(8.1.13.v20130916)
Nov 19, 2013 12:59:49 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 2 * LoggingFilter - Response received on thread main
2 < 500
2 <
Content-Length: 0
2 < Server: Jetty(8.1.13.v20130916)
线程"main"中的异常javax.ws.rs.InternalServerErrorException:
HTTP 500服务器错误
在
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:929)
Exception in thread "main" javax.ws.rs.InternalServerErrorException:
HTTP 500 Server Error
at
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:929)
{在目标之后}这样发出请求:
The request is made like this {after the target}:
TestPOJO responseMsg = target.path("/rest/doPOST")
.request(MediaType.APPLICATION_JSON)
.put(Entity.json(reqPOJO), TestPOJO.class);
Jetty日志中没有详细信息,而且似乎也从未出现在Jersey servlet中.
No details in Jetty's log and it doesn't seem it ever makes it to the Jersey servlet.
推荐答案
关于header full: java.lang.RuntimeException: Header>6144
的错误表示您的响应标头的大小超过6144字节.标头容量为6144字节,您生成的标头超出了该值.
The error about header full: java.lang.RuntimeException: Header>6144
means that your response header was over 6144 bytes in size. The header capacity was at 6144 bytes and your generated header exceeded it.
Why 6144? well, that's calculated based on your Buffers
implementation.
您正在使用什么Buffers
实现?这由 Connector
您正在使用.
What Buffers
implementation are you using? That is determined by the Connector
you are using.
您可以设置 AbstractConnector.setResponseHeaderSize(int)
为自己找到更大的东西.
You can set your AbstractConnector.setResponseHeaderSize(int)
to something larger for yourself.
如果您使用的是独立Jetty,请将您的etc/jetty.xml
修改为以下内容...
If you are using standalone Jetty, modify your etc/jetty.xml
to have the following ...
...
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
...
<Set name="responseHeaderSize">10000</Set>
...
</New>
</Arg>
</Call>
...
这是针对您情况的快速而肮脏的解决方法.
This is a quick and dirty fix for your situation.
我建议您找出为什么的响应标题大小!这是不正常的,可能表明您有一个更广泛和根本的问题.
I encourage you to find out why you have a response header that size! That's not normal and could indicate that you have a much wider and fundamental issue.
捕获整个HTTP事务请求+响应,使用 wireshark 捕获jersey-client与客户端之间的流量.服务器.
Capture the entire HTTP transaction request + response, use wireshark to capture the traffic between jersey-client and the server.
注意:从Jetty将无法从您进行的特定调用中看到此错误的响应标头,因为Jetty将无法生成标头(因此出现错误),并回退到默认的500错误响应.一旦增加了responseHeaderSize,它可能会开始正确生成,这时您可以捕获并查看它.
这篇关于Jersey Client POST结果-标头已满:java.lang.RuntimeException:标头> 6144的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!