Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.sonalb.net.http
Class HTTPRedirectHandler  view HTTPRedirectHandler download HTTPRedirectHandler.java

java.lang.Object
  extended bycom.sonalb.net.http.HTTPRedirectHandler

public class HTTPRedirectHandler
extends java.lang.Object

Convenience class that combines cookie-handling and redirect-handling logic. When the connect() method is invoked, the handler cyclically processes HTTP Redirects (if any), and also takes care of cookie-handling while doing so. The maximum number of redirects defaults to 10. The handler determines a successful run, when the HTTP response code is equal to a specified success code. This code defaults to 200 (OK).


Field Summary
(package private)  boolean bConnected
           
(package private)  boolean bConnectMethodAlreadyCalled
           
(package private)  boolean bCookies
           
(package private)  com.sonalb.net.http.cookie.CookieJar cj
           
(package private)  com.sonalb.net.http.cookie.Client client
           
static java.lang.String CVSID
           
(package private)  java.net.HttpURLConnection huc
           
(package private)  java.io.InputStream is
           
(package private)  int maxRedirects
           
(package private)  int successCode
           
 
Constructor Summary
HTTPRedirectHandler(java.net.HttpURLConnection huc)
          Creates a handler for the input HttpURLConnection.
 
Method Summary
 void addCookies(com.sonalb.net.http.cookie.CookieJar cj)
          Adds some Cookies to the existing Cookies in an HTTPRedirectHandler.
 void connect()
          Connects to initial HttpURLConnection (specified during construction), and initiates cookie-handling and redirect-handling.
 java.net.HttpURLConnection getConnection()
          Gets the HttpURLConnection for the final successful response.
 com.sonalb.net.http.cookie.CookieJar getCookieJar()
          Gets the CookieJar containing any pre-existing Cookies, as well as new ones extracted during processing.
 java.io.InputStream getInputStream()
          Gets the InputStream for the final successful response.
 void handleCookies(boolean b)
          Enables/Disables automated cookie-handling.
 boolean isConnected()
          Checks whether this handler has successfully connected.
 void setClient(com.sonalb.net.http.cookie.Client cl)
          Sets the Client to be used for this handler.
 void setCookieJar(com.sonalb.net.http.cookie.CookieJar cj)
          Sets the CookieJar containing Cookies to be used during cookie-handling.
 void setMaxRedirects(int i)
          Sets the maximum number of redirects that will be followed.
 void setSuccessCode(int i)
          Sets the HTTP response code designating a successful run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVSID

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

huc

java.net.HttpURLConnection huc

cj

com.sonalb.net.http.cookie.CookieJar cj

client

com.sonalb.net.http.cookie.Client client

bCookies

boolean bCookies

successCode

int successCode

maxRedirects

int maxRedirects

bConnected

boolean bConnected

bConnectMethodAlreadyCalled

boolean bConnectMethodAlreadyCalled

is

java.io.InputStream is
Constructor Detail

HTTPRedirectHandler

public HTTPRedirectHandler(java.net.HttpURLConnection huc)
Creates a handler for the input HttpURLConnection. The HttpURLConnection must NOT be connected yet.

Method Detail

setClient

public void setClient(com.sonalb.net.http.cookie.Client cl)
Sets the Client to be used for this handler.


handleCookies

public void handleCookies(boolean b)
Enables/Disables automated cookie-handling.


setSuccessCode

public void setSuccessCode(int i)
Sets the HTTP response code designating a successful run.


setCookieJar

public void setCookieJar(com.sonalb.net.http.cookie.CookieJar cj)
Sets the CookieJar containing Cookies to be used during cookie-handling.


addCookies

public void addCookies(com.sonalb.net.http.cookie.CookieJar cj)
Adds some Cookies to the existing Cookies in an HTTPRedirectHandler.


getCookieJar

public com.sonalb.net.http.cookie.CookieJar getCookieJar()
Gets the CookieJar containing any pre-existing Cookies, as well as new ones extracted during processing.


getInputStream

public java.io.InputStream getInputStream()
Gets the InputStream for the final successful response.


getConnection

public java.net.HttpURLConnection getConnection()
Gets the HttpURLConnection for the final successful response.


setMaxRedirects

public void setMaxRedirects(int i)
Sets the maximum number of redirects that will be followed.


connect

public void connect()
             throws java.io.IOException,
                    com.sonalb.net.http.cookie.MalformedCookieException
Connects to initial HttpURLConnection (specified during construction), and initiates cookie-handling and redirect-handling. It can only be called once per instance.


isConnected

public boolean isConnected()
Checks whether this handler has successfully connected.