0

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?

Neuron
  • 5,141
  • 5
  • 38
  • 59
O. Merk
  • 113
  • 10

1 Answers1

1

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

O. Merk
  • 113
  • 10
  • 3
    Can you explain the issue and your solution in a bit more detail so that we resolve it? – Sander Wozniak May 16 '18 at 10:58
  • 1
    Hello [O. Merk](https://stackoverflow.com/users/9623543/o-merk), it would be nice if you shared the details of your issue and the solution with us, so other people can benefit if they find this question. Also, if your problem is resolved, please "accept" your answer, so it is visible that this question is resolved. Thank you. – Florian Wilhelm May 17 '18 at 12:56