cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming External Service Through CAP Java

surajg12
Explorer
0 Kudos
959

I have been trying to consume NorthWind External service in my project and getting the following error

my handler code is bellow

My .cds file is bellow

Accepted Solutions (0)

Answers (1)

Answers (1)

marcbecker
Product and Topic Expert
Product and Topic Expert

The error from the OData endpoint is not providing much inner details, in your application logs you should find a detailed exception that points to the root cause of the error.

Looking at your code it looks like you are creating an infinite recursion, as your event handler is registered on CatalogService, but you are also delegating your Select query to CatalogService again, effectively calling your own method.

I think the @Qualifier annotation on the external service should not be CatalogService, but the name of the remote service NorthWind.

surajg12
Explorer
0 Kudos

Hi marcbecker thanks for your response

i replaced CatalogService with NorthWind and now i am getting error message as

{"error": {"code": "500","message": "Error executing the statement"}}

@Autowired @Qualifier("NorthWind") private CqnService external;
@On(event = CqnService.EVENT_READ, entity = "CatalogService.Products") public void onRead(CdsReadEventContext context) { CqnSelect select = Select.from("CatalogService.Products"); Result result = external.run(select); context.setResult(result);

}

i am new to cap java pls help

marcbecker
Product and Topic Expert
Product and Topic Expert
0 Kudos

Again, please provide the error message that you see in the application logs rather. It contains more information.

Most likely you didn't configure the NorthWind as a remote service correctly, please take a look at the documentation here: https://cap.cloud.sap/docs/java/remote-services

Please also make sure that the dependency to cds-feature-remote-odata is present in your Maven dependencies.

surajg12
Explorer
0 Kudos

here are the error log and yes i have added the required maven dependencies

marcbecker
Product and Topic Expert
Product and Topic Expert
0 Kudos

Please check that you have configured the NorthWind service as a RemoteService in the configuration, as described here: https://cap.cloud.sap/docs/java/remote-services. The query is delegated to the database (CAPs default behaviour, if no configuration is present) and not the remote OData API.