Skip to Content
0
Feb 22, 2022 at 08:05 AM

Error: getaddrinfo ENOTFOUND when calling s/4 on-premise OData service from BTP via cloud connector

27149 Views

To all experts,

I am trying to consume s/4 on-prem service from a small application developed using cloud application programming model (nodejs). After CF deployment, triggering the unbound function "run_odata_query" causes the following error:

[APP/PROC/WEB/0] ENOTFOUND 22 Feb 2022, 15:42:57 (GMT+08:00)

[APP/PROC/WEB/0] -3008 22 Feb 2022, 15:42:57 (GMT+08:00)

[APP/PROC/WEB/0] Error: getaddrinfo ENOTFOUND vhppgpsdci.ppg.com 22 Feb 2022, 15:42:57 (GMT+08:00)

[APP/PROC/WEB/0] at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) 22 Feb 2022, 15:42:57 (GMT+08:00)

[APP/PROC/WEB/0] at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17)

.......

Hopefully, someone could shed some lights here.

Both destination and cloud connector have been setup by our Basis team.

Source code shown below.

const { executeHttpRequest, getDestination } = require("@sap-cloud-sdk/core")

module.exports = async function (srv) {

srv.on("run_odata_query", async (req) => {

const queryURL = `sap/opu/odata/sap/${req.data.query}`

try {

let response = await executeHttpRequest(

{

destinationName: req.data.destination, jwt: getJWT()

},

{

method: "GET",

url: queryURL

}

)

console.log('s4 response - ' + response.status)

console.log(response.data)

return response.data

}

catch (e) {

if (e.code) console.log(e.code)

if (e.errno) console.log(e.errno)

if (e.stack) console.log(e.stack)

if (e.message) console.log(e.message)

}

})

srv.on("get_destination", async (req) => {

try {

let dest = await getDestination(req.data.name, { userJwt: getJWT() })

console.log(dest.originalProperties)

return dest.originalProperties

}

catch (e) {

if (e.code) console.log(e.code)

if (e.errno) console.log(e.errno)

if (e.stack) console.log(e.stack)

if (e.message) console.log(e.message)

}

})

}

function getJWT() {

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

const grantType = `grant_type=client_credentials`;

const oVCAP_SERVICES = JSON.parse(process.env.VCAP_SERVICES);

const oServiceCredentials = oVCAP_SERVICES.connectivity[0].credentials;

const clientID = "client_id=" + oServiceCredentials.clientid;

const clientSecret = "client_secret=" + oServiceCredentials.clientsecret;

const oauthURL = oServiceCredentials.token_service_url + "/oauth/token";

var xhr = new XMLHttpRequest();

xhr.open("POST", oauthURL, false);

//adding request headers

xhr.setRequestHeader("Accept", "application/json");

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

//sending request in synchronous mode

xhr.send(`${grantType}&${clientID}&${clientSecret}`);

if (xhr.status === 200) {

var resp_json = JSON.parse(xhr.responseText)

return resp_json.access_token

}

}