Groovy Documentation

org.jdesktop.http
[Java] Class Session

java.lang.Object
  org.jdesktop.beans.AbstractBean
      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.

Authors:
rbair


Nested Class Summary
enum Session.SecurityLevel

Specifies a value to use for security, either Low, Medium, or High.

 
Field Summary
private long bytesSoFar

Keeps track of the total number of bytes transfered upstream or downstream.

private SecurityHandler handler

private Session.SecurityLevel sslSecurity

private State state

Keeps track of the state of the Session when performing a request/response cycle.

private long totalBytes

Keeps track of the total number of bytes that are to be sent or receieved.

 
Constructor Summary
Session()

Creates a new Session.

Session(boolean installCookieManager)

Creates a new Session.

 
Method Summary
private SSLSocketFactory createSocketFactory(String host)

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()

SecurityHandler getMediumSecurityHandler()

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.

private byte[] readFully(InputStream in)

private void setBytesSoFar(long bytes)

void setMediumSecurityHandler(SecurityHandler h)

void setSslSecurityLevel(Session.SecurityLevel level)

Sets the security level to use with SSL.

protected void setState(State s)

private void setTotalBytes(long bytes)

Session valueOf(String name)

Returns the enum constant of this type with the specified name.

Session[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class org.jdesktop.beans.AbstractBean
org.jdesktop.beans.AbstractBean#clone(), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(), org.jdesktop.beans.AbstractBean#wait(), org.jdesktop.beans.AbstractBean#wait(long), org.jdesktop.beans.AbstractBean#wait(long, int), org.jdesktop.beans.AbstractBean#equals(java.lang.Object), org.jdesktop.beans.AbstractBean#toString(), org.jdesktop.beans.AbstractBean#hashCode(), org.jdesktop.beans.AbstractBean#getClass(), org.jdesktop.beans.AbstractBean#notify(), org.jdesktop.beans.AbstractBean#notifyAll()
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

bytesSoFar

private long bytesSoFar
Keeps track of the total number of bytes transfered upstream or downstream. This is reset when DONE, or when switching from upload to download. This is used whether or not the content-length is known


handler

private SecurityHandler handler


sslSecurity

private Session.SecurityLevel sslSecurity

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.

Authors:
rbair


state

private State state
Keeps track of the state of the Session when performing a request/response cycle.


totalBytes

private long totalBytes
Keeps track of the total number of bytes that are to be sent or receieved. This is reset when DONE, or switching from upload to download. This is only used if the content-length is known, otherwise it is set to -1.


 
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

createSocketFactory

private SSLSocketFactory createSocketFactory(String host)


createURL

protected URL createURL(String surl)
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 java.io.IOException


execute

public final Response execute(Method method, String url)
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.
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).
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.


execute

public final Response execute(Method method, String url, Parameter... params)
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.
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).
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.


execute

public Response execute(Request req)
Executes the given Request, and returns a Response. This method blocks.
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).
Returns:
the Response to the Request.


get

public final Response get(String url)
Constructs and executes a Request using the Method.GET method. This method blocks.
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).
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.


get

public final Response get(String url, Parameter... params)
Constructs and executes a Request using the Method.GET method. This method blocks.
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).
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.


getBytesSoFar

public final long getBytesSoFar()


getMediumSecurityHandler

SecurityHandler getMediumSecurityHandler()


getProgress

public final float getProgress()


getSslSecurityLevel

public final Session.SecurityLevel getSslSecurityLevel()
Gets the SecurityLevel used for SSL connections.
Returns:
the SecurityLevel
See Also:
setSslSecurityLevel


getState

public final State getState()


getTotalBytes

public final long getTotalBytes()


post

public final Response post(String url)
Constructs and executes a Request using the Method.POST method. This method blocks.
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).
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.


post

public final Response post(String url, Parameter... params)
Constructs and executes a Request using the Method.POST method. This method blocks.
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).
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.


put

public final Response put(String url)
Constructs and executes a Request using the Method.PUT method. This method blocks.
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).
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.


put

public final Response put(String url, Parameter... params)
Constructs and executes a Request using the Method.PUT method. This method blocks.
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).
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.


readFully

private byte[] readFully(InputStream in)


setBytesSoFar

private void setBytesSoFar(long bytes)


setMediumSecurityHandler

void setMediumSecurityHandler(SecurityHandler h)


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.


setState

protected void setState(State s)


setTotalBytes

private void setTotalBytes(long bytes)


valueOf

Session valueOf(String name)
Returns the enum constant of this type with the specified name.


values

Session[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation