org.codehaus.enunciate.modules.gwt.library_description.fmt Maven / Gradle / Ivy
[#ftl]
[#-- @ftlvariable name="sample_resource" type="org.codehaus.enunciate.contract.jaxrs.ResourceMethod" --]
[#-- @ftlvariable name="sample_service_method" type="org.codehaus.enunciate.contract.jaxws.WebMethod" --]
Introduction
The Google Web Toolkit client-side library is the
GWT module definition for access
to the Web service API for this application. You can use the
GWT Compiler
to create JavaScript functions that can be used to access the API.
[#if sample_service_method??]
This GWT library provides all client-side
code necessary to invoke an GWT remote procedure call. In accordance with the standard
GWT project structure,
the library provides all GWT RPC
service interfaces
(synchronous and asynchronous) and
translatable objects
in the "client" package of the main module.
GWT-RPC Example
//instantiate a new service...
${sample_service_method.declaringEndpointInterface.simpleName}Async service =
${sample_service_method.declaringEndpointInterface.simpleName}Async.Util.getInstance();
//make the asynchronous remote call to read the result...
service.${sample_service_method.simpleName}([#list sample_service_method.webParameters as param]${param.simpleName}, [/#list]
new AsyncCallback<...>() {
onSuccess(...) {
//handle the result as needed...
}
onFailure(Throwable error) {
//handle the error as needed...
}
});
[/#if]
[#if sample_resource??]
This GWT library provides all client-side
code necessary to invoke a REST endpoint that provides its data as JSON. In accordance with the standard
GWT project structure,
the library provides all JSON overlays that can be
used to read and write the JSON data.
JSON-REST Example
String url = GWT.getModuleBaseURL() + ...;
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, url);
request.sendRequest(null, new RequestCallback() {
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
//handle the successful data...
[#if sample_resource.representationMetadata?? && sample_resource.representationMetadata.xmlElement??]
${sample_resource.representationMetadata.xmlElement.simpleName} data = ${sample_resource.representationMetadata.xmlElement.simpleName}.fromJson(response.getText());
//handle the ${sample_resource.representationMetadata.xmlElement.simpleName}...
[/#if]
}
else {
//handle the error...
}
}
public void onError(Request request, Throwable throwable) {
//handle the error...
}
});
[/#if]