net.sf.fikin.ant.httpclientanttask
Class BaseAntMethod

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by net.sf.fikin.ant.httpclientanttask.BaseAntMethod
Direct Known Subclasses:
BaseResponseAntMethod

public abstract class BaseAntMethod
extends org.apache.tools.ant.Task

Base class of methods hierarchy

Encapsulates all common to all tasks properties

All Ant tasks are backed by a single 8static) HttpClient instance. This allows for creating multiple-tags operations with same http source which allosw for a more complex schenarious such as authenticate first, store the session as coockies and then do some hot and/or get operations. This also has an disadvantage of possible interferince if one has to deal with more than one source. In those cases, one has to "shutdown" the HttpClient instance the first time it starts operating with a new host. This effectively will erase all previous session data and create a fresh HttpClient instance. created on Feb 11, 2006

Since:
Version:
$Revision: 1.4 $
Author:
fiykov

Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
BaseAntMethod()
           
 
Method Summary
 void addProperty(org.apache.tools.ant.types.Parameter p)
          set HttpClient property
protected  void after_execute_method()
          do something after @link #execute_method() is called and before connection is release
protected  void before_execute_method()
          do something before @link #execute_method() is called
protected  void check()
          check that url has been set and coockies policy is a valid one
protected  void clearHttpClient()
          clear static HttpClient object after execution this is used in order to free mememory generally not needed though
 AntProxy createProxy()
          create proxy data
 AntCredentials createUserCredentials()
          create user credentials (http authentication)
protected  void execute_method()
          actual method execution
 void execute()
          execute the task : check method-type and move to a particular handling
 int getConnectionTimeout()
          what is the connection timeout before retrying, by default 5000ms
 java.lang.String getCookiePolicy()
          get the coockies policy
 boolean getFailOnError()
          get fail on error
protected  org.apache.commons.httpclient.HttpClient getHttpClient()
          instantiate (if needed) and return the common (static) HttpClient object
protected  org.apache.commons.httpclient.HttpMethod getHttpMethod()
          get the HttpClient class of this method
 java.util.HashSet getProperties()
          get HttpClient properties
 AntProxy getProxy()
          get given proxy data
 int getRetryAttempts()
          get how many times to retry connecting to the host, by default 5
 boolean getShutdown()
          is the HttpClient to be shutdown or not
 boolean getSslAcceptUntrusted()
          get SSL accept untrusted certificates
 java.lang.String getUrl()
          get method's url
 AntCredentials getUserCredentials()
          get user's authenticaiton data
protected abstract  org.apache.commons.httpclient.HttpMethod newHttpMethod(java.lang.String url)
          template method, all subclasses must define the right HttpClient object instantiated
 void setConnectionTimeout(int ms)
          set connection timeout before retrying, by default 5000ms
 void setCookiePolicy(java.lang.String policy)
          set coockies policy, one of: compatibility - The policy that provides high degree of compatibilty with common cookie management of popular HTTP agents ignoreCookies - The policy that ignores cookies default - The default cookie policy netscape - The Netscape cookie draft compliant policy rfc2109 - The RFC 2109 compliant policy by default it is "compatibility"
 void setFailOnError(boolean fail)
          set fail on error, by default true
protected  void setHttpMethod(org.apache.commons.httpclient.HttpMethod m)
          set the HttpMethod object
protected  void setProperties(org.apache.commons.httpclient.HttpMethod method)
          set HttpClient properties (settings)
protected  void setProxy()
          set proxy and credentials
 void setRetryAttempts(int cnt)
          set how many times to retry the operation if failing because of communication failures, by default 5
 void setShutdown(boolean shutdown)
          shutdown current HttpClient instance.
 void setSslAcceptUntrusted(boolean trust)
          set SSL accept-untrusted or self-signed (certificates) option, by default it is false
 void setUrl(java.lang.String url)
          method's url
protected  void setUserCredentials()
          set user credentials
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseAntMethod

public BaseAntMethod()
Method Detail

setUrl

public void setUrl(java.lang.String url)
method's url

Parameters:
url - of the method
Ant Task Param Required:
true

getUrl

public java.lang.String getUrl()
get method's url

Returns:
url of the method

setFailOnError

public void setFailOnError(boolean fail)
set fail on error, by default true

Parameters:
fail - if true
Ant Task Param Required:
false

getFailOnError

public boolean getFailOnError()
get fail on error

Returns:
fail on error

setRetryAttempts

public void setRetryAttempts(int cnt)
set how many times to retry the operation if failing because of communication failures, by default 5

Parameters:
cnt - ow many times to retry connecting to the host
Ant Task Param Required:
false

getRetryAttempts

