Over a million developers have joined DZone.
Platinum Partner

How to Invoke a Web Service with Jaggery

The Web Dev Zone is brought to you in partnership with Mendix. Download this Forrester Report to gain a better understanding of the low-code platform market and how to make a strategic platform selection you won’t regret.

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;
   }
}

The Web Dev Zone is brought to you in partnership with Mendix. Better understand the aPaaS landscape and how the right platform can accelerate your software delivery cadence and capacity with the Gartner 2015 Magic Quadrant for Enterprise Application Platform as a Service.

Topics:

Published at DZone with permission of Achala Chathuranga Aponso , DZone MVB .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}