I'm using Ant now to do all my deployment to our servers. Today I decided to see if I could use wget to reset my application after a build. I like to do this just to make sure after I deploy a new build - that everything is reset in case I added something that needs to be set/reset in the application scope.
First I downloaded wget for Windows. There seem to be a lot of versions of wget floating around but I picked this version because it has SSL/HTTPS support compiled in and I need to run this against a secure server.
Simply copy the wget.exe executable into your C:\WINNT dir (on Windows XP) so that you can execute wget from any location.
In my application I have a bit of code which will reset my application if I pass a query string in the URL:
http://localhost/index.cfm?reset=true
And in my Application.cfc I have:
-
<cfif StructKeyExists(URL,"reset")>
-
<cfset this.onApplicationStart()>
-
<cflocation url="reset.html" addtoken="false">
-
</cfif>
So I initially tried to run the same thing using wget:
C:\>wget http://localhost/survey/?reset --spider -d
A few notes on the command line switches: --spider prevents wget from downloading anything, -d - enables debug which is useful during initial testing, and -- help will display all available options.
This worked on my localhost - but when I tried it on the live server I received "ERROR 500: Internal Server Error".
After a bit of trial and error the culprit turned out to be the cflocation after the reset. When I removed that - everything worked!
So in order to work around that I added another parameter to wget - a user-agent string:
C:\>wget https://my.secure.url/index.cfm?reset --http-user=MyUsername --http-passwd=${my.password} --spider --no-check-certificate --user-agent=wgetreset --no-verbose
I'm passing in my authentication using --http-user and --http-passwd. I'm setting the value of the 'my.password' property earlier when I checkout my code from SVN - see this post for more information. I also set the user-agent string using --user-agent=wgetreset.
Now I simply modified my application.cfc to prevent the cflocation from firing if the request was made via wget:
-
<cfif StructKeyExists(URL,"reset")>
-
<!--- need to lock this call to prevent any race conditions --->
-
<cflock scope="application" timeout="10" type="exclusive">
-
<!--- restart the application --->
-
<cfset this.onApplicationStart()>
-
<cfif NOT cgi.HTTP_USER_AGENT IS "wgetreset">
-
<cflocation url="reset.html" addtoken="false">
-
</cfif>
-
</cflock>
-
</cfif>
And finally in my build.xml file I added a new target to perform the reset:
-
<target name="cleanUp" description="Resets the application">
-
<exec executable="wget" outputproperty="wget.output" resultproperty="wget.result">
-
<arg line="https://my.secure.server/index.cfm?reset --http-user=${svn.username} --http-passwd=${svn.password} --spider --no-check-certificate --user-agent=wgetreset --no-verbose"/>
-
</exec>
-
<!-- Check the status of the reset operation -->
-
<condition property="status" value="FAIL">
-
<contains string="${wget.output}" substring="ERROR 500"/>
-
</condition>
-
<condition property="status" value="SUCCESS">
-
<contains string="${wget.output}" substring="200 OK"/>
-
</condition>
-
-
<echo>
-
------------------------------------------------
-
Files moved to ${project.build.final} successfully!
-
------------------------------------------------
-
Application reset: ${status}
-
------------------------------------------------
-
</echo>
-
-
</target>
This runs at the end of my build. It executes wget and dumps the results of the command into a property ${wget.output} which I then check to see if it ran OK or if there was an error.

You May Also Enjoy Reading:
4 Comments
(Had to redo this with no start and end brackets) Just FYI you can do this without the need for any special download:
exec executable=”C:/Program Files/Mozilla Firefox/firefox.exe”
arg value=”http://mysite.com/myapp/index.cfm?reload=true”
/exec
Brian - I did see that in the Ant docs but there is no way to pass the HTTPS info using that method unless I missed something?
Ahh, I never tried it with https, but I would think that just using https in the URL you give Firefox would work? If not, then yep, the wget is probably the way to go.
Sorry - I had a case of protocol confusion yesterday!
Yes - that would work for HTTPS - I also had to authenticate on our server hence the username/password and wget…