I have created a web application in spring boot in which I want to use Spring MVC rest framework instead of jersey. I am trying to do something like this but it gives me error. I want a equivalent of StreamingOutput in Spring MVC.
Ex: This uses JAX-RS StreamingOutput
public static StreamingOutput buildErrorEntity(Object error)
{
StreamingOutput stream = outputStream -> {
PrintStream printStream = new PrintStream(outputStream);
new ObjectMapper().writeValue(printStream, error);
};
return stream;
}
I want to replace SteamingOutput but it gives me an error saying "Cannot resolve constructor PrintStream()
public static OutputStream buildErrorEntity1(Object error) {
OutputStream stream = outputStream -> {
PrintStream printStream = new PrintStream(outputStream);
new ObjectMapper().writeValue(printStream, error);
};
return stream;
}
I would really appreciate some help. Thank you.
StreamingResponseBody is used for asynchronous request processing where the application can write directly to the response OutputStream.
Interface StreamingResponseBody A controller method return value type for asynchronous request processing where the application can write directly to the response OutputStream without holding up the Servlet container thread.
GET) public ResponseBodyEmitter handle() { ResponseBodyEmitter emitter = new ResponseBodyEmitter(); // Pass the emitter to another component... return emitter; } // in another thread emitter. send(foo1); // and again emitter. send(foo2); // and done emitter.
They've added StreamingResponseBody in Spring 4.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With