Over a million developers have joined DZone.
Platinum Partner

GWT UniversalClient: "Look Mom, No RPC!"

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

How to develop GWT applications without RPC code using the UniversalClient API.

GWT has enabled a more OO style of programming again within the web application world (yeah, there are some that will say that is bad for the web). For fans of Swing-type component frameworks and other similar GUI frameworks, GWT is a great welcome.

But with this style of programming, you go back to separating the client from the server more clearly. This is both good and bad. The good is that you can do a lot more things with the client now (AJAX stuff) but the bad is that you have a demarcation line between where the client code ends and server-side code starts, which requires developers to write and stub out RPC classes and interfaces. With server-side web progamming, everything is sort of mixed together so developers don't worry about where the resource is, because most of the time the code is running on the server to begin work.

Anyway, with GWT you have to write RPC code. Not the hardest thing in the world to do, but it can be a bit of a pain. Well, here comes the SOAFaces framework to the rescue with its UnverisalClient. The UniversalClient is a bit like the MuleClient you find in the Mule ESB project. It can talk to just about any server-side method or service and pass and return arguments when invoking said services. The UniveralClient allows GWT developers to write their client code and call out to remote services with much less hassle. The UniversalClient interface can invoke just about any standard Java POJO method or Mule/ESB service and return the results without writing a line of GWT RPC code. If the ESB web service already exists, then just call it. If you want to create your own, simply attach an annotation to any service-side POJO and now it is available to be called from your GWT client (again, no RPC or marshelling to deal with). And it is your choice whether to pass and return JOSN or POJO objects back and forth.

Here is a code example of what a simple GWT client would look like using the UniversalClient API to invoke a very simple service on the server side. This is, of course, a simple example, but you can also use the UniversalClient to invoke Mule endpoints as well.

public class UCDemo implements EntryPoint {

private static final String UNIVERSAL_CLIENT_SERVLET = "/SOAFacesRPCServlet";
private UniversalClient _oClient;

private Button button;

* Simple entry point and use call to UniversalClient.
public void onModuleLoad() {
button = new Button("Click To Execute Service Call");

DockPanel dockPanel = new DockPanel();
dockPanel.add(button, DockPanel.WEST);

button.addClickListener(new ClickListener() {
public void onClick(Widget btn) {

//Format endpoint is: soafaces:///
String stEndpoint1 = "soafaces://com.dupont.crd.gwt.service.HelloService/helloThereEndpoint";
if (btn.equals(button)) {

//Create the UniversalClient Async Callback
UniversalClientPOJOCallback oMulePOJOCallback = new UniversalClientPOJOCallback() {

public void onUniversalClientSuccess(Object result) {
//Serivces returns a String
String returnVal = (String) result;
Window.alert("Wow this was a success! Return value: " + returnVal);

public void onFailure(Throwable ex) {
Window.alert("Error during UniversalClient call: " + ex.getMessage());

//Using send method to call remote service
getUniversalClient().send(stEndpoint1, oMuleJSONCallback);

private UniversalClient getUniversalClient() {
if(_oClient == null) {
_oClient = UniversalClientFactory.getInstance().getUniversalClient(UNIVERSAL_CLIENT_SERVLET);
return _oClient;

Here is what the server-side code looks like. This is the service endpoint referenced by the client above. As you can see, very simple. Just a POJO with an annotation marker. This allows the UnviversalClient to invoke this service and return the results.

public class HelloWorld {

public String helloThere() {
return "You got it";

Some Resources



The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}