public class UCDemo implements EntryPoint {
private static final String UNIVERSAL_CLIENT_SERVLET = "/mywebapp/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);
RootPanel.get().add(dockPanel);
button.addClickListener(new ClickListener() {
public void onClick(Widget btn) {
//Format endpoint is: soafaces://<fully qualified class name>/<annotation method name>
String stEndpoint1 = "soafaces://com.acme.service.HelloWorldService/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());
}
};
//Simply use the UniversalClient send method to call the remote service
//This service endpoint takes no arguments and returns a String
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 HelloWorldService {
@ServiceEndpoint(name="helloThereEndpoint")
public String helloThere() {
return "You got it";
}
}
Javadocs for UniversalClient:
http://www.grandlogic.com/downloads_content/soafaces-javadoc/index.html
If you would like see more, download the sample WAR that demostrates the UniversalClient in action:
http://code.google.com/p/soafaces/wiki/Downloads
This link will give you details on building your own GWT client using the UniversalClient interface:
http://code.google.com/p/soafaces/wiki/StandaloneGwtClient
You can read more about the SOAFaces and the UniversalClient open sources project here:
http://code.google.com/p/soafaces/