Search code examples
node.jsapigee

NodeJS async http request ArrayBuffer not defined in Apigee


Here's my code in nodeJS.. When I deployed it to my local it is always run ok, but when i deployed it on the production I always got an error "ArrayBuffer not defined". Can someone tell me what it caused? I'll tried to add ArrayBuffer but I got the same error. Thanks

  var svr = http.createServer(function(req, resp) {
  var response = [];  
  var calls = [];
  var windowLiveId;
  var huaweiReturnCode;
  var serviceId = apigeeAccess.getVariable(req,'subscription.serviceid');
  var ericssonRequestBody = {"offerId":serviceId,"generateBillingRecord":true };    

    calls.push(function(callback) {
           http.get('http://butcha-test.apigee.net/v1/accounts/', function (resource) {
                resource.setEncoding('binary');
                resource.on('data', function (data) {
                    windowLiveId = JSON.parse(data).AccountId;          
                     request.post({
                        url:'http://butcha-test.apigee.net/v1/erickson/'+windowLiveId,
                            method: 'POST',
                            headers:{
                                 'Content-Type': 'application/json'
                            },
                            body: JSON.stringify(ericssonRequestBody)

                        }, function(error,res,body){
                            apigeeAccess.setVariable(req,"ericsonStatus",(/2[0-9][0-9]/.test(res.statusCode)) ? "success":"fail");
                            apigeeAccess.setVariable(req,"ericsonStatusCode",res.statusCode);
                            callback(); 
                        });
                });
           });
       });

      calls.push(function(callback){
          request.post({
                url:'http://morning-sea-3467.getsandbox.com/mockOverseaBossServiceSoapBinding',
                method: 'POST',
                headers: {'content-type' : 'application/xml'},
                body: huaweiSoapRequest

            }, function(error,res,body){
                response.push(body);
                var tag = "<bean:returnCode>";
                var x = body.indexOf(tag) + tag.length;
                huaweiReturnCode = body.substring(x, (x+1));
                apigeeAccess.setVariable(req,"huaweiReturnCode",huaweiReturnCode);
                apigeeAccess.setVariable(req,"huaweiStatusResult",(huaweiReturnCode =="0")? "success":"fail");
                callback(); 
            });
    }); 

    async.parallel(calls, function(){
      resp.end(str2ab(response.toString));      
    });

});

Solution

  • Maybe because of the version of your Apigee? Because older version of Apigee is not supported nodeJs