问题描述
使用 Jersey 2.4 作为 REST servlet 的 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:
警告 o.e.j.server.AbstractHttpConnection - 标头已满:java.lang.RuntimeException: Header>6144
客户端只看到一个没有详细信息的 HTTP 500 响应:
The client sees only an HTTP 500 response with no details:
信息:1 * LoggingFilter - 在主线程上收到请求
1 > 放置http://localhost:8080/rest/doPOST
1 > 接受:application/json
1 >内容类型:应用程序/json
{"name":"克里斯Kringle","trkNbr":"585802240942","rptDt":null,"reqType":"detail"}
2013 年 11 月 19 日下午 12:59:49 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)
请求像这样{after the target}:
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.
推荐答案
The error about 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.
为什么是 6144?好吧,这是根据您的 缓冲区
实现.
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 将无法生成标头(因此出现错误)并回退到默认的 500 错误响应.增加 responseHeaderSize 后,它可能会开始正常生成,此时您可以捕获并查看它.
这篇关于Jersey 客户端 POST 结果 - 标头已满:java.lang.RuntimeException:Header&gt;6144的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!