cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error while consuming Northwind service into CAP (java) application

Poorva_Sonawane
Product and Topic Expert
Product and Topic Expert
0 Kudos
914

Hello,

I am trying to import and mock external service (Northwind) into my bookstore app (java) by following steps given in: https://cap.cloud.sap/docs/guides/using-services

I followed below steps:

1. import API definition using cds import command

cds import ~/Downloads/NorthWind.edmx

It created these files in srv/external folder

Configured remote service in application.yaml and added dependency to pom.xml

When running using cloud profile,

I get ""Failed to start a new transaction"" error to access entities under Northwind services

2. Mock remote service as OData service:

- Added mocked spring profile in application.yaml as below:

- Added DestinationConfiguration.java file as follows:

When running app with mocked profile :

mvn spring-boot:run -Dspring-boot.run.profiles=default,mocked

I am getting this error:

Can someone help?

Regards,

Poorva.

Accepted Solutions (0)

Answers (1)

Answers (1)

marcbecker
Product and Topic Expert
Product and Topic Expert
0 Kudos

Your application.yaml is not valid. Under application.services and remote.services we expect a Map or array of services and not directly a service definition. You need to rewrite it like this:

cds:
  application.services:
  - name: "NorthWind-mocked"
    model: "NorthWind"
    serve.path: "NorthWind
  remote.services:
  - name: NorthWind
    destination:
      name: "northWind-mocked"
Poorva_Sonawane
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi marcbecker,

Thanks for the answer.

Now I am able to run the application locally.

But when I click on service which extends external entity, I get this error : "Error executing the statement"

I have defined entity "clothes" which extends external entity "Products" from mocked Northwind service as follows

Also added "ClothStore" service which containing "Clothes" entity

When I run application on localhost and click on clothes entity under clothstore service,

I get 500 error with message "Error executing the statement".

I see below error in console,

Caused by: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [259]: invalid table name: Could not find table/view CLOTHSTORE_CLOTHES in schema 829841A637474F279F717E05EC123891: line 1 col 118 (at pos 117)

Also,

in schema.sql, I don't find any table generated for that entity.

Could you please help me resolving this issue ?

Regards,

Poorva.

marcbecker
Product and Topic Expert
Product and Topic Expert
0 Kudos

This seems to be the default behaviour of delegating the query to the database. If you want to delegate incoming API calls to the external service you need to write a custom ON handler for this.

I'd recommend you read through our "Consuming Services" cookbook here: https://cap.cloud.sap/docs/guides/using-services
This case is described exactly here: https://cap.cloud.sap/docs/guides/using-services#expose-remote-services