Class Session


public class Session extends 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.

  • Constructor Details

    • 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 Details

    • 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