processDirective(requestData,function(err,responseData){ if(err) { if(!err.code) { err.code = 'integration.processDirective'; } var RestResponse = {targetType:'RestResponse',status:'ERROR',errors:[]}; // Remove password and token from request credentials for logging if(requestData.options && requestData.options.credentials) { requestData.options.credentials = { username: requestData.options.credentials.username }; } // // The server only supports certain known properties in CdmError. To preserve our error data we // clone the error object so we can wrap it in the protected 'info' property; remove code and // message (since they are redundant) and add badRequest:requestData. // var info = emutils.clone(err); delete info.code; delete info.message; info.badRequest = requestData; RestResponse.errors.push({ targetType:'CdmError', code:err.code, message:(typeof err.message !== 'undefined' ? err.message : err.message), info:info }); console.log('Proxy returning error to MMS:'); //console.log(util.inspect(RestResponse,false,null)); console.dir(RestResponse); response.end(JSON.stringify(RestResponse, null, '\t')+'\n'); } else { // Do some error checking in case processDirective is badly behaved if(typeof responseData === 'undefined') { responseData = new Object(); console.log('Undefined response returned for request: ' + postData); } else if(responseData === null) { responseData = new Object(); console.log('Null response returned for request: ' + postData); } else if(responseData === '') { responseData = new Object(); console.log('Empty string response returned for request: ' + postData); } var responseString = JSON.stringify(responseData, null, '\t')+'\n'; // if(verbose) { // console.log('VERBOSE, REQUEST: ' + postData + ' RESPONSE: ' + responseString); // } response.end(responseString); } });
/**Call a SOAP operation @method call @static @param {Object} request The SOAP body, expressed as a JavaScript object @param {HttpOptions} httpOptions HTTP options for calling the target service @param {RequestDescriptor} requestDesc A description of the SOAP operation's request @param {DeserializationOptions} deserializationOptions Options for converting the SOAP response into a JavaScript object @param {ResponseDescriptor} responseDesc A description of the SOAP operation's response @param {Function(err, response)} cb Callback **/ function call(request, httpOptions, requestDesc, deserializationOptions, responseDesc, cb) { var xmlRequest = serializer.serialize(request, requestDesc); //console.log(xmlRequest); httpOptions = em_utils.clone(httpOptions); if (!httpOptions.headers) { httpOptions.headers = {}; } var soapAction; if (em_utils.hasValue(requestDesc.soapAction)) { soapAction = requestDesc.soapAction; } else if (em_utils.hasValue(httpOptions.soapAction)) { soapAction = httpOptions.soapAction; } else { soapAction = ""; } switch (requestDesc.soapVersion) { case "1.1": httpOptions.headers["content-type"] = "text/xml"; httpOptions.headers.soapAction = '"' + soapAction + '"'; break; case "1.2": var hdr = soapAction = "application/soap+xml"; if (soapAction) { hdr += ";action=soapAction"; } httpOptions.headers["content-type"] = hdr; break; default: throw new Error("Unknown SOAP version: " + requestDesc.soapVersion); } httpRequest.httpRequest(httpOptions, xmlRequest, function(err, httpResponse) { if (err) { cb(err); return; } deserializer.deserialize(httpResponse.body, responseDesc, deserializationOptions, function(err, response) { if (err && !err.fault && httpRequest.isErrorStatus(httpResponse.status)) { err = new Error("Error contacting service: HTTP status: " + httpResponse.status); } cb(err, response); }); }); }