1

We have a really long process an we want to trigger that progress with a webscript's endpoint

But because it is too long with too many steps, we want to write in the body the steps accomplished and I want them to be display into the client browser meanwhile the are created.

I tried flushing the outputStream, but that doesn't render the output into the browser inmediatly. The browser waits until all the steps finish for displaying the output

public class ProgressiveProcessWebscript implements AbstractWebScript 
    public final void execute(WebScriptRequest request, 
         WebScriptResponse response) {
       ...
       response.setContentType(MIMETYPE_TXT);

       OutputStream output = response.getOutputStream();
       FilterOutputStream filterOutputStream = new FilterOutputStream(output);

       for (Step step: stepList) {
          step.execute();
          filterOutputStream.write(step.getName().getBytes());
          filterOutputStream.flush();
       }

WebScriptResponse

Troncador
  • 3,356
  • 3
  • 23
  • 40

1 Answers1

0

You can't simply write to the OutputStream and flush it. You must implement another concept. There is different solutions for your problem.

You should take a look to this great post: What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

The Ajax Long Polling solution is in my opinion probably the easiest way, since you don't need any other framework server-side.

LaurentG
  • 11,128
  • 9
  • 51
  • 66