Home > ant task, apache ant, http, java, web services, xml > apache ant http task

apache ant http task

A lightweight, full featured and flexible apache ant http task is ready for use, visit http://code.google.com/p/missing-link/ to download the library with documentation, source and examples.  The ant task is licensed under the Apache 2.0 license and is freely available for use in any situation.

I created this library because there simply isn’t any good ones out there.  Most don’t contain or expose access to core HTTP features such as authentication and headers.  And those that do exist usually have bugs that prevent normal usage, poorly documented or have some other limiting factor.

It’s great for use in build processes which need to invoke HTTP services (think XML RESTful web services, for example), as well as testing URLs.

Using the ant task is very simple, here is a complete working ant build file example:

<?xml version="1.0" encoding="UTF-8"?>
<project name="ml-ant-http" basedir="." default="http-get">

<property name="ml-ant-http.jar" value="ml-ant-http-1.0.jar"/>

<fileset id="runtime.libs" dir=".">
<include name="${ml-ant-http.jar}"/>

<path id="runtime.classpath">
<fileset refid="runtime.libs"/>

<taskdef name="http" classname="org.missinglink.ant.task.http.HttpClientTask">
<classpath refid="runtime.classpath"/>

<target name="http-get">
<http url="http://www.google.com"/>
  1. Mohannad
    March 28, 2011 at 11:52 pm

    Hi Alex,
    Is it possible to use your missing-link http target to GET an attachment via an HTTP request? I tried your http target and can see an attachment in the response header but I can’t figure out how to obtain it.

  2. Alex
    March 29, 2011 at 5:59 am

    Hi Mohannad,

    Saving a response HTTP entity to a file (binary file, etc) is something I neglected to include in the 1.0 version… However it should only take a few minutes to incorporate it and create some test cases. Just to clarify, when you say attachment, what header are you referring to specifically? Currently I plan to simply save the response entity to a file based on a new configuration parameter.

    • Mohannad
      March 29, 2011 at 3:09 pm

      Thanks for the quick reply! I couldn’t find anything in the docs about saving attachments so I didn’t think it existed. Anyway, what I’m trying to do is save the Config.zip that I get from the following response:

      [http] Headers: yes
      [http] HTTP/1.1 200 OK
      [http] Date: Tue, 29 Mar 2011 04:41:33 GMT
      [http] Transfer-Encoding: chunked
      [http] Content-Disposition: attachment; filename=”Config.zip”
      [http] Content-Type: application/zip
      [http] Server: Apache-Coyote/1.1
      [http] Entity: yes

      Do you think you will be adding support for that anytime soon?
      Thanks for your awesome work!

      • Alex
        March 29, 2011 at 6:24 pm

        Hi Mohannad,

        Since that was a glaring omission from 1.0, I added support for it via a new “outfile” parameter on the root http task and rev’d the project to 1.1.

        I’ve updated the google code downloads with a 1.1 version, readme is updated and the build-sample.xml file shows an example of its usage to download the google homepage logo image.

        I’ll have an updated blog post later when I get a chance.

        Thanks for trying out the project and hopefully that fixes all the missing features you need!

  3. Mohannad
    March 30, 2011 at 12:30 am

    You are quick!! Thanks for the quick reply and the fix. That sounds like what I’m after. Will download the new version and let you know how I get on.
    Keep up the great work and thanks again for you help!

  4. rhonda
    May 10, 2011 at 2:04 pm

    nice tool…only had to make a slight modification to the xml file to adjust for the jar version. thanks for sharing!

    • Alex
      July 22, 2011 at 11:30 pm

      Hi Rhonda,

      Version 1.1.2 has been released with various bug fixes. The build process now automates the build sample XML file with the correct jar reference.

      Thanks for reporting this!

  5. Derek Lewis
    November 9, 2011 at 1:23 pm

    Hi Alex,
    Is it possible to use this task as a condition inside a ? I have a server that requires authentication that I’m deploying to, and trying to use to know that it’s up.

    • Alex
      November 9, 2011 at 1:50 pm

      Hi Derek,

      I think there’s a few things you could do with the way the task works now..

      – set the expected attribute to an expected response code (i.e. 200) and set failonunexpected=true, and hit some known webservice (like a ping/server status service)

      – set the expected attribute to an expected response code, failonunexpected=true and save it to a property with statusProperty=”status.code” and use that for an if conditional to set a property

      <conditional property="is.up" value="true">
          <equals arg1="200" arg2="${status.code}/>

      and use it as an if condition on your task, such as

      <target name="deploy.stuff" if="${is.up}">

      • Derek Lewis
        November 9, 2011 at 2:02 pm

        Hi Alex,
        Oops, it looks like the blog stripped out my ant xml. I was asking it it was usable within a waitfor task. The examples you’ve given will simply check the server once, whereas the waitfor task will check the conditions at a configurable interval, until a timeout is reached. When waiting for a server to finish deploying, this makes the waitfor task the preferred way of doing things. However, the waitfor task takes a special kind of nested element called a condition, not just any task. I was wondering if your http task is usable as a condition within a waitfor.

      • Alex
        November 9, 2011 at 2:12 pm

        Hi Derek,

        Sorry I misunderstood. That’s an interesting use case that I hadn’t considered, I use ant for a lot of things, but I’ve never had a need for waitfor yet.

        I’m willing to implement the necessary steps to make it work as a condition, I’ve logged the enhancement request here: http://code.google.com/p/missing-link/issues/detail?id=28

        I’ll reply to your comment here again when I get a chance to do this

      • Derek Lewis
        November 9, 2011 at 5:00 pm

        Great, thanks Alex. I’ll follow the issue on Google code too. 🙂

  6. Paul
    January 24, 2012 at 9:39 am

    Hi Alex,

    Is there support for using cookies through this library? For example, something roughly similar to cURL’s -b and -c options: http://curl.haxx.se/docs/manpage.html#-b

    Awesome tool BTW

  7. pds
    February 3, 2012 at 10:22 am

    really nice work, thanks so much.

    i’m using it to interface Tcat Server from Ant, makes life easy.

  8. July 13, 2012 at 2:59 pm

    It’s an awesome article for all the web visitors; they will take advantage from it I am sure.

  9. Buddy Casino
    October 7, 2013 at 1:31 pm

    Nice extension, I don’t get why ANT has those just an underpowered get tasks by default.

  10. Raz gilad
    November 28, 2016 at 4:30 am


    I use an ivy based ant procedure but now also need to deploy an artifact into a remote JFROG repository. I used this task to access the JFROG REST API and it work perfectly.


    Raz Gilad

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: