cancel
Showing results for 
Search instead for 
Did you mean: 

CAP - JAVA localized texts service expose

WonseokChoe
Explorer
0 Kudos

sample: https://github.com/SAP-samples/cloud-cap-samples-java.git

- cds path: cloud-cap-samples-java/srv/review-service.cds

call odata url: https://workspaces-ws-#####-app1.####.trial.applicationstudio.cloud.sap/api/review/Books_texts

return value:

{ "error": { "code": "403001", "message": "Not authorized to send event 'READ' to 'ReviewService.Books.texts'" } }

java stack error:

2021-07-20 17:33:59.428 INFO 1484 --- [nio-8080-exec-5] c.s.c.a.o.v4.processors.CdsProcessor : Exception marked the ChangeSet 16 as cancelled: Not authorized to send event 'READ' to 'ReviewService.Books.texts' (service 'ReviewService', event 'READ', entity 'ReviewService.Books.texts')

Accepted Solutions (1)

Accepted Solutions (1)

marcbecker
Contributor
0 Kudos

The behaviour of CAP Java is the expected one here. The Books_texts entity in the ReviewService in the Java sample is not explicitly exposed by the service. It is implicitly auto-exposed. Implicitly auto-exposed entities are not accessible directly, but only via proper navigation paths. You would need to run one of the following requests to obtain the texts of books:

https://workspaces-ws-#####-app1.####.trial.applicationstudio.cloud.sap/api/review/Books?$expand=tex...
https://workspaces-ws-#####-app1.####.trial.applicationstudio.cloud.sap/api/review/Books(...)/texts

In case you directly want to make the entity available you need to explicitly declare it in the service, for example:

extend service ReviewService with { 
    @requires: 'any' // or any other appropriate authorization
    entity Books.texts as projection on my.Books.texts;
}

See also more information about this in our documentation: https://cap.cloud.sap/docs/guides/authorization#events-and-auto-expose

WonseokChoe
Explorer
0 Kudos

Dear Becker,

Thank you for the advice.

I solved it as below through your advice.

annotate Books.texts with @cds.autoexpose;                  //In Node.js(cds watch) 
annotate Books.texts with @(cds.autoexpose,requires:'any'); //In Java(mvn spring-boot:run) //cds.services.version@1.15.3,@sap/cds@5.3.2

//Not Working//annotate Books.texts with @(cds.autoexpose,requires:'any'); //In Java(mvn spring-boot:run) //cds.services.version@1.15.3,@sap/cds@4.6.6

Answers (0)