diff options
author | mattinger <[email protected]> | 2006-08-22 17:16:14 +0000 |
---|---|---|
committer | mattinger <[email protected]> | 2006-08-22 17:16:14 +0000 |
commit | 813a108a2cf043bac8c137cb8be93f8be8d2a723 (patch) | |
tree | 0d175fcbb11bec268c7fe2dcb1c3bcda9860c7e4 /src | |
parent | 32d8edb22c05bd6b6e5d4c0b9a1563d8eb006d24 (diff) |
add ability to specify the client stuff right on the methods.
git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/trunk/ant-contrib@26 32d7a393-a5a9-423c-abd3-5d954feb1f2f
Diffstat (limited to 'src')
-rw-r--r-- | src/java/net/sf/antcontrib/net/httpclient/AbstractMethodTask.java | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/java/net/sf/antcontrib/net/httpclient/AbstractMethodTask.java b/src/java/net/sf/antcontrib/net/httpclient/AbstractMethodTask.java index 6bb34ed..1cb65cd 100644 --- a/src/java/net/sf/antcontrib/net/httpclient/AbstractMethodTask.java +++ b/src/java/net/sf/antcontrib/net/httpclient/AbstractMethodTask.java @@ -37,10 +37,10 @@ public abstract class AbstractMethodTask extends Task {
private HttpMethodBase method;
- private String clientRefId;
private File responseDataFile;
private String responseDataProperty;
private String statusCodeProperty;
+ private HttpClient httpClient;
private List responseHeaders = new ArrayList();
public static class ResponseHeader {
@@ -70,6 +70,10 @@ public abstract class AbstractMethodTask this.responseHeaders.add(responseHeader);
}
+ public void addConfiguredHttpClient(HttpClientType httpClientType) {
+ this.httpClient = httpClientType.getClient();
+ }
+
protected HttpMethodBase createMethodIfNecessary() {
if (method == null) {
method = createNewMethod();
@@ -90,7 +94,14 @@ public abstract class AbstractMethodTask }
public void setClientRefId(String clientRefId) {
- this.clientRefId = clientRefId;
+ Object clientRef = getProject().getReference(clientRefId);
+ if (clientRef == null) {
+ throw new BuildException("Reference '" + clientRefId + "' does not exist.");
+ }
+ if (! (clientRef instanceof HttpClientType)) {
+ throw new BuildException("Reference '" + clientRefId + "' is of the wrong type.");
+ }
+ httpClient = ((HttpClientType) clientRef).getClient();
}
public void setDoAuthentication(boolean doAuthentication) {
@@ -127,26 +138,14 @@ public abstract class AbstractMethodTask }
public void execute() throws BuildException {
- HttpClient client = null;
- if (clientRefId != null) {
- Object clientRef = getProject().getReference(clientRefId);
- if (clientRef == null) {
- throw new BuildException("Reference '" + clientRefId + "' does not exist.");
- }
- if (! (clientRef instanceof HttpClientType)) {
- throw new BuildException("Reference '" + clientRefId + "' is of the wrong type.");
- }
- HttpClientType clientType = (HttpClientType) clientRef;
- client = clientType.getClient();
- }
- else {
- client = new HttpClient();
+ if (httpClient == null) {
+ httpClient = new HttpClient();
}
HttpMethodBase method = createMethodIfNecessary();
configureMethod(method);
try {
- int statusCode = client.executeMethod(method);
+ int statusCode = httpClient.executeMethod(method);
if (statusCodeProperty != null) {
Property p = (Property)getProject().createTask("property");
p.setName(statusCodeProperty);
|