Retrieve streaming response body with additional data

Viewed 473

I have an API which responds with:

  @PostMapping
  public StreamingResponseBody export(<variables>) {
    return outputStream -> method(variables);
  }

Export service (which contains this API), does not have any data source attached - it is a simple microservice. Variables mostly are: really big JSON file with additional flags.

Problem is, that the method at the export also extracts additional data List<Object> data, required for further processing.

How to pass StreamingResponseBody together with data ? Any other out of the box solution would be great too.

1 Answers

I have went with an ObjectOutputStream implementation. I have created:

public class Response implements Serializable {
  private byte[] document;
  private List<Object> data;
}

and method just:

public void method(OutputStream os) throws Exception {
   try (ObjectOutputStream oos = new ObjectOutputStream(os)) {
     oos.writeObject(buildObj());
   }
}
Related