I'm trying to make a request to a Jersey REST service
which accepts an InputStream
as an entity using the PUT
method.
When I do, the Jersey client sets the Content-Length
header to 0.
The REST service requires that the Content-Length
is set to the actual size of the stream (IE the size of the file), but, whenever I try to set the Content-Length
the client throws:
org.apache.http.ProtocolException: Content-Length header already present
To note - the exception is not thrown when I add the Content-Length header, (at that point, this header doesn't exist), it's thrown (I assume) when Jersey / Apache HTTPClient
tries to add the 0
header value later.
Stack if it's any help:
Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:909) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:827) at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:326) ... 40 more
Caused by: org.apache.http.ProtocolException: Content-Length header already present at org.apache.http.protocol.RequestContent.process(RequestContent.java:96) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109) at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:518) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) ... 42 more
So, any ideas why Jersey / Apache HTTP Client
sets the Content-Length
header to 0, and, why I'm not able to override the Content-Length
header
I'm using:
Jersey 2.4.1
with the ApacheConnector
Thanks in advance
Will