java.lang.Object
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();
...
}
}
|
Constructor Summary |
Client()
Constructs an instance using the default CookieParser |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CVSID
public static final java.lang.String CVSID
- See Also:
- Constant Field Values
defaultCookieParser
private static final CookieParser defaultCookieParser
logger
private static java.util.logging.Logger logger
currentCookieParser
private CookieParser currentCookieParser
Client
public Client()
- Constructs an instance using the default CookieParser
getDefaultCookieParser
public static CookieParser getDefaultCookieParser()
- Returns the built-in
CookieParser implementation. Current implementation
conforms to RFC-2965.
resetToDefaultCookieParser
public void resetToDefaultCookieParser()
- Resets the
CookieParser implementation to be used for this instance, to the default
(built-in) implementation.
setCookieParser
public void setCookieParser(CookieParser cp)
- Sets the
CookieParser implementation to be used in this instance.
getCookieParser
public CookieParser getCookieParser()
- Gets the
CookieParser implementation being used in this instance.
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.
getCookies
protected CookieJar getCookies(java.net.URLConnection urlConn,
java.net.URL url)
throws MalformedCookieException
getCookies
protected CookieJar getCookies(com.sonalb.net.http.Header header,
java.net.URL url)
throws MalformedCookieException
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.