Enterprise Integration Zone is brought to you in partnership with:

I am a graduate of University of Westminster UK (IIT) B Sc Software Engineering ( First Class Honours). I am a Sun Certified Java Programmer for Java 2 platform, 1.5 versions (SCJP 1.5). – 93% and a Sun Certified Web Component Developer 97%. I work as a Software Engineer at WSO2. Achala is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

How to Invoke a Web Service with Jaggery

03.31.2013
| 1569 views |
  • submit to reddit

Here's a snippet for invoking Jaggery, a framework to write webapps and HTTP-focused web services for all aspects of the application: front-end, communication, Server-side logic and persistence in pure Javascript.

var invokeRetrieveArtifactId =  function (applicationKey,version,revision){
    var ws = require('ws');
var retrieveArtifactIdProcess = new ws.WSRequest();
var options = new Array();
options.useSOAP = 1.1;
options.action = "urn:retrieveArtifactId";
options["HTTPHeaders"] = [ { name : "Cookie", value :modManager.getAdminCookie() }];
var payload = '<p:RetrieveArtifactIdRequest xmlns:p="http://retrieve.core.appfactory.carbon.wso2.org"><p:applicationId>'+applicationKey+'</p:applicationId><p:version>'+version+'</p:version><p:revision>'+revision+'</p:revision></p:RetrieveArtifactIdRequest>';
var result;

try {
   var endPoint =getProperty('ServerUrls.AppFactory')+'RetrieveArtifactService'; // provide the endpoint
   retrieveArtifactIdProcess.open(options,endPoint, false);
   retrieveArtifactIdProcess.send(payload);
   result = retrieveArtifactIdProcess.responseE4X;
   var resultNS = new Namespace("http://retrieve.core.appfactory.carbon.wso2.org");
   var artifactDetails = result.resultNS::["return"].text()

   if(log.isDebugEnabled()){
       log.debug("Invoking service endpoint:"+endPoint+" returned result:"+result);
   }
    return artifactDetails;
} catch (e) {
   log.error("Error while retrieving the artifact id"+applicationKey + "\n"+e.message);
   throw "Error while retrieving the artifact id"+applicationKey;
   }
}
Published at DZone with permission of Achala Chathuranga Aponso, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)