3
votes

I just got an existing GWT web application. This application works in a very standard way: it has a client (browser) part and a server part. It uses GWT-RPC for the communication with the server, which implements RemoteServiceServlet.

Now, what I want to do is to implement an Android client which reuses the server part of the current GWT application. The Android client doesn't need to have the entire functionality of the current browser client. I just want to reuse the existing server without modification, so that the same server implementation can be used by both the browser and the Android client. I'm pretty new to GWT. What would you do in this case? Would you just send HTTP requests to the servlet server from the Android App, or is there a better way to do this?

Thank you!

1

1 Answers

0
votes

I would suggest not to use the GWT-RPC mechanism to communicate between the server and anything not GWT. The reason is, GWT-RPC is shielding away details of the communication. The internals of it may change with the GWT version you use.

What you should use instead depends on the architecture of the server application and your client.

What you could try is wrapping the GWT servlets with other servlets giving out the data in a common format (XML or JSON for example). This way, you are independent of the GWT-RPC internals and you don't have to modify the existing code (the wrapper servlets could be put in another project only referencing the existing GWT-RPC server project).

Here's an example:

A GWT-RPC Servlet:

public class MyGwtServiceImpl extends RemoteServiceServlet implements MyGwtService {
        // Method delivering my task list to GWT client
        @Override
        public List<Task> getTaskList(final String clientId) {
           // Get task list ...
           return result;
        }
    }
}

Now you could wrap that servlet to return JSON or XML:

public class MyJsonServlet extends MyGwtServiceImpl {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
       List<Task> result = super.getTaskList(req.getParameter("clientId"));
       // Serialize result to JSON and write to OutputStream
    }
}