users@jersey.java.net

[Jersey] Re: Bad Checksum when using PUT

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 26 Oct 2011 13:01:50 +0200

Ok. So lets play with WireShark..

HttpURLConnection:

PUT /waws/nova/psk?targetID=998877 HTTP/1.1
Content-Type: application/xml
User-Agent: Java/1.6.0_26
Host: ws.irisnetlab.be
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 0

HTTP/1.1 201 Created
Server: nginx/1.0.4
Date: Wed, 26 Oct 2011 10:31:41 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive

jersey-client:

PUT /waws/nova/psk?targetID=12345 HTTP/1.1
User-Agent: Java/1.6.0_26
Host: ws.irisnetlab.be
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

HTTP/1.1 411 Length Required
Server: nginx/1.0.4
Date: Wed, 26 Oct 2011 10:38:23 GMT
Content-Type: text/html
Content-Length: 180
Connection: close


ok, makes sense. Problem here is that Content-Length is *NOT* added even
if I specify it explicitly

resource.queryParams(queryParams).header("Content-Length",
"0").put(String.class);

After some investigation I figured where the issue is. Why are you
calling "connection.setDoOutput(true);" ? It basically means that you
have some entity and HttpURLConnection then adds Content-Length header.
But When you are making request via Jersey-client, it *correctly* states
that you don't have any payload (entity) thus not including this header
to your request.

I still don't understand that requirement from servers side.

You can "emulate" entity with jersey-client:

         MultivaluedMap<String,String> queryParams = new
MultivaluedMapImpl();
         queryParams.add("targetID", "12345");

         String url = "http://ws.irisnetlab.be/waws/nova/psk";

         Client client = Client.create();
         client.addFilter(new LoggingFilter());
         WebResource resource = client.resource(url);

*resource.queryParams(queryParams).put(String.class, "");*

but that service is somehow broken from my point of view - you should
talk to its creator who should suppress this requirement.

Regards,
Pavel



On 10/26/11 11:55 AM, stlecho wrote:
> When using the underneath shown code, the call returns a correct result.
>
>
>
>> URL url = new
>> URL("https://ws.irisnetlab.be/waws/nova/psk?targetID=998877");
>> HttpURLConnection connection = (HttpURLConnection) url.openConnection();
>> connection.setDoOutput(true);
>> connection.setInstanceFollowRedirects(false);
>> connection.setRequestMethod("PUT");
>> connection.setRequestProperty("Content-Type", "application/xml");
>>
>> OutputStream os = connection.getOutputStream();
>> os.flush();
>>
>> InputStream is= connection.getInputStream();
>> String myString = convertStreamToString(is);
>> connection.disconnect();
>>
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Bad-Checksum-when-using-PUT-tp6929189p6932113.html
> Sent from the Jersey mailing list archive at Nabble.com.
>