Search code examples
javagoogle-app-enginegwtservletsrequestfactory

GWT and GAE: How to link RequestFactory server code with Servlets?


I'm trying to figure out how to deploy a GWT app to Google App Engine. From this page on using JSPs, it looks like GAE is expecting a normal, HttpServlet-based web app, with the typical handlers:

public class MyServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) {
        // Handle the HTTP request here and return a response
    }
}

After reading the GWT documentation and watching several Google I/O videos, I am confident that I want to use GWT's RequestFactory option instead of the traditional GWT-RPC method for client-server communication.

In researching examples of how to use RequestFactory, I found this simple example which proposes the following class architecture:

Client-Side:
    PizzaProxy - client-side proxy for Pizza.class
    PizzaRequestFactory - RF impl
    PizzaRequestContext - RF context impl

Server-Side:
    Pizza - the entity
    PizzaDao - DAO for entity
    DaoLocator - ServiceLocator for all DAOs
    PizzaLocator - Locator for entity

For one, I'd say I was a little surprised to see the code this normalized, but don't mind this kind of an architecture for each entity if it pays off in performance or just provides the usualy benefit of good old fashioned clean code.

Most importantly, I'm not seeing the connection between what GAE wants and what this RequestFactory seems to provide (on the server-side). In other words, I see an example of RequestFactory server-side code sans any kind of HttpServlet whatsoever.

So I ask: how can I "wire" these two (RequestFactory and HttpServlet) concepts up so that the GWT client app can send HTTP/S to the GAE backend, which is servlet-driven? Is there a way to keep the architecture proposed in the "Pizza App" above, or is there a different architecture/approach needed when deploying to GAE?

In fact, come to think of it, this problem would apply not only to GAE, but any standard Java web container: Tomcat, JBoss, Jetty...

UPDATE: I just found the code samples for GWT's Request Framework and it seems like this might be what I'm looking for. However, this doesn't appear to have anything to do with RequestFactory, so I'm a little confused/concerned that if I go with the classes in that link that I'll lose the benefits that come with RequestFactory.


Solution

  • You have to map the RequestFactoryServlet, by default to /gwtRequest (that's the default in DefaultRequestTransport on the client-side). Everything else is done by reflection.

    See http://blog.ltgt.net/gwt-211-requestfactory/ (this was about GWT 2.1.1; RF has changed quite a bit in GWT 2.4 but the general idea is still the same)