Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.axonivy.lab.rest;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.util.stream.IntStream;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.WebApplicationException;
- import javax.ws.rs.core.Response;
- import javax.ws.rs.core.StreamingOutput;
- import ch.ivyteam.ivy.environment.Ivy;
- import ch.ivyteam.log.Logger;
- @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();
- }
- }
Add Comment
Please, Sign In to add comment