Skip to Content
0
Sep 13 at 05:15 AM

Error in Cloud to on-prem connectivity of Hana DB with NodeJS Apllication

106 Views

I was trying to connect the on-premise HANA DB (not the Application layer with XSA) from SAP BTP with NodeJS Application. I have been referring the following blog for the connectivity with slight changes. Below is the code that I have used to connect the on-premise system,

const express = require('express')
const app = express();
var hdbext = require('@sap/hdbext');

const VCAP_SERVICES = {
    "clientid": "xx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "clientsecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx===",
    "url": "https://xxxxxxxxxxx.authentication.eu10.hana.ondemand.com",
    "identityzone": "xxxxxxxxxxxxxxx",
    "tenantid": "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
    "tenantmode": "dedicated",
    "verificationkey": "-----BEGIN PUBLIC KEY-----xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-----END PUBLIC KEY-----",
    "xsappname": "clonexxxxxxxxxxxxxxxxxxxxxxbad!b522503|connectivity!b17",
    "uaadomain": "authentication.eu10.hana.ondemand.com",
    "onpremise_proxy_host": "connectivityproxy.internal.cf.eu10.hana.ondemand.com",
    "onpremise_proxy_http_port": "20003",
    "onpremise_proxy_ldap_port": "20001",
    "onpremise_proxy_port": "20003",
    "onpremise_proxy_rfc_port": "20001",
    "onpremise_socks5_proxy_port": "20004",
    "token_service_domain": "authentication.eu10.hana.ondemand.com",
    "token_service_url": "https://xxxxxxxxxxxx.authentication.eu10.hana.ondemand.com"
};
const conSrvCred = VCAP_SERVICES;

app.listen('3000', function () {
    console.log('')
    console.log('CloudToOnprem application started')
})

app.get('/callonprem', async function (req, res) {
    // Call to on onPrem via SCC utilizing socks5 proxy port
    try {
        const connJwtToken = await _fetchJwtToken(conSrvCred.token_service_url, conSrvCred.clientid, conSrvCred.clientsecret);
        const result = await _callOnPremSql(conSrvCred.onpremise_proxy_host, conSrvCred.onpremise_socks5_proxy_port, connJwtToken);
        res.json(result);
    } catch (e) {
        res.json({
            'msg': JSON.stringify(e)
        });
    }
});


const _fetchJwtToken = async function (oauthUrl, oauthClient, oauthSecret) {
    return new Promise((resolve, reject) => {
        const tokenUrl = oauthUrl + '/oauth/token?grant_type=client_credentials&response_type=token'
        const config = {
            headers: {
                Authorization: "Basic " + Buffer.from(oauthClient + ':' + oauthSecret).toString("base64")
            }
        }
        axios.get(tokenUrl, config)
            .then(response => {
                resolve(response.data.access_token)
            })
            .catch(error => {
                reject(error)
            })
    })
}

// SQL _onCallOnPrem
const _callOnPremSql = async function (connProxyHost, connProxyPort, connJwtToken) {
    return new Promise((resolve, reject) => {
        // Quick explanation of parameters used:
        // serverNode: Is the virtual host/port configured in SCC
        // UID: db userid
        // PWD: db password
        // proxyHostname: SCP/BTP proxy required to access SCC
        // proxyPort: SCP/BTP proxy port required to access SCC (needs to be socks5 port for SQLDBC)
        // sslValidateCertificate: Enable validation on whether cert is from known trusted CA
        let scpAccoundId = "1232-423423-423-223424";
        var connOptions = {
            host: 'xx.xx.xx.xx',
            port: 30015,
            user: 'xxxxxxxxxxx',
            password: 'abcdefgh',
            proxyHostname: connProxyHost,
            proxyPort: connProxyPort,
            proxyHttp: true,
            proxyScpAccount: "Basic " + Buffer.from(scpAccoundId).toString("base64"),
            proxyUserName: connJwtToken,
            sslValidateCertificate: false
        };
        try {
           
            hdbext.createConnection(connOptions, function (error, client) {
                let responseJson = {};
                if (error) {
                    reject(error);
                } else {
                    client.exec('SELECT TOP 1 * FROM "Schema_name"."Table";', function (err, rs) {
                        if (err) {
                            reject(err);
                        } else {
                            responseJson.resultset = rs;
                            resolve(responseJson);
                        }

                    });
                }
            });

        } catch (error) {
            console.log("error==============>  ", error)
            reject(error);
        }
    })
}


When I run the application and try to connect on-premis Hana DB I am getting the following error,

{ Error: Connection failed (RTE:[89008] Socket closed by peer (10.34.123.12:30015))

I am not able to connect the on-prem HANA DB with tcp connection.Is there any changes that I have to do to connect on-prem hana?