Bug 51762 - loadresource hitting the server twice
Summary: loadresource hitting the server twice
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.2
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-02 15:15 UTC by matthias
Modified: 2012-12-20 22:11 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matthias 2011-09-02 15:15:45 UTC
the following simple target seems to hit the server twice. i have logged the http traffic with wireshark and it confirms that the http-call is sent (and received) twice.

<project name="Test" default="recreate-via-http" >

    <target name="recreate-via-http">
        <loadresource property="result" >
            <url url="http://someserver/somecall.php"  />           
        </loadresource>  
        <echo>${result}</echo>
    </target>

</project>
Comment 1 matthias 2011-09-02 15:41:34 UTC
as a user on stackoverflow points out, it seems that the problem is getting the length of the content first and then getting the actual content, resulting in two http calls.

see:
http://stackoverflow.com/questions/7284649/ant-loadresource-task-called-twice
Comment 2 Stefan Bodewig 2011-10-28 14:52:50 UTC
The analysis is correct.  For "local" resources the querying the size first is a nice optimization.  Also, we don't set properties for resources of length 0 and don't need to read the resource in order to find out it is empty that way.

There is no easy way for Ant to know whether a resource is a remote resource, it may have been wrapped in some sort of decorator like a gzipresource wrapped around an urlresource.

The best we can probably do is adding an option to disable the size check.

WRT the stackoverflow comments: The call to close() inside of the getSize method is strictly necessary as there will be many cases where only the size of a resource is asked for without actually reading the stream (just think of the size selector).
Comment 3 Ryan 2012-12-20 22:11:42 UTC
I'd love to see this fixed. I am trying to switch to ant for our deployment, but we reinitialize our web apps via a special URL. I need to call this after deployment. Calling it twice adds a delay and impacts the users.

I don't understand the comments about why it's necessary to do it this way. If I call GET or wget on the command line those programs don't request my URL twice.