Dan Haywood created ISIS-2119:
---------------------------------

             Summary: Increase timeout to avoid occasional exceptions when 
download Blobs
                 Key: ISIS-2119
                 URL: https://issues.apache.org/jira/browse/ISIS-2119
             Project: Isis
          Issue Type: Bug
    Affects Versions: 1.17.0
            Reporter: Dan Haywood
            Assignee: Dan Haywood
             Fix For: 1.18.0


On a slow connection, can get occasional exceptions when downloading a blob... 
that the behaviour cannot be found on the entity.  There's not a lot to go on.

Inspecting the returned payload though, I discovered at the end:

{code}
<evaluate><![CDATA[(function(){setTimeout("window.location.href='./orders.Order:7975?24-1.IBehaviorListener.0-'",
 10);})();]]></evaluate>
{code}

which gave me the clue.  The relevant code is in 
ActionResultResponseHandlingStrategy:

{code}
    SCHEDULE_HANDLER {
        @Override
        public void handleResults(
                final ActionResultResponse resultResponse,
                final IsisSessionFactory isisSessionFactory) {
            final RequestCycle requestCycle = RequestCycle.get();
            AjaxRequestTarget target = 
requestCycle.find(AjaxRequestTarget.class);

            if (target == null) {
                // non-Ajax request => just stream the Lob to the browser
                // or if this is a no-arg action, there also will be no parent 
for the component
                
requestCycle.scheduleRequestHandlerAfterCurrent(resultResponse.getHandler());
            } else {
                // otherwise,
                // Ajax request => respond with a redirect to be able to stream 
the Lob to the client
                ResourceStreamRequestHandler scheduledHandler = 
(ResourceStreamRequestHandler) resultResponse.getHandler();
                StreamAfterAjaxResponseBehavior streamingBehavior = new 
StreamAfterAjaxResponseBehavior(scheduledHandler);
                final Page page = target.getPage();
                page.add(streamingBehavior);
                String callbackUrl = 
streamingBehavior.getCallbackUrl().toString();
                target.appendJavaScript("setTimeout(\"window.location.href='" + 
callbackUrl + "'\", 10);");
            }

        }
    },
{code}

What's happening here is that response from the ajax call to invoke the button 
is the fragments to rebuild the page ... it's not possible to also return the 
BLOB.  So the Ajax instead sets a timeout to download that Blob as a separate 
web call.

Experimenting with this code, if the behaviour is stripped off (everything 
after the "?") then the download doesn't occur; so this is needed.

Since I've seen the problem mostly with large docs and on a slow connection, my 
guess is that this is some sort of race condition.  Since we can wait a bit 
more than 10ms, my suggestion is to increase the timeout to 250ms.




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to