Writing to response.writer is not working

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing to response.writer is not working

Ron King
Hi everyone,

I want to write an html page back to the user at the very beginning of an ActionBean submit method.
The method calls a web service that takes around a minute to respond, and I want to put up a message
before the web service finishes.

I'm on Tomcat 8. I tried flushing the writer, but the page still doesn't display until after I return the
Resolution from the submit method.

Is there a way to make it write immediately?

Regards,

Ron

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Writing to response.writer is not working

VANKEISBELCK Remi
Hi again,

Seems like a regular "long running job / polling" scenario. It can be done with current Stripes version, even if it will be less performant if your http client is really non blocking, but that's another story.

So here's how I'd do this.

1/ Server side

In the ActionBean, I'd submit a task to an executor service (a thread pool) with that long running job that calls the webservice. This task should update the back-end state in some way, so that you can do polling and know when it's done. 
The same ActionBean can handle Ajax polling via another event method. This one will be called from some JS code in your page.

public class MyAction implements ActionBean {

  public Resolution triggerLongRunningJob() {
    // retrieve Executor Service, from servlet context or custom ActionBeanContext
    ExecutorService executorService = ... ; 
    // submit task
    executorService.submit(new MyLongRunningTask(...);
    // return a redirect resolution to the "wait" screen
    return new RedirectResolution(getClass(), "displayWaitScreen")
  }

  public Resolution displayWaitScreen() {
    return new ForwardResolution("/WEB-INF/jsp/wait-screen.jsp");
  }

  public Resolution poll() {
    // find task completion status and return to the client
    String jsonTaskCompletion = ... ;
    return new StreamingResolution("application/json", jsonTaskCompletion);
  }


  // the long running task code is in a Runnable
  private class MyLongRunningTask implements Runnable {
    public void run() {
      // call the webservice and update internal state

    }
  }
}


2/ Client side

First you'll submit the form to the 'triggerLongRunningJob' event. This will launch the background task and return directly. 
Then, you'll send xhr requests to the 'poll' event, that will tell you what to do next. If task has completed, then you'll probably change the location of the browser in some way in order to display a "result" page of some sort (ie use your data from the completed task and do whatever you need with it).

HTH

Rémi

 



2016-01-23 17:05 GMT+01:00 Ron King <[hidden email]>:
Hi everyone,

I want to write an html page back to the user at the very beginning of an ActionBean submit method.
The method calls a web service that takes around a minute to respond, and I want to put up a message
before the web service finishes.

I'm on Tomcat 8. I tried flushing the writer, but the page still doesn't display until after I return the
Resolution from the submit method.

Is there a way to make it write immediately?

Regards,

Ron

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Writing to response.writer is not working

Joaquin Valdez-2
Hi!

Is this the same idea as this: 


Joaquin 

On Jan 23, 2016, at 10:52 AM, VANKEISBELCK Remi <[hidden email]> wrote:

Hi again,

Seems like a regular "long running job / polling" scenario. It can be done with current Stripes version, even if it will be less performant if your http client is really non blocking, but that's another story.

So here's how I'd do this.

1/ Server side

In the ActionBean, I'd submit a task to an executor service (a thread pool) with that long running job that calls the webservice. This task should update the back-end state in some way, so that you can do polling and know when it's done. 
The same ActionBean can handle Ajax polling via another event method. This one will be called from some JS code in your page.

public class MyAction implements ActionBean {

