Package org.jdesktop.http
Class Session
java.lang.Object
org.jdesktop.beans.AbstractBean
org.jdesktop.http.Session
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
Nested ClassesModifier and TypeClassDescriptionstatic classSpecifies a value to use for security, either Low, Medium, or High. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected URLThis method exists for the sake of testing.Constructs and executes aRequestusing the Method.GET method.Constructs and executes aRequestusing the Method.GET method.longfloatGets the SecurityLevel used for SSL connections.getState()longConstructs and executes aRequestusing the Method.POST method.Constructs and executes aRequestusing the Method.POST method.Constructs and executes aRequestusing the Method.PUT method.Constructs and executes aRequestusing the Method.PUT method.voidSets the security level to use with SSL.protected voidMethods 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
-
Constructor Details
-
Session
public Session()Creates a new Session. Automatically installs theCookieManager. -
Session
public Session(boolean installCookieManager)Creates a new Session. IfinstallCookieManageris true, then the CookieManager is installed automatically. Otherwise, theCookieManagerwill not be installed, allowing you to use some other cookie manager.- Parameters:
installCookieManager-
-
-
Method Details
-
setSslSecurityLevel
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
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
-
setState
-
get
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
get
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
post
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
post
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
put
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
put
Constructs and executes aRequestusing 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
execute
Constructs and executes aRequest, and returns theResponse. This method blocks. The givenmethod,urlwill be used to construct theRequest. All otherRequestproperties are left in their default state.- Parameters:
method- The HTTPMethodto 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
execute
Constructs and executes aRequest, and returns theResponse. This method blocks. The givenmethod,url, andparamswill be used to construct theRequest. All otherRequestproperties are left in their default state.- Parameters:
method- The HTTPMethodto 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
Responseto theRequest. - Throws:
Exception- if an error occurs while creating or executing theRequeston the client machine. That is, if normal http errors occur, they will not throw an exception (such as BAD_GATEWAY, etc).
-
execute
-
createURL
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:
IOExceptionMalformedURLException
-