org.jdesktop.http
Class Session

java.lang.Object
  extended by org.jdesktop.beans.AbstractBean
      extended by org.jdesktop.http.Session

public class Session
extends org.jdesktop.beans.AbstractBean

Represents a user's "session" on the web. Think of it as a "tab" in a tabbed web browser. It may access multiple web sites during one "session", but remembers the cookies for all of them.

Sessions also contain all the information needed to keep track of the progress of a request/response cycle (including uploading and downloading of data). The values are reset at the beginning of a request and maintain their values until the next request is made. The property change events are fired on whatever thread called the execute method -- most likely a background thread (not the EDT). Be careful of that when binding GUI widgets to these properties.


Nested Class Summary
static class Session.SecurityLevel
          Specifies a value to use for security, either Low, Medium, or High.
 
Constructor Summary
Session()
          Creates a new Session.
Session(boolean installCookieManager)
          Creates a new Session.
 
Method Summary
protected  URL createURL(String surl)
          This method exists for the sake of testing.
 Response execute(Method method, String url)
          Constructs and executes a Request, and returns the Response.
 Response execute(Method method, String url, Parameter... params)
          Constructs and executes a Request, and returns the Response.
 Response execute(Request req)
          Executes the given Request, and returns a Response.
 Response get(String url)
          Constructs and executes a Request using the Method.GET method.
 Response get(String url, Parameter... params)
          Constructs and executes a Request using the Method.GET method.
 long getBytesSoFar()
           
 float getProgress()
           
 Session.SecurityLevel getSslSecurityLevel()
          Gets the SecurityLevel used for SSL connections.
 State getState()
           
 long getTotalBytes()
           
 Response post(String url)
          Constructs and executes a Request using the Method.POST method.
 Response post(String url, Parameter... params)
          Constructs and executes a Request using the Method.POST method.
 Response put(String url)
          Constructs and executes a Request using the Method.PUT method.
 Response put(String url, Parameter... params)
          Constructs and executes a Request using the Method.PUT method.
 void setSslSecurityLevel(Session.SecurityLevel level)
          Sets the security level to use with SSL.
protected  void setState(State s)
           
 
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Session

public Session()
Creates a new Session. Automatically installs the CookieManager.


Session

public Session(boolean installCookieManager)
Creates a new Session. If installCookieManager is true, then the CookieManager is installed automatically. Otherwise, the CookieManager will not be installed, allowing you to use some other cookie manager.

Parameters:
installCookieManager -
Method Detail

setSslSecurityLevel

public void setSslSecurityLevel(Session.SecurityLevel level)
Sets the security level to use with SSL.

Parameters:
level - one of High, Medium, or Low. Low will not prompt or fail for self signed certs. Medium will prompt for self signed certs. High will fall back on the default behavior, and simply fail for self signed certs.

getSslSecurityLevel

public final Session.SecurityLevel getSslSecurityLevel()
Gets the SecurityLevel used for SSL connections.

Returns:
the SecurityLevel
See Also:
setSslSecurityLevel(org.jdesktop.http.Session.SecurityLevel)

getTotalBytes

public final long getTotalBytes()

getBytesSoFar

public final long getBytesSoFar()

getProgress

public final float getProgress()

getState

public final State getState()

setState

protected void setState(State s)

get

public final Response get(String url)
                   throws Exception
Constructs and executes a Request using the Method.GET method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

get

public final Response get(String url,
                          Parameter... params)
                   throws Exception
Constructs and executes a Request using the Method.GET method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
params - The params to include in the request. This may be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

post

public final Response post(String url)
                    throws Exception
Constructs and executes a Request using the Method.POST method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

post

public final Response post(String url,
                           Parameter... params)
                    throws Exception
Constructs and executes a Request using the Method.POST method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
params - The params to include in the request. This may be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

put

public final Response put(String url)
                   throws Exception
Constructs and executes a Request using the Method.PUT method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

put

public final Response put(String url,
                          Parameter... params)
                   throws Exception
Constructs and executes a Request using the Method.PUT method. This method blocks.

Parameters:
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
params - The params to include in the request. This may be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

execute

public final Response execute(Method method,
                              String url)
                       throws Exception
Constructs and executes a Request, and returns the Response. This method blocks. The given method, url will be used to construct the Request. All other Request properties are left in their default state.

Parameters:
method - The HTTP Method to use. This must not be null.
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

execute

public final Response execute(Method method,
                              String url,
                              Parameter... params)
                       throws Exception
Constructs and executes a Request, and returns the Response. This method blocks. The given method, url, and params will be used to construct the Request. All other Request properties are left in their default state.

Parameters:
method - The HTTP Method to use. This must not be null.
url - The url to hit. This url may contain a query string (ie: params). The url cannot be null.
params - The params to include in the request. This may be null.
Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

execute

public Response execute(Request req)
                 throws Exception
Executes the given Request, and returns a Response. This method blocks.

Returns:
the Response to the Request.
Throws:
Exception - if an error occurs while creating or executing the Request on the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).

createURL

protected URL createURL(String surl)
                 throws MalformedURLException
This method exists for the sake of testing. I can create a url while testing even without having internet access by overriding this method to return an HttpURLConnection subclass that doesn't actually connect to the internet. I can then fake out all the operations of the URL connection. This method is not to be overridden by any classes other than the test class.

Parameters:
conn -
Returns:
Throws:
IOException
MalformedURLException