Skip to Content
0
Aug 23, 2020 at 02:43 PM

PROBLEM consuming On-premise external services with latest CAP update

296 Views

Hi, everybody,

With the last CAP update (4.1.7) the On-premise external services I was using start giving the following error:

<error xmlns="http://docs.oasis-open.org/odata/ns/metadata">
<code>ERR_TLS_CERT_ALTNAME_INVALID</code>
<message>
Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:www.xxxxxxxxxxx.com.mx, DNS:xxxxxxxxxxx.com.mx
</message>
</error>

My configuration of the external service in the package.json:

"Z_OD_SCP_CORE_0001_SRV": {
        "kind": "odata",
        "model": "srv/external/Z_OD_SCP_CORE_0001_SRV",
        "credentials": {
          "destination": "Z_OD_SCP_CORE_0001_DEST",
          "requestTimeout": 30000
        }
      }

My service CDS (srv/Z_OD_SCP_CORE_0001_SRV.cds)

using {Z_OD_SCP_CORE_0001_SRV as external} from './external/Z_OD_SCP_CORE_0001_SRV.csn';

service CoreService {
    @readonly
    entity Sociedades as projection on external.SociedadSet;
}

Finally (srv/Z_OD_SCP_CORE_0001_SRV.js)

const cds = require('@sap/cds');

module.exports = cds.service.impl(async function () {
  const { Sociedades } = this.entities;
  const extSrv = await cds.connect.to('Z_OD_SCP_CORE_0001_SRV');

  this.on('READ', Sociedades, (req) => extSrv.tx(req).run(req.query));
});

Before the update this service was working perfect, but now it doesn't work. When I returned to version 4.1.5 it still stopped working normally, and started throwing me the following message:

<error xmlns="http://docs.oasis-open.org/odata/ns/metadata">
<code>500</code>
<message>Request failed with status code 404</message>
</error>

To solve this error I had to modify my original code in this way:

const cds = require('@sap/cds');

module.exports = cds.service.impl(async function () {
  const { Sociedades } = this.entities;
  const extSrv = await cds.connect.to('Z_OD_SCP_CORE_0001_SRV');
  const { SociedadSet } = extSrv.entities;

  this.on('READ', Sociedades, (req) => extSrv.tx(req).run(SELECT.from(SociedadSet)));
});

Doing a little research, I realized the following, doing some cosole.log:

Getting back to CAP 4.1.5 version, the code that previously worked, printing the CQN, i got this: (THIS IS NOT WORKING NOW)

  this.on('READ', Sociedades, (req) => {
    console.log(req.query);
    return extSrv.tx(req).run(req.query);
  });
[cds] - server listening on { url: 'http://localhost:4004' }
[ terminate with ^C ]

GET /core/Sociedades
{ SELECT: {
  from: {ref:['CoreService.Sociedades']},
  columns: [ {ref:['Bukrs']}, {ref:['Butxt']}, {ref:['Sort2']} ],
  orderBy: [ {ref:[ 'Bukrs' ], sort: 'asc' } ],
  limit: { rows: {val:1000} }
}}

with the change a made (THIS IS ACTUALLY WORKING)

  this.on('READ', Sociedades, (req) => {
    console.log(SELECT.from(SociedadSet));
    return extSrv.tx(req).run(SELECT.from(SociedadSet));
  });
[cds] - server listening on { url: 'http://localhost:4004' }
[ terminate with ^C ]


GET /core/Sociedades
{ SELECT: {
  from: {ref:['Z_OD_SCP_CORE_0001_SRV.SociedadSet']},
  columns: [
    {ref:[ 'Bukrs' ], as: 'Bukrs' },
    {ref:[ 'Butxt' ], as: 'Butxt' },
    {ref:[ 'Sort2' ], as: 'Sort2' }
  ]
}}

Notice the difference in the from property of the query.

This es the version of my libraries that I actually have:

cds --version 
@sap/cds: 4.1.5
@sap/cds-compiler: 1.35.0
@sap/cds-dk: 2.0.8
@sap/cds-foss: 2.0.0
@sap/cds-odata-v2-adapter-proxy: 1.4.42
@sap/cds-reflect: 2.12.2
@sap/cds-runtime: 2.1.7
@sap/cloud-sdk-core: 1.17.2
@sap/hana-client: 2.5.105
@sap/xsenv: 3.0.0
@sap/xssec: 3.0.9
Node.js: v12.18.3

Thanks in advance