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?