4

Im new to REST and am developing a client to post data to a external hosted service. 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 get request

Representation reply = clientResource.get();

I'm using reslet api 2.0.8. This seems like the problem in post org.restlet: Posting JSON content against webservice returns HTTP error 411 (length required)

I have the following jars in the classpath

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.

Community
  • 1
  • 1
Joey Cardoso
  • 43
  • 1
  • 3
  • 1
    If you're on Windows, try running Fiddler while making the request. This is especially helpful if you have another working call to compare it to. http://www.fiddler2.com/fiddler2/ – Merlyn Morgan-Graham Jun 24 '11 at 00:40

1 Answers1

5

the problem is that GAE doesn't support HTTP chunked encoding, therefore serialized object can't be sent (via POST or PUT) to a GAE server. In Restlet Framework version 2.1 M4 we have a workaround available that buffers the HTTP entity to prevent chunk encoding. To use it, call the ClientResource#setRequestEntityBuffering(boolean) method with a "true" value. Note that this workaround isn't required for the GWT edition.

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

Best regards, Thierry Boileau

  • 1
    The same appens on Cloudbees, thanks for the trick (https://cloudbees.zendesk.com/entries/20889467-error-411-length-required) – Martin Pernollet Jan 23 '12 at 03:20
  • @Martin That's because Cloudbees is a Google partner that runs off AppEngine: https://cloud.google.com/partners/. Wow this answer was so specific! AppEngine wasn't even mentioned but it was the correct solution! – Chloe Oct 18 '13 at 23:28