Class WebUtil

java.lang.Object
com.sun.ts.lib.util.WebUtil

public class WebUtil extends Object
Contains convenience methods for interacting with a web server.
Author:
Mark Roth
  • Constructor Details

    • WebUtil

      public WebUtil()
  • Method Details

    • getRequestFromURL

      public static String getRequestFromURL(String urlString) throws MalformedURLException
      Converts a standard URL to a request. For example, the string "http://goodtimes:8000/testing" would be converted to "/testing".
      Parameters:
      urlString - The URL to convert
      Returns:
      The resulting GET request
      Throws:
      MalformedURLException - Thrown if the urlString does not contain a valid URL.
    • sendRequest

      public static WebUtil.Response sendRequest(String method, InetAddress addr, int port, String req, Properties postData, Hashtable cookieList) throws IOException
      Sends a request to the web server. A WebUtil.Response object is returned with the response information.
      Parameters:
      method - Can be either "GET" or "POST"
      addr - Address of web server
      port - Port of web server
      req - The file to request (e.g. /jsp_dep_secContextRoot/jspSec.jsp)
      postData - If this is a POST request, the data to be posted, encoded in a Properties class. null if no post data to be sent.
      cookieList - A list of cookies to send when requesting the page. null if no cookie list is to be sent.
      Returns:
      WebUtil.Response object containing response information
      Throws:
      IOException - Thrown if request could not be made
    • sendAuthenticatedRequest

      public static WebUtil.Response sendAuthenticatedRequest(String method, InetAddress addr, int port, String req, Properties postData, Hashtable cookieList, String username, String password) throws IOException
      Sends an authenticated request to the web server. A WebUtil.Response object is returned with the response information.
      Parameters:
      method - Can be either "GET" or "POST"
      addr - Address of web server
      port - Port of web server
      req - The file to request (e.g. /jsp_dep_secContextRoot/jspSec.jsp)
      postData - If this is a POST request, the data to be posted, encoded in a Properties class. null if no post data to be sent.
      cookieList - A list of cookies to send when requesting the page. null if no cookie list is to be sent.
      username - The username for authentication, null if no authentication required.
      password - The password for authentication, null if no authentication required.
      Returns:
      WebUtil.Response object containing response information
      Throws:
      IOException - Thrown if request could not be made
    • encodeBase64

      public static String encodeBase64(String s)
      Encodes the given string in base64 format (useful for BASIC authentication). Base64 encoding is defined by RFC2047.
      Parameters:
      s - The string to encode
      Returns:
      The encoded string