java - Jersey 2.0 Content-Length not set -


i'm trying post web service requires content-length header set using following code:

// edit: added apache connector code clientconfig clientconfig = new clientconfig(); apacheconnector apache = new apacheconnector(clientconfig);  // setup client log requests , responses , entities client.register(new loggingfilter(logger.getlogger("com.example.app"), true));  part part = new part("123"); webtarget target = client.target("https://api.thing.com/v1.0/thing/{thingid}"); response jsonresponse = target.resolvetemplate("thingid", "abcdefg")                 .request(mediatype.application_json)                 .header(httpheaders.authorization, "anauthcodehere")                 .post(entity.json(part)); 

from release notes https://java.net/jira/browse/jersey-1617 , jersey 2.0 documentation https://jersey.java.net/documentation/latest/message-body-workers.html implies content-length automatically set. however, 411 response code server indicating content-length not present in request.

does know best way content-length header set?

i've verified through setting logger content-length header not generated in request.

thanks.

i ran quick test jersey client 2.2 , netcat, , showing me jersey sending content-length header, though loggingfilter not reporting it.

to test, first ran netcat in 1 shell.

nc -l 8090 

then executed following jersey code in shell.

response response = clientbuilder.newclient()     .register(new loggingfilter(logger.getlogger("com.example.app"), true))     .target("http://localhost:8090/test")     .request()     .post(entity.json(ioutils.toinputstream("{key:\"value\"}"))); 

after running code, following lines logged.

info: 1 * loggingfilter - request received on thread main 1 > post http://localhost:8090/test 1 > content-type: application/json {key:"value"} 

however, netcat reports several more headers in message.

post /test http/1.1 content-type: application/json user-agent: jersey/2.0 (httpurlconnection 1.7.0_17) host: localhost:8090 accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 connection: keep-alive content-length: 13  {key:"value"} 

i ran test on osx java6 , java7, same results. ran test in jersey 2.0, similar results.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -