org.apache.commons.jelly.tags.http
Class HttpTagSupport

java.lang.Object
  extended by org.apache.commons.jelly.TagSupport
      extended by org.apache.commons.jelly.tags.http.HttpTagSupport
All Implemented Interfaces:
org.apache.commons.jelly.Tag
Direct Known Subclasses:
DeleteTag, GetTag, HeadTag, OptionsTag, PostTag, PutTag

public abstract class HttpTagSupport
extends org.apache.commons.jelly.TagSupport

The base tag for all http requests

Version:
$Id: HttpTagSupport.java 155420 2005-02-26 13:06:03Z dirkv $
Author:
dion

Field Summary
private  boolean _followRedirects
          whether or not to follow redirects
private  java.util.List _parameters
          list of parameters as name value pairs
private  java.lang.String _path
          the path to be tested relative to the host/port specifed on the parent suite tag.
private  java.util.List _requestHeaders
          list of headers as name value pairs
private  java.lang.String _uri
          The complete uri to be processed Either this property or the path and the suite's host must be provided.
private  java.lang.String _var
          unique identifier of the tag/ variable to store result in
private static java.lang.String HEADER_NAME_USER_AGENT
          the header name for the user agent
 
Fields inherited from class org.apache.commons.jelly.TagSupport
body, context, hasTrimmed, parent, shouldTrim
 
Constructor Summary
HttpTagSupport()
          Creates a new instance of HttpTag
 
Method Summary
 void addParameter(java.lang.String name, java.lang.String value)
          Add a parameter to the list
 void addRequestHeader(java.lang.String name, java.lang.String value)
          Add a request header to the list
 void doTag(org.apache.commons.jelly.XMLOutput xmlOutput)
          Perform the tag functionality.
private  org.apache.commons.httpclient.HttpMethod getConfiguredHttpMethod()
          retrieve the method from the subclass and configure it ready for execution
private  org.apache.commons.httpclient.HttpClient getHttpClient()
          return a HttpClient shared on the session tag, or a new one if no session tag exists
protected abstract  org.apache.commons.httpclient.HttpMethod getHttpMethod()
          A method that must be implemented by subclasses to provide the url method implementation
 java.util.List getParameters()
          Getter for property parameters.
 java.lang.String getPath()
          Getter for property path.
 java.util.List getRequestHeaders()
          Getter for property requestHeaders.
 java.lang.String getResolvedUrl()
           
private  SessionTag getSessionTag()
          retrieve the optional parent session tag
 java.lang.String getUri()
          Getter for property uri.
 java.lang.String getVar()
          Getter for property var.
 boolean isFollowRedirects()
          Getter for property followRedirects.
 void setFollowRedirects(boolean followRedirects)
          Setter for property followRedirects.
protected  void setParameters(org.apache.commons.httpclient.HttpMethod method)
          Set the current parameters on the url method ready for processing
 void setParameters(java.util.List parameters)
          Setter for property parameters.
 void setPath(java.lang.String path)
          Setter for property path.
 void setRequestHeaders(java.util.List requestHeaders)
          Setter for property requestHeaders.
 void setUri(java.lang.String uri)
          Setter for property uri.
 void setVar(java.lang.String var)
          Setter for property var.
 
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_var

private java.lang.String _var
unique identifier of the tag/ variable to store result in


_path

private java.lang.String _path
the path to be tested relative to the host/port specifed on the parent suite tag. Either this property and the suite's host must be provided, or the url property must be specifed


_uri

private java.lang.String _uri
The complete uri to be processed Either this property or the path and the suite's host must be provided.


_followRedirects

private boolean _followRedirects
whether or not to follow redirects


_parameters

private java.util.List _parameters
list of parameters as name value pairs


_requestHeaders

private java.util.List _requestHeaders
list of headers as name value pairs


HEADER_NAME_USER_AGENT

private static final java.lang.String HEADER_NAME_USER_AGENT
the header name for the user agent

See Also:
Constant Field Values
Constructor Detail

HttpTagSupport

public HttpTagSupport()
Creates a new instance of HttpTag

Method Detail

getResolvedUrl

public java.lang.String getResolvedUrl()
Returns:
the url specified by the tag, either the url if not null, or a combination of the host, port and path

getHttpMethod

protected abstract org.apache.commons.httpclient.HttpMethod getHttpMethod()
                                                                   throws java.net.MalformedURLException
A method that must be implemented by subclasses to provide the url method implementation

Returns:
a HttpUrlMethod implementation
Throws:
java.net.MalformedURLException - when the url or path is invalid

doTag

public void doTag(org.apache.commons.jelly.XMLOutput xmlOutput)
           throws org.apache.commons.jelly.JellyTagException
Perform the tag functionality. In this case, get the http url method execute it and make it available for validation

Parameters:
xmlOutput - where to send output
Throws:
org.apache.commons.jelly.JellyTagException - when an error occurs

getConfiguredHttpMethod

private org.apache.commons.httpclient.HttpMethod getConfiguredHttpMethod()
                                                                  throws java.net.MalformedURLException
retrieve the method from the subclass and configure it ready for execution

Returns:
a configured method
Throws:
java.net.MalformedURLException - when retrieving the URL fails

setParameters

protected void setParameters(org.apache.commons.httpclient.HttpMethod method)
                      throws java.net.MalformedURLException
Set the current parameters on the url method ready for processing

Parameters:
method - the method to configure
Throws:
java.net.MalformedURLException - when #getHttpUrlMethod() does

getSessionTag

private SessionTag getSessionTag()
retrieve the optional parent session tag

Returns:
the ancestor tag with class SessionTag or null if not found

getHttpClient

private org.apache.commons.httpclient.HttpClient getHttpClient()
return a HttpClient shared on the session tag, or a new one if no session tag exists

Returns:
the shared http client from the session tag, or create a new one.

addParameter

public void addParameter(java.lang.String name,
                         java.lang.String value)
Add a parameter to the list

Parameters:
name - the parameter name
value - the parameter value

addRequestHeader

public void addRequestHeader(java.lang.String name,
                             java.lang.String value)
Add a request header to the list

Parameters:
name - the header name
value - the header value

getVar

public java.lang.String getVar()
Getter for property var.

Returns:
Value of property var.

setVar

public void setVar(java.lang.String var)
Setter for property var.

Parameters:
var - New value of property var.

getPath

public java.lang.String getPath()
Getter for property path.

Returns:
Value of property path.

setPath

public void setPath(java.lang.String path)
Setter for property path.

Parameters:
path - New value of property path.

getUri

public java.lang.String getUri()
Getter for property uri.

Returns:
Value of property uri.

setUri

public void setUri(java.lang.String uri)
Setter for property uri.

Parameters:
uri - New value of property uri.

isFollowRedirects

public boolean isFollowRedirects()
Getter for property followRedirects.

Returns:
Value of property followRedirects.

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Setter for property followRedirects.

Parameters:
followRedirects - New value of property followRedirects.

getParameters

public java.util.List getParameters()
Getter for property parameters.

Returns:
Value of property parameters.

setParameters

public void setParameters(java.util.List parameters)
Setter for property parameters.

Parameters:
parameters - New value of property parameters.

getRequestHeaders

public java.util.List getRequestHeaders()
Getter for property requestHeaders.

Returns:
Value of property requestHeaders.

setRequestHeaders

public void setRequestHeaders(java.util.List requestHeaders)
Setter for property requestHeaders.

Parameters:
requestHeaders - New value of property requestHeaders.