Required Length (411) - The length required by the RESTlet client

Im new for REST and create a client to send data to external hosting. Im using org.reslet.resource.ClientResource to create a client

Representation rep = new JsonRepresentation(json); rep.setMediaType(MediaType.APPLICATION_JSON); rep.setCharacterSet(CharacterSet.UTF_8); ClientResource clientResource = getClientResource(); Representation reply = clientResource.post(rep); return readResponseStream(reply, clientResource); 

however i get the following error

 Exception in thread "main" Length Required (411) - Length Required at org.restlet.resource.ClientResource.handle(ClientResource.java:858) at org.restlet.resource.ClientResource.post(ClientResource.java:1197) at org.mine.client.impl.RestClient.post(RestClient.java:59) 

The same code works for a receive request

 Representation reply = clientResource.get(); 

I am using reslet api 2.0.8. This seems like a problem in post org.restlet: posting JSON content against webservice returns HTTP 411 error (length required)

I have the following banks on the way to classes

 org.apache.commons.codec.jar org.apache.commons.logging.jar org.apache.httpclient.jar org.apache.httpcore.jar org.json.jar org.restlet.ext.json.jar org.restlet.jar 

Any help would be greatly appreciated.

+4
source share
1 answer

the problem is that GAE does not support HTTP chunked encoding, so a serialized object cannot be sent (via POST or PUT) to the GAE server. In Restlet Framework version 2.1 M4, we have a workaround that buffers an HTTP object to prevent chunk encoding. To use it, call the CustomerResource # setRequestEntityBuffering (boolean) method with a "true" value. Please note that this workaround is not required for the GWT edition.

Since you are using Restlet 2.0.8, I suggest you use the workaround posted here: http://restlet.tigris.org/issues/show_bug.cgi?id=1219

Regards, Thierry Boalo

+5
source

All Articles