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.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

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);
   result = retrieveArtifactIdProcess.responseE4X;
   var resultNS = new Namespace("http://retrieve.core.appfactory.carbon.wso2.org");
   var artifactDetails = result.resultNS::["return"].text()

       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.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


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