Resoa service invocation with AJAX based on JQUERY / JSON
// Defining namespaces
if (!org) org = {}; if (!org.resoa) org.resoa = {};
// Helper function for AJAX calls
org.resoa.getAJAXOptions = function (successHandler, errorHandler) {
var options = {
contentType : "application/json; charset=utf-8",
dataType : "json", //service invocation is based on JSON
url : "/service", //the URL of the resoa service domain
cache : false,
type : "POST",
complete : successHandler, //the success function
error : errorHandler //the error function
};
return options;
};
//we instance request object, using the auto-generated Javascript library
var usr = new org.foo.user.User();
//setting request values
usr.setName("Jon_Smith");
//set data to JSON representation of request object, call the Java service method 'exists'
ajaxOptions.data = usr.toJson("exists");
//we call in synchronized way
ajaxOptions.async = false;
//performing the AJAX request
var xmlReq = $.ajax(ajaxOptions);
//examining the result, which is the JSON representation of the Java response object
if (org.foo.user.Message.prototype.instanceOf(xmlReq.responseText)){
//creating Javascript Message object out of response JSON
var msg = new org.foo.user.Message(xmlReq.responseText);
//continue with business logic by examining the response...
}
Characteristics of Resoa Rest
- The XSD defined business object model is available as Javascript library as well.
You might auto-generate this library during the project build.
- Resoa services (Java) are invoked by HTTP/JSON, using the Resoa Rest Server architecture.
It cares about the URL to service domain mapping and the JSON / Java Object de-/serialization.
- The Javascript code generator can be extended with additional functions by XML definded plugIn's. HTML Form to business object mapping functions are included in
every library by default.