  public Resolution triggerLongRunningJob() {
    // retrieve Executor Service, from servlet context or custom ActionBeanContext
    ExecutorService executorService = ... ; 
    // submit task
    executorService.submit(new MyLongRunningTask(...);
    // return a redirect resolution to the "wait" screen
    return new RedirectResolution(getClass(), "displayWaitScreen")
  }

  public Resolution displayWaitScreen() {
    return new ForwardResolution("/WEB-INF/jsp/wait-screen.jsp");
  }

  public Resolution poll() {
    // find task completion status and return to the client
    String jsonTaskCompletion = ... ;
    return new StreamingResolution("application/json", jsonTaskCompletion);
  }


  // the long running task code is in a Runnable
  private class MyLongRunningTask implements Runnable {
    public void run() {
      // call the webservice and update internal state

    }
  }
}


2/ Client side

First you'll submit the form to the 'triggerLongRunningJob' event. This will launch the background task and return directly. 
Then, you'll send xhr requests to the 'poll' event, that will tell you what to do next. If task has completed, then you'll probably change the location of the browser in some way in order to display a "result" page of some sort (ie use your data from the completed task and do whatever you need with it).

HTH

Rémi

 



2016-01-23 17:05 GMT+01:00 Ron King <[hidden email]>:
Hi everyone,

I want to write an html page back to the user at the very beginning of an ActionBean submit method.
The method calls a web service that takes around a minute to respond, and I want to put up a message
before the web service finishes.

I'm on Tomcat 8. I tried flushing the writer, but the page still doesn't display until after I return the
Resolution from the submit method.

Is there a way to make it write immediately?

Regards,

Ron

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Writing to response.writer is not working

Poitras Christian
Hi,

Both are similar.

@WaitPage annotation tries to simplify things for you by masking a lot of things you would need to code yourself.
One example is that the action bean with all parameters may not be available in Remi’s code, unless the Runnable has access to it.

One advantage of Remi’s code is that it’s clear that you are starting a long process and you don’t want to force your user to wait for it.
With @WaitPage, the annotation is the only thing that allows you to know this method will take a long time. Even worse, if you forget to register the WaitPageInterceptor and a user calls the annotated method, he will believe the page doesn’t respond…

Christian


De : Joaquin Valdez <[hidden email]<mailto:[hidden email]>>
Répondre à : Stripes Users List <[hidden email]<mailto:[hidden email]>>
Date : Saturday, January 23, 2016 at 1:41 PM
À : "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>, Stripes Users List <[hidden email]<mailto:[hidden email]>>
Objet : Re: [Stripes-users] Writing to response.writer is not working

Hi!

Is this the same idea as this:

https://stripesframework.atlassian.net/wiki/display/STRIPES/Wait+Page+for+Long+Events ?

Joaquin

On Jan 23, 2016, at 10:52 AM, VANKEISBELCK Remi <[hidden email]<mailto:[hidden email]>> wrote:

Hi again,

Seems like a regular "long running job / polling" scenario. It can be done with current Stripes version, even if it will be less performant if your http client is really non blocking, but that's another story.

So here's how I'd do this.

1/ Server side

In the ActionBean, I'd submit a task to an executor service (a thread pool) with that long running job that calls the webservice. This task should update the back-end state in some way, so that you can do polling and know when it's done.
The same ActionBean can handle Ajax polling via another event method. This one will be called from some JS code in your page.

public class MyAction implements ActionBean {

  public Resolution triggerLongRunningJob() {
    // retrieve Executor Service, from servlet context or custom ActionBeanContext
    ExecutorService executorService = ... ;
    // submit task
    executorService.submit(new MyLongRunningTask(...);
    // return a redirect resolution to the "wait" screen
    return new RedirectResolution(getClass(), "displayWaitScreen")
  }

  public Resolution displayWaitScreen() {
    return new ForwardResolution("/WEB-INF/jsp/wait-screen.jsp");
  }

  public Resolution poll() {
    // find task completion status and return to the client
    String jsonTaskCompletion = ... ;
    return new StreamingResolution("application/json", jsonTaskCompletion);
  }


  // the long running task code is in a Runnable
  private class MyLongRunningTask implements Runnable {
    public void run() {
      // call the webservice and update internal state

    }
  }
}


2/ Client side

First you'll submit the form to the 'triggerLongRunningJob' event. This will launch the background task and return directly.
Then, you'll send xhr requests to the 'poll' event, that will tell you what to do next. If task has completed, then you'll probably change the location of the browser in some way in order to display a "result" page of some sort (ie use your data from the completed task and do whatever you need with it).

HTH

Rémi





2016-01-23 17:05 GMT+01:00 Ron King <[hidden email]<mailto:[hidden email]>>:
Hi everyone,

I want to write an html page back to the user at the very beginning of an ActionBean submit method.
The method calls a web service that takes around a minute to respond, and I want to put up a message
before the web service finishes.

I'm on Tomcat 8. I tried flushing the writer, but the page still doesn't display until after I return the
Resolution from the submit method.

Is there a way to make it write immediately?

Regards,

Ron

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]<mailto:[hidden email]>
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]<mailto:[hidden email]>
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users