cancel
Showing results for 
Search instead for 
Did you mean: 

CAP - JAVA Actions and Functions

FatihOrnek
Explorer
0 Kudos

Hi,

This is how I defined action.

When I trigger it via Business App Studio, it keeps asking for username password. Where could it be wrong?

I am testing the example below.

I am referring to URL:

https://cap.cloud.sap/docs/java/provisioning-api#implementing-event-handlers

Please get back to me on the following feedback:

marcbecker
Contributor
0 Kudos

Hi,

can you please provide a little more context? How are you triggering the action? Can you please provide the request URL you are trying? With which parameters are you trying it?

Best regards,
Marc

FatihOrnek
Explorer
0 Kudos

Hi marcbecker ,

I have defined an cds entity as follows. There is an action named getUserInfo.

I open the test screen with terminal mvn clean spring-boot: run. I am sending parameters over the link as follows. But I'm getting an authorization error. There is a problem with the link I defined as action. Other service triggers work correctly and do not give authorization errors.

Sample EventHandler code.

     @On(event = "getUserInfo", entity = "SfapiService.SFUserInfo")
     public void getUserInfo(GetUserInfoContext context) {
        
        Integer stars = context.getId();
        SFUserInfoReviews inf = SFUserInfoReviews.create();
        inf.setId(stars);
      
        context.setResult(inf);
    }

marcbecker
Contributor

The URL is not correct. Please have a look at the OData V4 specification on how to trigger actions: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31359014

First of all, Actions need to be triggered using a POST request, not a GET request. The parameters are provided in a JSON Map in the Body.

The action you have defined here is bound to the entity SFUserInfo, therefore the URL to the action should look like this:

/odata/v4/SfapiService/SFUserInfo(<ID>)/SfapiService.getUserInfo

If you don't want the action to be bound to an entity you should define an action directly in the service like outlined here: https://cap.cloud.sap/docs/cds/cdl#actions

In that case you also shouldn't provide an entity in your event handler registration.

FatihOrnek
Explorer
0 Kudos

Thanks, Marc. This method works fine.

View Entire Topic
FatihOrnek
Explorer
0 Kudos

Hi heli.heli ,

I used CDS custom actions and functions structure instead of Java.

Thanks.

0 Kudos

Thank you for your answer.