SAP / cloud-sdk-java

Use the SAP Cloud SDK for Java to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
22 stars 14 forks source link

When I send a GET request to ODATA using SAP Cloud SDK in SAP Business Application Studio, an empty object is returned #650

Open absmh opened 3 days ago

absmh commented 3 days ago

Issue Description In SAP Business Application Studio, I am developing a Java program that uses SAP Cloud SDK to send a GET request to ODATA to retrieve data. When executing a GET request, some ODATA successfully retrieves data, but there is an issue where an empty object is returned for some ODATA. Even if an empty object is returned, no error occurs and the program ends normally. In addition, when executing a request with the SAP standard transaction code "/n/IWFND/GW_CLIENT" or Postman for the problematic ODATA, data can be retrieved without any problems. Data cannot be retrieved only when calling from SAP Business Application Studio.

Has there been any confirmed occurrence of such an issue to date? *Due to confidentiality reasons, I cannot share the details of the project, so I am providing the minimum information possible to start with. I will add more information as necessary.

Supplementary Information --ODATA for which data cannot be obtained: 1)ODATA:API_PRODUCT_SRV  Entity:A_ProductPlant、A_ProductStorageLocation、A_ProductValuation 2)ODATA:API_COSTCENTER_SRV  Entity:A_Costcenter 3)ODATA:API_MATERIAL_STOCK_SRV  Entity:A_MatlStkInAcctMod 4)ODATA:API_GLACCOUNTINCHARTOFACCOUNTS_SRV  Entity:A_GLAccountText

--Sample source code: Here is the source code to execute a GET request on API_PRODUCT_SRV.A_ProductStorageLocation.

private static final HttpDestination destination = DestinationAccessor.getDestination("destination name").asHttp();
private static final DefaultProductSrvService service = new DefaultProductSrvService().withServicePath("service path");
final List<StorageLocationData> result = service.getAllProductStorageLocation().executeRequest(destination);

--SDK version: <5.14.0> --Project type: MTA project --Development environment: SAP Business Application Studio

KavithaSiva commented 3 days ago

Hi @absmh,

Are you trying to access the OData service on an on-premise system or a Cloud system? Could you please cross-check with this guide, to see if your set up with Business Application Studio is right?

The code snippet looks good to me, so if there is an issue while retrieving data you should ideally get an ODataException. Do you have any additional code in a catch block to return gracefully in case of failures?

Would it be possible to get debug logs or debug your application to see what exactly happens? And if the OData service itself is returning these empty results?

Regards, Kavitha

absmh commented 1 day ago

Hi @KavithaSiva , Sorry for the late reply. Thank you for your comment.

I am trying to access an OData service on an on-premise system.

I checked the guide and there seemed to be no problem with the Business Application Studio setup.

I omitted this in the source code I provided, but the part where the data is retrieved is surrounded by a try-catch so that the ODataException can be caught. There is also an outer try-catch so that other exceptions can be caught. However, when I run the program, no exceptions occur and it ends normally, so I cannot find out what is wrong.

try{
    ・・・
    try{
        final List<StorageLocationData> result = service.getAllProductStorageLocation().executeRequest(destination);
    }catch(ODataException e){
                //Outputting logs
        throw new ODataException(e);
    }
    ・・・
}catch(Exception e){
         //Outputting logs
    throw new Exception(e);
}

If the code snippet is correct, are there any other possible causes? If there are any points that I should pay attention to, such as environment settings or permission settings, I would appreciate it if you could let me know.

Thank you,