org.sr.client
Class HttpForm

java.lang.Object
  extended by org.sr.client.HttpForm

public class HttpForm
extends java.lang.Object

HTTP Form implementation for GET/POST requests. This class uses TSAuthenticator class for authentication requests.

Author:
Serhat Dirik
See Also:
TSAuthenticator

Field Summary
static java.lang.String FIELD_HEADER
           
static java.lang.String FIELD_ID
           
static java.lang.String FIELD_PARAMS
           
static java.lang.String METHOD_GET
           
static java.lang.String METHOD_POST
           
static java.lang.String UTF8_CHARSET
           
 
Constructor Summary
HttpForm()
          Default constructor
HttpForm(java.lang.String charSet)
          Creates a new form which uses the given charset
 
Method Summary
 void addCookie(java.lang.String name, java.lang.String value)
           
 void addCookies(java.lang.String cookies)
           
 void clearAdditionalRequestProperties()
          Clear all additional header fields
 void clearCookies()
          Clears all cookie values
 void clearFieldValues()
          Clears all field values that are set previously
 HttpFormResponse get(java.lang.String url)
          sends the form values to given url by using http get
 java.lang.String getCharset()
          Gives the charset of the form
 java.net.HttpURLConnection getConnection(java.lang.String targetURL)
          Gives a connection to requested url
 java.lang.String getCookie(java.lang.String name)
          Gives the requested cookie value
 java.lang.String getCookies()
          gives all cookie values
 java.util.Map<java.lang.String,java.lang.String> getCookiesAsMap()
           
 int getReadTimeout()
           
 boolean isFollowRedirects()
           
 HttpFormResponse post(java.lang.String url)
          posts the form to given url
 void putAdditionalRequestProperty(java.lang.String name, java.lang.String value)
          Puts the given name,value pair to the http header
 void putFieldValue(java.lang.String name, java.lang.String value)
          Adds a new field and its value to the form
 void removeCookie(java.lang.String name)
           
 void setCharset(java.lang.String charset)
           
 void setCookies(java.lang.String cookies)
           
 void setFollowRedirects(boolean followRedirects)
          Sets if the call should follow HTTP 302 redirects
 void setReadTimeout(int miliseconds)
          Sets the read time out value
 java.lang.String toGetString()
          Gives all form fields as get query string
 java.lang.String toPostString()
          Gives all form fields as post query string
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_PARAMS

public static final java.lang.String FIELD_PARAMS
See Also:
Constant Field Values

FIELD_HEADER

public static final java.lang.String FIELD_HEADER
See Also:
Constant Field Values

FIELD_ID

public static final java.lang.String FIELD_ID
See Also:
Constant Field Values

METHOD_POST

public static final java.lang.String METHOD_POST
See Also:
Constant Field Values

METHOD_GET

public static final java.lang.String METHOD_GET
See Also:
Constant Field Values

UTF8_CHARSET

public static final java.lang.String UTF8_CHARSET
See Also:
Constant Field Values
Constructor Detail

HttpForm

public HttpForm()
Default constructor


HttpForm

public HttpForm(java.lang.String charSet)
         throws java.io.UnsupportedEncodingException
Creates a new form which uses the given charset

Throws:
java.io.UnsupportedEncodingException
Method Detail

getCharset

public java.lang.String getCharset()
Gives the charset of the form


setCharset

public void setCharset(java.lang.String charset)
                throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

clearFieldValues

public void clearFieldValues()
Clears all field values that are set previously


putFieldValue

public void putFieldValue(java.lang.String name,
                          java.lang.String value)
Adds a new field and its value to the form


putAdditionalRequestProperty

public void putAdditionalRequestProperty(java.lang.String name,
                                         java.lang.String value)
Puts the given name,value pair to the http header


clearAdditionalRequestProperties

public void clearAdditionalRequestProperties()
Clear all additional header fields


setReadTimeout

public void setReadTimeout(int miliseconds)
Sets the read time out value


getReadTimeout

public int getReadTimeout()

toGetString

public java.lang.String toGetString()
Gives all form fields as get query string


toPostString

public java.lang.String toPostString()
Gives all form fields as post query string


getConnection

public java.net.HttpURLConnection getConnection(java.lang.String targetURL)
                                         throws java.io.IOException
Gives a connection to requested url

Throws:
java.io.IOException

post

public HttpFormResponse post(java.lang.String url)
                      throws java.io.IOException
posts the form to given url

Throws:
java.io.IOException

get

public HttpFormResponse get(java.lang.String url)
                     throws java.io.IOException
sends the form values to given url by using http get

Throws:
java.io.IOException

clearCookies

public void clearCookies()
Clears all cookie values


getCookies

public java.lang.String getCookies()
gives all cookie values

Returns:
cookies as one string

getCookie

public java.lang.String getCookie(java.lang.String name)
Gives the requested cookie value

Parameters:
name - name of the cookie
Returns:
cookie value

addCookies

public void addCookies(java.lang.String cookies)

addCookie

public void addCookie(java.lang.String name,
                      java.lang.String value)

removeCookie

public void removeCookie(java.lang.String name)

getCookiesAsMap

public java.util.Map<java.lang.String,java.lang.String> getCookiesAsMap()

setCookies

public void setCookies(java.lang.String cookies)

isFollowRedirects

public boolean isFollowRedirects()

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Sets if the call should follow HTTP 302 redirects

Parameters:
followRedirects -