Tuesday, January 6, 2009

Invoking secured services couldn't be easier

A key feature of the 1.5.1 version of the Mashup Server that we released mid last year is that it can invoke services secured using complex WS-Security scenarios with ease. Hear is an example of it,

The service securedService running up on mooshup.com has been secured such that the request sent to this service should be encrypted and all requests should contain the username and password in a SOAP header (requires Username Token). Hence all registered user on mooshup can access this service. A client for this scenario would be simple as,



invokeSecuredService.inputTypes={"firstParam" : "string" , "secondParam" : "string"};
invokeSecuredService.outputType="string";
function invokeSecuredService(firstParam, secondParam) {
var request = new WSRequest();
var options = new Array();
options.encryptionUser = "keithspublickey";
options.username = "yourUsername";
options.password = "yourPassword";
var payload = {firstParam}{secondParam};
var result;
try {
var service = new QName("http://services.mashup.wso2.org/securedService", "securedService");
request.openWSDL("http://mooshup.com/services/keith/securedService?wsdl", false, options, service, "SOAP12Endpoint");
request.send("demo", payload);
var response = request.responseE4X;
result = response["return"].toString();
} catch (e) {
system.log(e.toString(),"error");
return result = e.toString();
}
return result;
}


You could follow the "Invoking Web Services from a Mashup" tutorial to get a feel of how easy it is to access web services using the WSO2 Mashup Server.

No comments: