RPC over HTTP
Second Level Domain Same Origin Policy (SLD-SOP)
Bear in mind that the standard browser restricts its pages to only be able to request for, and to include, content from within the same second-level domain (SLD) as the server that provided that page to the browser. Top level domains (and top-level and a half) are such as .com, .org, .net, .me.us or .co.uk. So, domain names such as google.com, fbi.gov, mit.edu are second level domains. While, mail.google.com would be a third-level domain. Therefore, GWT RPC would work only within the confines of an SLD.
Note that SLD-SOP also requires the port number to be the same, such that jan.synthful.com:9100 is not on the same SLD as jan.synthful.com:9101. A particular browser brand may be lax and allows different port numbers within the same SLD consideration, but that would not be compliant to standard SLD restrictions.
GWT client-side code
The Java source of the GWT client intending to conduct RPC with its server must provide its own service declaration interface,
- which has a @RemoteServiceRelativePath directive to tell the GWT compiler the URL that would service its RPC request.
- which declares the remote service method to tell the GWT RPC class the datatype of the request argument and the expected return datatype. Surely, you need to pass arguments when you call a procedure and expect an object to to be returned. The datatype of the argument and the return signature and all their recursive members must implement the serializable interface (of course, or expect a nonserializable run-time error when the RPC process attempts to serialize those data).
- where the remote service method is to be invoked on the client-side GWT code to trigger the RPC.
- where the name of remote service method corresponds to the name of the remote method/procedure that GWT RPC would pass to the server to invoke to service this call.
- which must implement the com.google.gwt.user.client.rpc.RemoteService interface, which is an empty, marker interface.
The GWT client source code must also provide an async-response request interface for the GWT compiler. This interface should declare a method with two arguments
- the serializable datatype declared in the service declaration interface, to tell the GWT compiler constructing this whole setup the datatype of the request argument and the datatype of the object to be returned by the RPC service.
- the call-back method of the client that would asynchronously handle the server response. The call-back method must implement the com.google.gwt.user.client.rpc.AsyncCallback interface.
The server-side code
The URL on the server-side targeted by the GWT RPC client must, of course, be able to recognise the request parameters. How else would it be best but for the servlet to implement service declaration interface provided by the client. For a server that implements JEE standards - that is obvious. However, if the responder on the server is not written in Java - it would have to mimic the serialization of Java datatype declared in that interface. Since this is not a hitch hiker's guide to PHP, Python or Perl, etc, non-JEE responders are beyond the scope of discussion.
Remember that the service declaration interface defined the remote service method which your server is "supposed to" use to service the RPC request. You could write your own RPC request handler servlet by ignoring the service declaration interface as well as the remote service method name it declares but service the request any old how. Your handler servlet would still need to deserialize the RPC request parameters.
If you are coding server-side in Java, GWT provides the server-side request handler as well, RemoteServiceServlet, to
- call the method as requested by the GWT client. The method must implement service declaration interface which you have declared for the client.
- deserialize the data, that came with the request, back into a Java object, and pass the object to the requested method.
- serialize the return type of the method to be sent back to the GWT client.
Naturally, your handler servlet would need to be mapped to the URL on which the GWT client has sent a GET request, as registered in the @RemoteServiceRelativePath directive of service declaration interface.
To use the GWT framework, your servlet needs to extend com.google.gwt.user.server.rpc.RemoteServiceServlet.
Continue next Passing Parameters in GWT RPC (Client-side)