node-red-bluemix-nodes
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -21,7 +21,6 @@ /** | ||
https = require('https'), | ||
url = require('url'), | ||
url = require('url'), | ||
vcap = JSON.parse(process.env.VCAP_SERVICES || "{}"), | ||
services = null, serviceList = null, | ||
parseXMLString = require('xml2js').parseString, | ||
isDev = false; | ||
parseXMLString = require('xml2js').parseString; | ||
@@ -31,4 +30,2 @@ services = vcap["businessrules"]||[]; | ||
console.log("[businessrules] Found these Business Rules services: ", serviceList); | ||
// make these names available to the node configuration | ||
@@ -44,11 +41,11 @@ RED.httpAdmin.get('/business-rules/vcap', function(req, res) { | ||
console.log("[businessrules] Looking for rulesets under ", serviceName); | ||
services.forEach(function (service) { | ||
services.some(function (service) { | ||
if (service.name === serviceName) { | ||
selectedService = service; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
if (!selectedService) { | ||
console.log("[businessrules] No service named " + config.service); | ||
res.json([]); | ||
@@ -58,4 +55,2 @@ return; | ||
console.log("[businessrules] Endpoint is ", selectedService.credentials.executionAdminRestUrl); | ||
var restUrl = url.parse(selectedService.credentials.executionAdminRestUrl); | ||
@@ -84,3 +79,2 @@ | ||
serviceResp.on('data', function(data) { | ||
console.log('data :' + data); | ||
responseString += data; | ||
@@ -131,3 +125,2 @@ }); | ||
} catch (e) { | ||
console.log('not JSON'); | ||
return false; | ||
@@ -142,4 +135,3 @@ } | ||
if (err) { | ||
console.log('isXMLString error:', err); | ||
b=false; | ||
b = false; | ||
} | ||
@@ -166,8 +158,8 @@ }); | ||
} | ||
console.log("[businessrules] Selected service is ", selectedService); | ||
services.forEach(function (service) { | ||
services.some(function (service) { | ||
if (service.name === selectedService) { | ||
node.selectedService = service; | ||
console.log("[businessrules] Selected service is well defined in configuration : ", service); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
@@ -185,3 +177,3 @@ if (!node.selectedService) | ||
function verifyPayload(node, msg) { | ||
function verifyPayload(node, msg, params) { | ||
if (!msg.payload) { | ||
@@ -197,5 +189,4 @@ node.status({fill:'red', shape:'ring', text:'missing payload'}); | ||
} | ||
node.isJsonPayload = isJSONString(msg.payload); | ||
node.isXmlPayload = isXMLString(msg.payload); | ||
if (node.isJsonPayload==false && node.isXmlPayload==false) | ||
params.payloadType = isJSONString(msg.payload) ? "application/json" : (isXMLString(msg.payload) ? "application/xml" : null ); | ||
if (params.payloadType === null) | ||
{ | ||
@@ -206,7 +197,6 @@ node.status({fill:'red', shape:'ring', text:'bad format payload'}); | ||
} | ||
console.log('debug : return true'); | ||
return true; | ||
} // function | ||
function executeService(node, msg, config) { | ||
function executeService(node, msg, config, params) { | ||
var restUrl = null, dataString = null, encodedCredentials = null, | ||
@@ -217,15 +207,7 @@ headers = null, options = null, req = null, contentType = null; | ||
dataString = msg.payload; | ||
// encode 'user:password' in Base64 string for basic authentication of the execution API | ||
encodedCredentials = new Buffer(node.selectedService.credentials.user + ':' + | ||
node.selectedService.credentials.password).toString('base64'); | ||
console.log("[businessrules] Submitting payload: ", dataString); | ||
if (node.isJsonPayload==true) | ||
contentType = 'application/json'; | ||
else | ||
contentType = 'application/xml'; | ||
headers = { | ||
'Content-Type' : contentType, | ||
'Content-Type' : params.payloadType, | ||
'Content-Length' : dataString.length, | ||
@@ -242,5 +224,2 @@ 'Authorization' : 'Basic ' + encodedCredentials | ||
if (isDev===true) | ||
console.log('options : ', options); | ||
req = https.request(options, function(resp) { | ||
@@ -252,4 +231,2 @@ var responseString = ''; | ||
responseString += data; | ||
if (isDev===true) | ||
console.log("receiving data : " + data); | ||
}); | ||
@@ -282,3 +259,3 @@ | ||
var node = this, b = false; | ||
var node = this; | ||
@@ -288,17 +265,10 @@ RED.nodes.createNode(this, config); | ||
node.on('input', function (msg) { | ||
//var params = {}; | ||
var params = {}; | ||
node.status({}); | ||
b = verifyServiceCredentials(node, msg); | ||
if (!b) { | ||
return; | ||
} | ||
b = checkSelectedServiceExists(node, msg, config.service); | ||
if (!b) { | ||
return; | ||
} | ||
b = verifyPayload(node, msg); | ||
if (!b) { | ||
return; | ||
} | ||
executeService(node,msg,config); | ||
if (verifyServiceCredentials(node, msg) && | ||
checkSelectedServiceExists(node, msg, config.service) && | ||
verifyPayload(node, msg, params)) { | ||
executeService(node,msg,config, params); | ||
} | ||
}); | ||
@@ -305,0 +275,0 @@ } |
{ | ||
"name": "node-red-bluemix-nodes", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "A collection of extra Node-RED nodes for IBM Bluemix.", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
131835
1405