Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Engine - RequestFactory vs servlets vs other approaches

Our team is working on Android Application back ended with App Engine. We have some difference on opinions regarding the implementation of client-server communication. On one hand App Engine suggesting RequestFactory approach, which (as Google say)

provides a solid foundation for automatic batching and caching of requests in the future

and light-weighed

But we find this approach a little "clumsy". On the other hand we can use an ordinary servlet approach which we know well, and feel more comfortable with. We sure want lighter, faster and scalable communication, but in what proportion RequestFactory really provides them? What more we can gain and loose from both approaches.

[More of that, we read about such options like GWT-RPC (an older version of RequestFactory), and RestyGWT. But we know little about these approaches and not sure if their fit our case.]

I found here some similar questions not answered. So I suppose, this may be a helpful discussion for many.

like image 715
leonprou Avatar asked Dec 31 '11 12:12

leonprou


1 Answers

A few notes:

  1. RequestFactory is not a part of AppEngine (see here), but an add-on introduced by the latest Android Eclipse plugin. Originally RequestFactory was created for GWT.

  2. The upside of RequestFactory is that is seamlessly works with GWT and Android.

  3. The downside is that it's not cross-platform, i.e. not available for iPhone, etc..

  4. It's unclear how to version RequestFactory. If your app is big and evolving, you are bound to have two or more versions of RPC APIs serving clients. GWT clients can be easily forced to use the newest API (=page reload), not so with Android. AFAIK, there is no option of having two RequestFactory endpoints. With REST you can simply have multiple URLs for different API versions.

  5. Mixing public/private APIs. Since there are no multiple RequestFactory endpoints you can not easily divide them into public (no auth required) and private/secure (= auth required). With REST (and GWT-RPC) you can simply have two servlets (private and public) and set security constraints in web.xml (or have your own servlet Filter).

  6. RequestFactory does not support java.util.Map. This severely limits you ability to have entities with dynamic properties - there are workarounds to this but they are IMO an unnecessary kludge (like having two lists, one for keys the other for values).

Solution: this is a solution that I use in my projects:

  1. Create a service layer that returns POJO domain objects.

  2. Create RPC layer that calls the service layer. You can have multiple RPC technologies calling the same service layer. I usually have GWT-RPC and REST.

  3. Using POJO-only domain objects is sometimes impossible (also due to JPA/JDO), thus forcing you to create DTOs. DTOs are a pain to maintain and I try to avoid them if possible. It's possible to use domain objects most of the time with some workarounds: on AppEngine you can get a lot of help by using Objectify instead of low-level/JPA/JDO. It supports GWT-RPC. With REST I suggest you use Jackson where you can do all kinds of custom conversions.

like image 198
Peter Knego Avatar answered Sep 18 '22 23:09

Peter Knego