Jersey Client POST results in - header full: java.

2019-05-07 05:52发布

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>

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 - header full: java.lang.RuntimeException: Header>6144

The client sees only an HTTP 500 response with no details:

INFO: 1 * LoggingFilter - Request received on thread main
1 > PUT http://localhost:8080/rest/doPOST
1 > Accept: application/json
1 > Content-Type: application/json
{"name":"Kris Kringle","trkNbr":"585802240942","rptDt":null,"reqType":"detail"}

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)

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

No details in Jetty's log and it doesn't seem it ever makes it to the Jersey servlet.

1条回答
Anthone
2楼-- · 2019-05-07 06:29

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.

What Buffers implementation are you using? That is determined by the Connector you are using.

You can set your AbstractConnector.setResponseHeaderSize(int) to something larger for yourself.

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.

Capture the entire HTTP transaction request + response, use wireshark to capture the traffic between jersey-client and the server.

Note: it might not be possible to see this bad response header from the specific call you are making, as Jetty will fail to generate the header (hence the error) and falls back to a default 500 error response. Once you increase your responseHeaderSize it might start generating properly, at which point you can capture and look at it.

查看更多
登录 后发表回答