Warm tip: This article is reproduced from stackoverflow.com, please click
java sap-cloud-platform sap-cloud-sdk

SFSF OData call: Failed to convert response into ODataFeed: An 'EdmSimpleTypeException' occurred

发布于 2020-05-11 16:46:36

Following the problem from question: Generate VDM for SFSF using Java in SAP Cloud SDK: Generated URI is wrong

I generated a Virtual Data Model from a metadata file from SFSF using the Maven plugin and SAP Cloud SDK for Java.

The generator works correctly, however the URI generated is not what SFSF is expecting:

  • Generated URI: /odata/v2/SFODataSet

  • Expected URI: /odata/v2 or /odata/v2/JobRequisition

(SFODataSet entity does not exist, and SFSF gives an error when trying to access it).

Anyway, I proceed and change the DEFAULT_SERVICE_PATH in the generated files to /odata/v2 and create the following servlet that includes the query:

@WebServlet("/req")
public class JobReqServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private static final Logger logger = LoggerFactory.getLogger(JobReqServlet.class);

    private final ErpHttpDestination destination = DestinationAccessor.getDestination("sfsf-sdk-dest").asHttp()
            .decorate(DefaultErpHttpDestination::new);


    @Override
    protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException {
        try {
            long id = 2126;
            final JobRequisition jobReqs = new DefaultRCMJobRequisitionService()
                .getJobRequisitionByKey(id)
                .execute(destination);
            response.getWriter().write("Done!");
        } catch (final ODataException e) {
            logger.error(e.getMessage(), e);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            response.getWriter().write(e.getMessage());
        }
    }
}

This queries a single job requisition (with the id 2126). There's no need to add the option .withServicePath() because it's already changed.

However, when running the app, I get an Internal Server Error after 10-20 second of waiting.

In the logs I can see the following:

  • The destination is fetched correctly
  • The HTTP request is correct
  • SFSF responds with the correct data

But just after the data is received there's an error:

"com.sap.cloud.sdk.odatav2.connectivity.ODataQuery","thread":"http-nio-0.0.0.0-8080-exec-3","level":"ERROR","categories":[],"msg":"Failed to convert response into ODataFeed: An exception of type 'EdmSimpleTypeException' occurred." }

Find in Drive here:

  • Debug logs (SDKapplogs.txt)
  • JSON response from SFSF (response.json)

Any help would be appreciated.

Questioner
kepair
Viewed
28
Alexander Dümont 2020-03-05 20:40

The EDMX file that you've used to generate the VDM from is not compatible with the remote OData service responses. Please ask the maintainer of the OData service to provide an up-to-date metadata file. You can also try and download it directly from http://[URL]/odata/v2/$metadata.

I found about half of the JSON sample payload that you attached was not compatible with the EDMX file published on API Business Hub.

  • The response contains unknown entity properties which cannot be matched with the metadata:

    "departmentCode": null
    "locationCode": null
    "divisionCode": null
    "costCenterCode": null
    "instrGen": null
    "legalEntityCode": null
    "templateName": "Standard Job Requisition"
    "routeMap": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/routeMap"}}
    "motorVeh": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/motorVeh"}}
    "payType": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/payType"}}
    "requiredTravel": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/requiredTravel"}}
    "state": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/state"}}
    "jobProfile": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/jobProfile"}}
    "division_obj": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/division_obj"}}
    "legalEntity_obj": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/legalEntity_obj"}}
    "jobReqFwdCandidates": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/jobReqFwdCandidates"}}
    "status": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/status"}}
    "budgeted": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/budgeted"}}
    "jobApplications": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/jobApplications"}}
    "shiftSchedule": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/shiftSchedule"}}
    "interviewGuide": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/interviewGuide"}}
    "jobAnalyzerReportingData": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/jobAnalyzerReportingData"}}
    "assessment": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/assessment"}}
    "adCode": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/adCode"}}
    "flsa": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/flsa"}}
    "costCenter_obj": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/costCenter_obj"}}
    "filter1": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/filter1"}}
    "filter2": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/filter2"}}
    "filter3": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/filter3"}}
    "eeoJobCat": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/eeoJobCat"}}
    "location_objlist": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/location_objlist"}}
    "accommo": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/accommo"}}
    "experienceReq": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/experienceReq"}}
    "relocationPack": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/relocationPack"}}
    "rsnVacancy": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/rsnVacancy"}}
    "location_obj": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/location_obj"}}
    "competencies": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/competencies"}}
    "department_obj": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/department_obj"}}
    "PD": {"__deferred": {"uri": "https://[URL]/odata/v2/JobRequisition(2126L)/PD"}}
    
  • The response contains unexpected null values for entity properties which are not allowed to be null:

    "closedDateTime": null
    "timeToFill": null
    "jobReqGUId": null
    "overallScaleName": null
    "lastModifiedProxyUserId": null
    "positionNumber": null
    "age": null
    

Unfortunately the errors are not handled gracefully and will shutdown any deserialization attempt. Since this is happening within the third party Olingo library of SAP Service SDK, we cannot fix or change it, or provide a meaningful workaround.

You will need to make sure the correct metadata file is used, from start to end.