Org.restlet: publishing JSON content against webservice returns HTTP 411 error (length required)

Simplified code example: http://pastebin.com/9ZQxSXi9

Hello

I wanted to experiment with the restlet 2.0 library and webservice gpodder, but for some reason I reached the point where I do not see a tree for trees. The service in this example requires HTTP authentication and hosting some JSON content for the URL. Nothing complicated, but somehow, although the debugging view claims that the request object contains the necessary content, the RESTful webservice response leads me to think that the HTTP request header does not contain the content.

Any ideas what the reason is? Thanks in advance.

+1
source share
1 answer

The problem is that none of the WriterRepresentation implementations that I have seen (JsonRepresentation, JacksonRepresentation, XStreamRepresentation) sets the size of the presentation when transmitting the object. Therefore, if you create a new version of JacksonRepresentation (map), the size is not calculated.

You must manually calculate the length of the contents of the map and call Representation.setSize (). Or, like me, use

new JsonRepresentation ("json string ...");

This constructor can calculate the size, of course, the length of the string, so the correct content length header is set, and everything works smoothly.

+1
source

All Articles