This is a clone of missing-link project on Google Code (https://code.google.com/p/missing-link/)
The missing link Ant HTTP task was created due to the lack of a full featured, usable and liberally licensed Ant HTTP task. This Ant task is coded from scratch utilizing only core Java classes; as such it does not require any third party dependencies at runtime.
This Ant task also simplifies common aspects of HTTP communication, which other libraries seem to needlessly complicate, such as: authentication, TLS/SSL and HTTP methods other than GET and POST.
The missing link Ant HTTP task is licensed under the Apache 2.0 license, a copy of the license can be found with the missing link Ant HTTP task distribution or at http://www.apache.org/licenses/LICENSE-2.0.html.
The missing link Ant HTTP task was created with the following features in mind:
Name | Description | Required | Default | Example |
---|---|---|---|---|
url |
HTTP URL | Yes | http://www.google.com |
|
method |
HTTP method | No | GET |
GET , PUT , POST , etc. |
printRequest |
Print request entity | No | false |
true or false |
printResponse |
Print response entity | No | false |
true or false |
printRequestHeaders |
Print request headers | No | true |
true or false |
printResponseHeaders |
Print response headers | No | true |
true or false |
expected |
Expected HTTP status | No | 200 |
200 , 201 , 404 , etc. |
failOnUnexpected |
Fail on unexpected status | No | true |
true or false |
outfile |
Write response to file | No | Any filename | |
followRedirects |
Follow redirections | No | true |
true or false |
setContentLengthHeader |
Set Content-Length header |
No | false |
true or false |
statusProperty |
Property to save status to | No | http.status |
|
update |
Update/overwrite outfile | No | true |
true or false |
entityProperty |
Property to save response entity to | No | response.entity |
<http url="http://google.com"
method="GET"
printRequest="false"
printResponse="true"
printRequestHeaders="true"
printResponseHeaders="true"
expected="200"
failOnUnexpected="false"/>
Name | Description | Required | Default | Example |
---|---|---|---|---|
username |
HTTP Basic username | Yes | john.doe |
|
password |
HTTP Basic password | No | p@55w0rd |
|
show |
Print the credentials | No | false |
true or false |
<http url="http://google.com">
<credentials username="john.doe" password="p@55w0rd"/>
</http>
Name | Description | Required | Default | Example |
---|---|---|---|---|
file |
KeyStore file | Yes (unless trustall="true" ) |
/path/to/keystore.jks |
|
password |
KeyStore password | No | p@55w0rd |
|
trustall |
Accept all certificates | No | false |
true or false |
NB: use trustall
with caution in production environments!
<http url="http://google.com">
<keystore file="/path/to/keystore.jks" password="p@55w0rd"/>
</http>
Name | Description | Required | Default | Example |
---|---|---|---|---|
name |
Header name | Yes | Accept |
|
value |
Header value | No | application/xml,*/* |
<http url="http://google.com">
<headers>
<header name="Accept" value="application/xml,*/*"/>
<header name="Content-Type" value="application/xml"/>
</headers>
</http>
Name | Description | Required | Default | Example |
---|---|---|---|---|
name |
Query parameter name | Yes | qp |
|
value |
Query parameter value | No | value123 |
<http url="http://google.com">
<query>
<parameter name="qp1" value="value1"/>
<parameter name="qp2" value="value2"/>
</query>
</http>
Name | Description | Required | Default | Example |
---|---|---|---|---|
file |
File to read entity from | No | request.xml |
|
binary |
Treat entity as binary | False | true or false |
|
value |
Value to use as entity | No | ${my.prop} |
<http url="http://google.com">
<entity file="request.zip" binary="true"/>
</http>
<http url="http://google.com">
<entity><![CDATA[Request Entity]]></entity>
</http>
The following is a basic example of how to import and use the missing link Ant HTTP task:
<?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}"/>
</fileset>
<path id="runtime.classpath">
<fileset refid="runtime.libs"/>
</path>
<taskdef name="http" classname="org.missinglink.ant.task.http.HttpClientTask">
<classpath refid="runtime.classpath"/>
</taskdef>
<target name="http-get">
<http url="http://www.google.com"/>
</target>
</project>