I had the same problem, and wrote my own connector based on the existing ApacheConnector. See the following SO article for more details:
http://stackoverflow.com/questions/18157218/jersey-2-0-content-length-not-set
Make sure you understand that a copy of the entity will be made and for large entity bodies this may cause an out of memory problem. My requests were known to have small entity bodies, so this method works well for me.
--
Todd
From: Will Ferguson <willferguson00_at_gmail.com<mailto:willferguson00_at_gmail.com>>
Reply-To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Monday, January 27, 2014 3:11 AM
To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Re: ApacheConnector & setting Content-Length header (Jeysey Client 2.4.1)
Hi All,
Am I right to assume then that setting the content-length just isn't possible with the ApacheConnector?
If anyone has any idea about this would be great,
Thanks,
Will
On 13 January 2014 09:58, Will Ferguson <willferguson00_at_gmail.com<mailto:willferguson00_at_gmail.com>> wrote:
Hi,
Could anyone please explain how get Jersey / ApacheConnector to set the correct Content-Length header on a client request?
I have a REST service that requires this be set to the size of the entity in a PUT request, and I can't work out how to enable it.
It seems calculating it in the MessageBodyWriter has been deprecated and it looks like the ApacheConnector is always setting it to -1.
Thanks in advance,
Will