Platinum Partner
css,enterprise-integration,javascript,tips and tricks,jaggery

How to Invoke a Web Service with Jaggery

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 {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}