com.pushtotest.tool.protocolhandler
Class HTTPProtocol

java.lang.Object
  extended by com.pushtotest.tool.protocolhandler.ProtocolWrapper
      extended by com.pushtotest.tool.protocolhandler.HTTPProtocol
All Implemented Interfaces:
Protocol, java.lang.Runnable
Direct Known Subclasses:
HTTPSProtocol

public class HTTPProtocol
extends ProtocolWrapper

This is the implementation of the HTTP Protocol handler. This will probably reused by a lot of stuff including HTTPS and SOAP, so be careful not to make to many assumption about the way of the world, so that other code can piggy back off of it.


Field Summary
 com.sonalb.net.http.cookie.CookieJar cookieJar
           
static int GET
           
static int POST
           
 
Fields inherited from class com.pushtotest.tool.protocolhandler.ProtocolWrapper
body, errno, header, host, name, pass, path, port, proxyHost, proxyPass, proxyPort, proxyUser, query, response, running, scheme, timeout, type, url
 
Fields inherited from interface com.pushtotest.tool.protocolhandler.Protocol
IOERROR, NOERROR, NOTREADY, OTHER, TIMEOUT
 
Constructor Summary
HTTPProtocol()
           
 
Method Summary
 void clearURLlist()
          Clears the previously recorded list of visited URLs.
 Response connect()
          Calling this method actually causes the connection to be made.
 Response connect(int follow)
          Same as connect() plus has option to follow HTTP 302 Redirect commands.
 Response connect(javax.net.ssl.SSLSocketFactory sslSF)
          Calling this method actually causes the connection to be made.
 java.util.Iterator getCookies()
          Returns an iterator that returns a collection of com.sonalb.net.http.cookie.Cookie objects, each one encapusaltes a cookie.
 java.lang.String getHeaderField(java.lang.String headerkey)
          Get a HTTP header field, based on the header key name.
 java.util.Map getHeaderFields()
          Get the HTTP Header field list
 java.util.Enumeration getURLlist()
          Returns an Enumeration of URLs to which this object has connected.
 java.lang.String id()
          Returns an id for this protocol.
 void send()
          Not needed in an HTTP context
 void setDisconnect(boolean flag)
           
 void setHostnameVerifier(com.sun.net.ssl.HostnameVerifier hnv)
          Sets the HostnameVerifier for an HTTPS connection.
protected  boolean supports(java.lang.String id)
          Tests to see if this protocol will support a specific type.
 
Methods inherited from class com.pushtotest.tool.protocolhandler.ProtocolWrapper
getBody, getErrno, getHost, getPassword, getResponse, getTimeout, getUrl, getUrl, getURL, getUsername, isRunning, parseUrl, run, setBody, setErrno, setHeader, setHost, setPassword, setPath, setPort, setProxyHost, setProxyPass, setProxyPort, setProxyUser, setQueryString, setScheme, setTimeout, setType, setUrl, setUsername, supportsBody, supportsHeader, supportsResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET

public static final int GET
See Also:
Constant Field Values

POST

public static final int POST
See Also:
Constant Field Values

cookieJar

public com.sonalb.net.http.cookie.CookieJar cookieJar
Constructor Detail

HTTPProtocol

public HTTPProtocol()
Method Detail

id

public java.lang.String id()
Returns an id for this protocol. The id is a string that will be used to uniquily identify the protocol. For example :// would be appropriate (without the "://").

Specified by:
id in interface Protocol
Specified by:
id in class ProtocolWrapper
Returns:
The id for this Protocol.

setDisconnect

public void setDisconnect(boolean flag)

connect

public Response connect(javax.net.ssl.SSLSocketFactory sslSF)
                 throws NotReadyException,
                        NoSuchClassException,
                        ToolException,
                        java.io.IOException
Calling this method actually causes the connection to be made. It will do the work of making the connection, gathering the response, etc. This version takes a type param to allow different types of connection to be made with a given Protocol. E.g. an HTTPProtocol could define GET and POST to determine what type of HTTP request it should send. Automatically follows HTTP 302 Redirect commands. See connect( flag ) to control following redirect commands.

Returns:
The response object that is the appropriate type for this Protocol.
Throws:
NotReadyException - If the connect is called without all of the proper pieces set that it needs to connect to the given protocol.
ConnectionTimeoutException - If a timeout was set and that timeout is reached before the connection is completed. Additionally it will set the SSLSocketFactory to allow the connection to a SSL where private certificates are used.
NoSuchClassException
ToolException
java.io.IOException

connect

public Response connect()
                 throws NotReadyException,
                        NoSuchClassException,
                        ToolException,
                        java.io.IOException
Calling this method actually causes the connection to be made. It will do the work of making the connection, gathering the response, etc. This version takes a type param to allow different types of connection to be made with a given Protocol. E.g. an HTTPProtocol could define GET and POST to determine what type of HTTP request it should send. Automatically follows HTTP 302 Redirect commands. See connect( flag ) to control following redirect commands.

Specified by:
connect in interface Protocol
Specified by:
connect in class ProtocolWrapper
Returns:
The response object that is the appropriate type for this Protocol.
Throws:
NotReadyException - If the connect is called without all of the proper pieces set that it needs to connect to the given protocol.
ConnectionTimeoutException - If a timeout was set and that timeout is reached before the connection is completed.
NoSuchClassException
ToolException
java.io.IOException

connect

public Response connect(int follow)
                 throws NotReadyException,
                        NoSuchClassException,
                        ToolException,
                        java.io.IOException
Same as connect() plus has option to follow HTTP 302 Redirect commands.

Parameters:
follow - if set to 1 tells connect to automatically follow HTTP 302 Redirect commands to the next URL. 1 also tells connect to follow redirects and add base URL values when the redirect header URL does not include them.
Throws:
NotReadyException
NoSuchClassException
ToolException
java.io.IOException

getCookies

public java.util.Iterator getCookies()
Returns an iterator that returns a collection of com.sonalb.net.http.cookie.Cookie objects, each one encapusaltes a cookie. The Cookie object supports both Netscape (Version 0) and RFC2965 (Version 1) cookies. The fields common to both these versions are:
NAME - Must be set, no default value
VALUE - Default value: Empty
Domain - Must be set, default: Local
Path - Must be set, default: / (root)
Secure - Optional, default: false


getURLlist

public java.util.Enumeration getURLlist()
Returns an Enumeration of URLs to which this object has connected.

Returns:
Enumeration returns null if no URLs have been used with a connect method.

setHostnameVerifier

public void setHostnameVerifier(com.sun.net.ssl.HostnameVerifier hnv)
Sets the HostnameVerifier for an HTTPS connection.


clearURLlist

public void clearURLlist()
Clears the previously recorded list of visited URLs. See getURLlist().


supports

protected boolean supports(java.lang.String id)
Tests to see if this protocol will support a specific type. Can be used to determine if a given Header, Body, etc can be passed into this Protocol. This uses the inherited supportsBody, supportsHeader, etc since they should all use either 'http' or 'https'.

Overrides:
supports in class ProtocolWrapper
Parameters:
id - The string id to test.

send

public void send()
Not needed in an HTTP context

Specified by:
send in class ProtocolWrapper

getHeaderFields

public java.util.Map getHeaderFields()
Get the HTTP Header field list


getHeaderField

public java.lang.String getHeaderField(java.lang.String headerkey)
Get a HTTP header field, based on the header key name. See getHeaderFields() to get a list of fields.