org.apache.commons.latka.http
Class SessionImpl

java.lang.Object
  extended by org.apache.commons.latka.http.SessionImpl
All Implemented Interfaces:
Session

public class SessionImpl
extends Object
implements Session

An implementation of a Latka Session interface based on the Apache Commons HttpClient package.

Version:
$Id: SessionImpl.java 561366 2007-07-31 15:58:29Z rahul $
Author:
Doug Sale, Morgan Delagrange, dIon Gillard

Field Summary
protected  org.apache.commons.httpclient.HttpState _state
          this state object 'belongs' to HttpClient we maintain a reference in SessionImpl for simplicity
protected  LinkedList _urls
          tracks URLs treated by this session Session will automatically set the referer header for a request to the URL of the previous request
 
Constructor Summary
SessionImpl()
           
 
Method Summary
 void addCookie(String domain, String path, String name, String value)
          Adds a cookie to all HTTP requests whose domain and path match (according to RFC2109).
 Request createRequest(String label, URL url, int httpMethod, String version, boolean followRedirects)
          Creates a labeled request object with the specified URL, HTTP Method, version, and redirect handling behavior.
 Request createRequest(String label, URL url, int httpMethod, String version, boolean followRedirects, Proxy proxy)
          Create a labeled request , with the specified URL, HTTP method, version, and redirect handling behavior, using the given proxy for communications.
 Request createRequest(URL url, int httpMethod, Proxy proxy, String version)
          Creates a request object with the specified URL, HTTP Method, and version to be accessed via the provided proxy.
 Request createRequest(URL url, int httpMethod, String version)
          Creates a request object with the specified URL, HTTP Method, and version.
 String getCookieValue(String name)
          Returns the value of cookie name.
protected  URL getReferer()
          The URL of the last request that was executed.
protected  void setReferer(URL url)
          Called inside the request.execute() method, setting the referer for the next request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_urls

protected LinkedList _urls
tracks URLs treated by this session Session will automatically set the referer header for a request to the URL of the previous request


_state

protected org.apache.commons.httpclient.HttpState _state
this state object 'belongs' to HttpClient we maintain a reference in SessionImpl for simplicity

Constructor Detail

SessionImpl

public SessionImpl()
Method Detail

createRequest

public Request createRequest(URL url,
                             int httpMethod,
                             String version)
Creates a request object with the specified URL, HTTP Method, and version.

Specified by:
createRequest in interface Session
Parameters:
url - The URL to request of the HTTP server.
httpMethod - An integer representing the HTTP method (e.g. GET, PUT) used to communicate with server.
version - A String representing the version of the HTTP request, i.e. 1.0 or 1.1.
Returns:
a new Request object representing the url and httpMethod
See Also:
Request.HTTP_METHOD_GET, Request.HTTP_METHOD_POST

createRequest

public Request createRequest(String label,
                             URL url,
                             int httpMethod,
                             String version,
                             boolean followRedirects)
Creates a labeled request object with the specified URL, HTTP Method, version, and redirect handling behavior. Note: in the current implementation, old request objects will not be resued.

Specified by:
createRequest in interface Session
Parameters:
label - Name of the request
url - The URL to request of the HTTP server.
httpMethod - An integer representing the HTTP method (e.g. GET, PUT) used to communicate with server.
version - A String representing the version of the HTTP request, i.e. 1.0 or 1.1.
followRedirects - whether HTTP redirects should be processed
Returns:
a new Request object representing the url and httpMethod
See Also:
Request.HTTP_METHOD_GET, Request.HTTP_METHOD_POST

createRequest

public Request createRequest(URL url,
                             int httpMethod,
                             Proxy proxy,
                             String version)
Creates a request object with the specified URL, HTTP Method, and version to be accessed via the provided proxy.

Specified by:
createRequest in interface Session
Parameters:
url - The URL to request of the HTTP server.
httpMethod - An integer representing the HTTP method (e.g. GET, PUT) used to communicate with server.
version - A String representing the version of the HTTP request, i.e. 1.0 or 1.1.
proxy - a proxy to use during the request
Returns:
a new Request object representing the url and httpMethod
See Also:
Request.HTTP_METHOD_GET, Request.HTTP_METHOD_POST, Proxy

createRequest

public Request createRequest(String label,
                             URL url,
                             int httpMethod,
                             String version,
                             boolean followRedirects,
                             Proxy proxy)
Create a labeled request , with the specified URL, HTTP method, version, and redirect handling behavior, using the given proxy for communications.

Specified by:
createRequest in interface Session
Parameters:
label - a name used to identify the request
url - The URL to request of the HTTP server.
httpMethod - An integer representing the HTTP method (e.g. GET, PUT) used to communicate with server.
version - A String representing the version of the HTTP request, i.e. 1.0 or 1.1.
followRedirects - whether to follow HTTP redirection responses
proxy - a proxy to use during the request
Returns:
a new Request object representing the url and httpMethod.
See Also:
Request.HTTP_METHOD_GET, Request.HTTP_METHOD_POST, Proxy

setReferer

protected void setReferer(URL url)
Called inside the request.execute() method, setting the referer for the next request.

Parameters:
url - URL of the last executed request.

getReferer

protected URL getReferer()
The URL of the last request that was executed. This will be the _actual_ url accessed in the result of a 301 or 302 redirect (the page that returned a 200 status code).

Returns:
Referer of the last request, or null if there have been no successful requests.

addCookie

public void addCookie(String domain,
                      String path,
                      String name,
                      String value)
Adds a cookie to all HTTP requests whose domain and path match (according to RFC2109).

Specified by:
addCookie in interface Session
Parameters:
domain - the domain to which the cookie should apply
path - the path to which the cookie should apply
name - the name of the cookie
value - the value of the cookie

getCookieValue

public String getCookieValue(String name)
Returns the value of cookie name.

Specified by:
getCookieValue in interface Session
Parameters:
name - the name of the cookie
Returns:
the value of the cookie, or null if the cookie isn't set


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.