File not downloaded with execAndWait Struts Interceptor after inserting delay
Asked Answered
O

1

0

My code downloads a file from back-end server. Since we will be retrieving records numbering in millions, we have used Struts2 execAndWait Interceptor. To test this, we are inserting delay of 30 secs. I'm able to download file without inserting delay (where test data very small), but after inserting it, i never get the file. Logs show that action class is being repeatedly executed due to <meta-refresh> of 5 secs in wait file, even input-stream is populated.

What could be the reason for such behaviour ?

Code Set-up:

Struts.xml:

<action name="file-download" class="com.company.namespace.test.TestDownloadActionClass">
     <interceptor-ref name="defaultStack" />
     <interceptor-ref name="execAndWait">
         <param name="delay">10000</param>
         <param name="delaySleepInterval">500</param>
     </interceptor-ref>
     <result name="wait" type="freemarker" >/dir/resources/First-Page.ftl</result>
     <result name="error" type="freemarker" >/dir/resources/Error-Page.ftl</result>
     <result name="success" type="stream">
        <param name="contentDisposition">attachment; filename="${downloadFilename}"</param>
        <param name="contentType">application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</param>
        <param name="inputName">inputStream</param> 
        <param name="bufferSize">1024</param>
    </result>
</action>

P.S: I haven't tested this code on million data sets. Test data consists of only few data.

Obnoxious answered 23/2, 2015 at 6:25 Comment(0)
S
0

The reason is you are using the execAndWait interceptor in the wrong way. The interceptor is running an action in the background thread. While the action is executed, that could take a long time, the wait result returned to the browser. When the result is executed the response is committed. The wait result is returned after the specified parameter delay.

Parameters:

  • delay (optional) - an initial delay in millis to wait before the wait page is shown (returning wait as result code). Default is no initial delay.
  • delaySleepInterval (optional) - only used with delay. Used for waking up at certain intervals to check if the background process is already done. Default is 100 millis.

The wait result is not returned if the initial delay parameter is large enough to finish a job.

This interceptor also supports using an initial wait delay. An initial delay is a time in milliseconds we let the server wait before the wait page is shown to the user. During the wait this interceptor will wake every 100 millis to check if the background process is done premature, thus if the job for some reason doesn't take to long the wait page is not shown to the user.

Serenaserenade answered 24/2, 2015 at 8:10 Comment(3)
Hi @Roman, I am getting the wait page since delay is > 10 sec. But I am not able to download file which is supposedly populated and sent from back-end. During this, my wait is is also refreshing continuously, thereby execute() is hit every time. So the refresh cycle is continuously happening with no file being downloaded. Is there anything wrong in struts configuration ?Obnoxious
If I remove execAndWait interceptor, in case of million or more records, will not the http session at server expire ? To resolve this, I have used interceptor.Obnoxious
Ok, I got your point, if you have any other question, please edit your post or ask a new question if you have a different problem.Serenaserenade

© 2022 - 2024 — McMap. All rights reserved.