Hi Ivy team
I want to build a JAX-RS API returning response in a streaming manner (chunked transfer encoding). The code looks like below:
@Path("{applicationName}/streams")
public class StreamingResponseRestSResource {
@GET
public Response getStreamingResponse() {
// This works by keeping a reference then pass it to the anonymous class.
// It may NOT work in all situations.
final Logger logger = Ivy.log();
StreamingOutput streamingOutput = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException,
WebApplicationException {
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(output)), true);
Ivy.log().error("HHH - BREAK HERE");
logger.error("HHH - It works with passed reference of Logger");
IntStream.range(0, 100_000)
.forEach(c -> out.println("HHH - Count up to " + c));
}
};
return Response.ok(streamingOutput).build();
}
}
Full code here: http://pastebin.com/tEAMGFB3
If I do
curl -i -u Developer:Developer http://localhost:8081/ivy/api/designer/streams
the response would be:
{
"errorId": "1578A42A15718503",
"errorMessage": "Access to ivy environment outside a process request thread is not possible.\nCurrent thread: Thread[http-nio-8081-exec-14,5,main]",
"statusCode": 500
}
If I comment out the line ...
Ivy.log().error("HHH - BREAK HERE");
...the error disappears.
Is there anyway to fix the access to Ivy
with StreamingOutput
implementation?
asked
03.10.2016 at 14:50
Genzer Hawker
(suspended)
accept rate:
66%