public int getRetryAttempts()
get how many times to retry connecting to the host, by default 5

Returns:
how many times to retry connecting to the host

setShutdown

public void setShutdown(boolean shutdown)
shutdown current HttpClient instance. This has the effoect of erasing all currently accumulated session data and in effect creates a fresh HttpClient instance.

Parameters:
shutdown - in case it is true
Ant Task Param Required:
false

getShutdown

public boolean getShutdown()
is the HttpClient to be shutdown or not

Returns:
true in case HttpClient is to be re-instantiated

setSslAcceptUntrusted

public void setSslAcceptUntrusted(boolean trust)
set SSL accept-untrusted or self-signed (certificates) option, by default it is false

Parameters:
trust - if true
Ant Task Param Required:
false

getSslAcceptUntrusted

public boolean getSslAcceptUntrusted()
get SSL accept untrusted certificates

Returns:
true if to accept them

getConnectionTimeout

public int getConnectionTimeout()
what is the connection timeout before retrying, by default 5000ms

Returns:
timeout in ms

setConnectionTimeout

public void setConnectionTimeout(int ms)
set connection timeout before retrying, by default 5000ms

Parameters:
ms - to timeout
Ant Task Param Required:
false

createUserCredentials

public AntCredentials createUserCredentials()
create user credentials (http authentication)

Returns:
http authentication
Ant Task Param Required:
false

getUserCredentials

public AntCredentials getUserCredentials()
get user's authenticaiton data

Returns:
user's authentication data if given

createProxy

public AntProxy createProxy()
create proxy data

Returns:
given proxy data
Ant Task Param Required:
false

getProxy

public AntProxy getProxy()
get given proxy data

Returns:
AntProbject object

addProperty

public void addProperty(org.apache.tools.ant.types.Parameter p)
set HttpClient property

Parameters:
p -
Ant Task Param Required:
false

getProperties

public java.util.HashSet getProperties()
get HttpClient properties

Returns:
properties set

setCookiePolicy

public void setCookiePolicy(java.lang.String policy)
set coockies policy, one of: by default it is "compatibility"

Parameters:
policy -
Ant Task Param Required:
false

getCookiePolicy

public java.lang.String getCookiePolicy()
get the coockies policy

Returns:
coockies policy mode

getHttpMethod

protected org.apache.commons.httpclient.HttpMethod getHttpMethod()
get the HttpClient class of this method

Returns:
HttpMethod

setHttpMethod

protected void setHttpMethod(org.apache.commons.httpclient.HttpMethod m)
set the HttpMethod object

Parameters:
m -

getHttpClient

protected org.apache.commons.httpclient.HttpClient getHttpClient()
instantiate (if needed) and return the common (static) HttpClient object

Returns:
the common HttpClient object

newHttpMethod

protected abstract org.apache.commons.httpclient.HttpMethod newHttpMethod(java.lang.String url)
template method, all subclasses must define the right HttpClient object instantiated


clearHttpClient

protected void clearHttpClient()
clear static HttpClient object after execution this is used in order to free mememory generally not needed though


check

protected void check()
              throws org.apache.tools.ant.BuildException
check that url has been set and coockies policy is a valid one

Throws:
org.apache.tools.ant.BuildException

execute_method

protected void execute_method()
                       throws org.apache.tools.ant.BuildException,
                              org.apache.commons.httpclient.HttpException,
                              java.io.IOException
actual method execution

Throws:
org.apache.tools.ant.BuildException
org.apache.commons.httpclient.HttpException
java.io.IOException

before_execute_method

protected void before_execute_method()
                              throws org.apache.tools.ant.BuildException,
                                     org.apache.commons.httpclient.HttpException,
                                     java.io.IOException
do something before @link #execute_method() is called

Throws:
org.apache.tools.ant.BuildException
org.apache.commons.httpclient.HttpException
java.io.IOException

after_execute_method

protected void after_execute_method()
                             throws org.apache.tools.ant.BuildException,
                                    org.apache.commons.httpclient.HttpException,
                                    java.io.IOException
do something after @link #execute_method() is called and before connection is release

Throws:
org.apache.tools.ant.BuildException
org.apache.commons.httpclient.HttpException
java.io.IOException

execute

public void execute()
             throws org.apache.tools.ant.BuildException
execute the task : check method-type and move to a particular handling

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

setUserCredentials

protected void setUserCredentials()
set user credentials


setProxy

protected void setProxy()
set proxy and credentials


setProperties

protected void setProperties(org.apache.commons.httpclient.HttpMethod method)
set HttpClient properties (settings)



Copyright © 2003-2007 Nikolay Fiykov. All Rights Reserved.