简体   繁体   中英

Usage of com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiQuery inside Spring RestController

I am trying to call a BAPI from a Spring REST controller. The call to the backend system works fine, however returning the ResponseEntity leads to an error " getOutputStream() has already been called for this response"

@RequestMapping( method = RequestMethod.GET ) 
public ResponseEntity<List<ExportingCostCenterInformation>> getBusinessPartners()
{
    final ErpEndpoint endpoint = new ErpEndpoint(new ErpConfigContext("ErpQueryEndpoint_RFC"));

    final BapiQuery query = new BapiQuery("BAPI_COSTCENTER_GETLIST")
        .withExporting("CONTROLLINGAREA", "KOKRS", "1000");

    List<ExportingCostCenterInformation> ecci = null;
    try {
        ecci = query.execute(endpoint)
            .get("COSTCENTER_LIST")
            .getAsCollection()
            .asList(ExportingCostCenterInformation.class);
    } catch (UnsupportedOperationException | IllegalArgumentException | QuerySerializationException | DestinationNotFoundException | DestinationAccessException | QueryExecutionException e) {
        // ...
    } 

    return ResponseEntity.ok(ecci);         
}

Any ideas why this error comes up?

The getter & setter methods of class ExportingCostCenterInformation were not well defined. That was the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM