Add Android Client to Existing GWT Server

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 to communicate with a server that implements RemoteServiceServlet.

Now I want to implement an Android client that reuses the back end of the current GWT application. The Android client doesn't have to have all the functionality of the current browser client. I just want to reuse an existing server with no changes so that the same server implementation can be used by both the browser and the android client. I am new to GWT. What would you do in this case? Are you just sending HTTP requests to the servlet server from the Android app, or is there a better way to do this?

Thank!

+3


source to share


1 answer


I would suggest not using the GWT-RPC mechanism for server-to-server communication and anything other than GWT. This is because GWT-RPC protects the details of the message. Internal elements can be changed using the GWT version.

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

What you can try is wrapping GWT servlets with other servlets that output data in a common format (like XML or JSON). This way, you are not dependent on the internals of GWT-RPC and you do not need to modify existing code (wrapper servlets can be placed in another project only with a reference to an existing GWT-RPC server project).

Here's an example:



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 can port this 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
    }
}

      

0


source







All Articles