Restlet POSTing JSON to Appengine error
Asked Answered
M

2

2

We have a small app with Restlet on the GAE server and GWT and Android clients. Restlet serves GWT-serialized replies to GWT clients and JSON to Android clients.

All is ok with GWT-serialization both locally and on AppEngine production servers.

All is ok with Android (JSON) clients talking to local dev server.

Android taking to production AppEngine server GETs JSON replies, but POST fails. There is no error or warning in logs. The function on server gets called but parameter passed is null.

This is the offending code:

@Post("json")
public void createLocationJSON(Location location) {  // location is always null
    // do something with 'location'
}
Macaronic answered 29/10, 2010 at 11:34 Comment(0)
M
3

Just to let everybody know: I managed to get GAE+Restlet+JSON+GWT working after much fiddling. The process was really chaotic (reminded me of days programing for the Win32): I was just changing settings until it started working.

The problem that I was having is:

  1. It was serving the wrong representation (JSON, XML, GWT) to the wrong clients. Later it turned out that I had to pay attention to the order of methods inside the class. WTF??
  2. I could not get it to work on sub-path, e.g. /rest/*.

I'm not going to use Restlet for the following reasons (hint to authors):

  1. Documentation is scarce, inaccurate and sometimes contradictory (explaining thing in different ways in different parts of documentation).
  2. Configuration is not standard JAX-RS. I know they have an option to configure it as JAX-RS, but all examples in docs are not based on this.

Since then I switched to Jersey.

Macaronic answered 29/12, 2010 at 8:52 Comment(4)
Actually fine, until 1.5 that stopped working on appengine (resolved later via configuration): java.net/jira/browse/JERSEY-630Macaronic
In the mean time we replaced it with Resteasy, which IMHO has better docs.Macaronic
Thanks for the research! I'm just getting started and want to use one of these frameworks... would you recommend Resteasy?Exhibitionist
Yes I would. A nice piece of sw.Macaronic
N
1

You encountered a limitation of GAE that several Restlet users faced.

Some time ago, GAE stopped supporting accepting chunked HTTP entity. We reproduced this issue with both POST and PUT and raw GAE Servlets, so this isn't Restlet related. See GAE issue: http://code.google.com/p/googleappengine/issues/detail?id=129

The only workaround we found is to not chunk entities, meaning being able to compute their size in advance.

In Restlet 2.1 M3 version that we just released, we added a simple "entityBuffering" property on ClientResource to facilitate this (set to 'false' by default).

We are in the process of upgrading our "First Application" example to illustrate the workaround. We also had to cope with GWT 2.2 breaking compatibility with its previous GWT 2.1 core API, so Restlet 2.1 will only work on GWT.

Addition details are available on this page: http://wiki.restlet.org/docs_2.1/13-restlet/21-restlet/318-restlet/303-restlet.html

Best regards,

Jerome

Restlet ~ Founder and Technical Lead ~ http://www.restlet.org

Noelios Technologies ~ http://www.noelios.com

Nagey answered 31/3, 2011 at 17:19 Comment(7)
Hi Jerome. Thanks for the -1. Very classy. There are some things I'd like to add:Macaronic
1. Your reply is a few months late. Where were you when I needed help? Question is tagged restlet and I'd expect you guys to monitor SO as this THE Q&A site for devs.Macaronic
2. The GAE issue is from 2008. I had problems in Oct 2010. You have a edition of Restlet specifically targeted at GAE. Why couldn't you clearly state in docs that there is a serious issue?Macaronic
3. GWT support. GWT supports several RPC mechanisms, one of them being plain JSON over HTTP (= REST). Why did you have to plug into a non-standard protocol, that Google changes repeatedly?Macaronic
Regarding GAE, we got reports about this issue relatively recently and updated the docs after reproducing. We don't know why but the example in our docs used to work before and was tested directly on GAE. I suspect that they changed their HTTP policy sometime later, maybe to make it consistent between Python and Java (the issue was raised on Python IIRC)Nagey
Restlet/GWT optionnally supports the "GWT object serialization" (also used in GWT-RPC) as it prevents the need for parsing and formatting. This is a representation type/media type and not a protocol. We don't use GWT-RPC protocol in Restlet/GWT even though it can be used in parallel. Also, with content negotiation, the same REST ressource can expose both pure JSON, pure XML and GWT object format (and potentially other ones), based on the same representation beans. This is a great feature that Restlet users love in generalNagey
The -1 is for not replying precisely to the initial issue. It would also have been nice to reach us directly and suggest us to track SO or at least make sure the issue was really about Restlet (GAE in that case). We try to help our users in our own mailing list/forum in priority. Now, we recognize the importance of StackOverflow and this exchange encourages us to monitor and be more active here as well other reputation damage can apparently happen quickly ;) Please let's stop this part of the discussion now. I'll reply to the technical points next. Best regards, JeromeNagey

© 2022 - 2024 — McMap. All rights reserved.