简体   繁体   中英

Retrieve streaming response body with additional data

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.

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());
   }
}

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