Virtual path, parallelism problem

Imported Google Group message.
Sender:Saheed Chavarría.
Date:Tuesday, 17 November 2015 08:36:42 UTC.

hi Saheed,

It might just be because there is no meta_data associated with the token used to make the request, in the return statement, change it to just return an empty object:

From:

function batchTest(request, session, config) {
// Set up a response object
var response = {
Body: “”
Headers: {
“test”: “virtual-header-1”,
“test-2”: “virtual-header-2”,
“content-type”: “application/json”
},
Code: 200
}

// Batch request
var batch = {
    "requests": [
        {
            "method": "GET",
            "headers": {
                "x-tyk-test": "1",
                "x-tyk-version": "1.2",
                "authorization": "1dbc83b9c431649d7698faa9797e2900f"
            },
            "body": "",
            "relative_url": "http://httpbin.org/get"
        },
        {
            "method": "GET",
            "headers": {},
            "body": "",
            "relative_url": "http://httpbin.org/user-agent"
        }
    ],
    "suppress_parallel_execution": false
}


log("[Virtual Test] Making Upstream Batch Request")
var newBody = TykBatchRequest(JSON.stringify(batch))


// We know that the requests return JSON in their body, lets flatten it
var asJS = JSON.parse(newBody)
for (var i in asJS) {
    asJS[i].body = JSON.parse(asJS[i].body)
}


// We need to send a string object back to Tyk to embed in the response
response.Body = JSON.stringify(asJS)


return TykJsResponse(response, session.meta_data)

}

To:

function batchTest(request, session, config) {
// Set up a response object
var response = {
Body: “”
Headers: {
“test”: “virtual-header-1”,
“test-2”: “virtual-header-2”,
“content-type”: “application/json”
},
Code: 200
}

// Batch request
var batch = {
    "requests": [
        {
            "method": "GET",
            "headers": {
                "x-tyk-test": "1",
                "x-tyk-version": "1.2",
                "authorization": "1dbc83b9c431649d7698faa9797e2900f"
            },
            "body": "",
            "relative_url": "http://httpbin.org/get"
        },
        {
            "method": "GET",
            "headers": {},
            "body": "",
            "relative_url": "http://httpbin.org/user-agent"
        }
    ],
    "suppress_parallel_execution": false
}


log("[Virtual Test] Making Upstream Batch Request")
var newBody = TykBatchRequest(JSON.stringify(batch))


// We know that the requests return JSON in their body, lets flatten it
var asJS = JSON.parse(newBody)
for (var i in asJS) {
    asJS[i].body = JSON.parse(asJS[i].body)
}


// We need to send a string object back to Tyk to embed in the response
response.Body = JSON.stringify(asJS)


return TykJsResponse(response, {})

}

Cheers,
Martin