com.sonalb.net.http.cookie
Class Client

java.lang.Object
  extended by com.sonalb.net.http.cookie.Client

public class Client
extends java.lang.Object

This class is used to invoke the cookie-handling logic of the jCookie Library. It is the developer's view of the library. All cookie-handling methods are invoked on this object. The following snippet shows common-case usage. The highlighted portion is the only cookie-handling code, as far as the developer is concerned.

 import com.sonalb.net.http.cookie.*;
 import java.net.*;
 import java.io.*;
 ...

 public class Example
 {
      ...
      
      public void someMethod()
      {
         ...
         URL url = new URL("http://www.site.com/");
         HttpURLConnection huc = (HttpURLConnection) url.openConnection();

         // Setup the HttpURLConnection here
         ...

         huc.connect();
         InputStream is = huc.getInputStream();
         Client client = new Client();
         CookieJar cj = client.getCookies(huc);

         // Do some processing
         ...

         huc.disconnect();

         // Make another request
         url = new URL("http://www.site.com/");
         huc = (HttpURLConnection) url.openConnection();
         client.setCookies(huc, cj);

         huc.connect();
         ...
      }
   }
 

Author:
Sonal Bansal

Constructor Summary
Client()
          Constructs an instance using the default CookieParser
 
Method Summary
 CookieParser getCookieParser()
          Gets the CookieParser implementation being used in this instance.
 CookieJar getCookies(java.net.URLConnection urlConn)
          Processes cookie headers from the given URLConnection.
static CookieParser getDefaultCookieParser()
          Returns the built-in CookieParser implementation.
 void resetToDefaultCookieParser()
          Resets the CookieParser implementation to be used for this instance, to the default (built-in) implementation.
 void setCookieParser(CookieParser cp)
          Sets the CookieParser implementation to be used in this instance.
 CookieJar setCookies(java.net.URLConnection urlConn, CookieJar cj)
          Sets cookie headers on the given URLConnection, using Cookies in the CookieJar.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client()
Constructs an instance using the default CookieParser

See Also:
CookieParser, getDefaultCookieParser()
Method Detail

getDefaultCookieParser

public static CookieParser getDefaultCookieParser()
Returns the built-in CookieParser implementation. Current implementation conforms to RFC-2965.

Returns:
the default CookieParser implementation
See Also:
RFC2965CookieParser

resetToDefaultCookieParser

public void resetToDefaultCookieParser()
Resets the CookieParser implementation to be used for this instance, to the default (built-in) implementation.

See Also:
setCookieParser(CookieParser)

setCookieParser

public void setCookieParser(CookieParser cp)
Sets the CookieParser implementation to be used in this instance.

Parameters:
cp - the CookieParser to be used

getCookieParser

public CookieParser getCookieParser()
Gets the CookieParser implementation being used in this instance.

Returns:
the CookieParser in use

getCookies

public CookieJar getCookies(java.net.URLConnection urlConn)
                     throws MalformedCookieException
Processes cookie headers from the given URLConnection. This method must be called after the URLConnection is connected.

Parameters:
urlConn - the URLConnection to be processed
Throws:
MalformedCookieException - if there was some error during cookie processing

setCookies

public CookieJar setCookies(java.net.URLConnection urlConn,
                            CookieJar cj)
Sets cookie headers on the given URLConnection, using Cookies in the CookieJar. This method must be called before the URLConnection is connected.

Parameters:
urlConn - the URLConnection to be processed
cj - the CookieJar containing the Cookies to be set