SAP / node-rfc

Asynchronous, non-blocking SAP NW RFC SDK bindings for Node.js
Apache License 2.0
249 stars 73 forks source link

How works Client with mysapsso2 ? #221

Closed ikit closed 2 years ago

ikit commented 2 years ago

Question Hi, I'm trying to create a connection to SAP using node-rfc with user sso token. The creation of the Client doesn't raise any error, but then when I try to call a query, nothing append (no result, no exception catched).

Below the parameters I provide to the client.

const client = new Client({
      user: user.id,
      mysapsso2: user.sso,
      ashost: process.env.SAP_HOST,
      mshost: process.env.SAP_MHOST,
      r3name: process.env.SAP_R3NAME,
      sysnr: process.env.SAP_SYSNR,
      client: process.env.SAP_CLIENT,
      lang: process.env.SAP_LANG
    });
await client.open();
// client.alive <= true;

const sapResult = await client.call(name, params).catch(...);

Note that all works fine if a use Client pool with a generic user with login/pwd authent

const pool = new Pool({
    user: process.env.SAP_USER,
    passwd: process.env.SAP_PASSWORD,
    ashost: process.env.SAP_HOST,
    r3name: process.env.SAP_R3NAME,
    sysnr: process.env.SAP_SYSNR,
    client: process.env.SAP_CLIENT,
    lang: process.env.SAP_LANG
  });
const client = (await pool.acquire()) as Client;
...
bsrdjan commented 2 years ago

The usage of connection parameters like ashost, mshost, mysapsso2 etc. is described in sapnwrfc.ini file of SAP NWRFC SDK. It is located in SDK demo folder:

cd $SAPNWRFC_HOME/demo

Logs can be activated using rfc_trace connection parameter, which is also described in sapnwrfc.ini. Use the RFC_TRACE=3 in DEFAULT section for the most detailed trace.

You can use your own sapnwrfc.ini and maintain destinations' connection parameters there, like:

sapnwrfc.ini

DEFAULT
#RFC_TRACE=3 # 'global' trace level

DEST=QM7
USER=demo
PASSWD=welcome
ASHOST=ldciqm7
SYSNR=00
CLIENT=005
LANG=EN
RFC_TRACE=2 # 'local' trace level

DEST=MME
USER=demo
PASSWD=welcome
#ASHOST=coevi51
ASHOST=10.68.110.51
SYSNR=00
CLIENT=620
LANG=EN

Destinations can be used with client or pool connections, like:

const client = new Client({dest: "MME"});

const pool = new Pool({connectionParameters: {dest: "OM7"} });

Hope this helps with further testing.

ikit commented 2 years ago

Hi, thanks for your answer. But even if I set the RFC_TRACE=3 in the sapnwrfc.ini, I don't see more log when I run my code... but I thinks that is normal, because I hope that sapnwrfc lib don't load demo settings file when node-rfc use it.

In the Client constructor options, I see I can set trace which is EnumTrace type. But I cannot use this option in my code because the EnumTrace type is not exported by the node-rfc module.

how I'm supposed to use this option ?

I notice that If I provide a wrong mysapsso2, I got a RFC_ABAP_MESSAGE saying "SSO Ticket not interpretable". So I suppose that the connection between my application and the SAP server is ok (when I provide a good sso token). But then the client object didn't answer when I use the call method.

ikit commented 2 years ago

Hi

The main problem was that my application do lot of async call, and some of them were not well catched. That's why the rfc error was lost.

Now I properly catch errors, and solve it (bad network settings), the Client connection with SSO seems work well 👍 Thanks for the help.

bsrdjan commented 2 years ago

Glad to hear :) I was just writing the answer and let me share it anyway, it might help with tracing if needed later on.

But even if I set the RFC_TRACE=3 in the sapnwrfc.ini, I don't see more log when I run my code... but I thinks that is normal, because I hope that sapnwrfc lib don't load demo settings file when node-rfc use it.

The demo INI file is not used but SAP NWRFC SDK is looking for sapnwrfc.ini in current working folder. When sapnwrfc.ini is found there, the RFC_TRACE=3 in the DEFAULT section should provide the most detailed log. It can be also set as destination (system) connection parameter. SAP NWRFC SDK can search for sapnwrfc.ini also in another folder, set by setinifiledirectory add-on method.

EnumTrace is not exported and that will be fixed. In the meantime, the trace connection parameter can be set like:

 const connectionParameters = {
    user: "demo",
    passwd: "welcome",
    ashost: "10.11.12.13",
    sysnr: "00",
    client: "320",
    lang: "EN",
    trace:"3", // or '0', '1', '2'
};

But then the client object didn't answer when I use the call method.

Before using call() method you can check the client.alive flag or use the client.ping() method to check if the connection is open.

Some network error messages take 1 or 2 min to come up. You could eventually try to wait 2 min or so, to check if any errors reported from the call() method.

bsrdjan commented 2 years ago

It looks solved but please re-open if needed.