Package com.sun.ts.lib.util
Class WebUtil
java.lang.Object
com.sun.ts.lib.util.WebUtil
Contains convenience methods for interacting with a web server.
- Author:
- Mark Roth
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Reponse object containing information returned from the web server -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Encodes the given string in base64 format (useful for BASIC authentication).static String
getRequestFromURL
(String urlString) Converts a standard URL to a request.static WebUtil.Response
sendAuthenticatedRequest
(String method, InetAddress addr, int port, String req, Properties postData, Hashtable cookieList, String username, String password) Sends an authenticated request to the web server.static WebUtil.Response
sendRequest
(String method, InetAddress addr, int port, String req, Properties postData, Hashtable cookieList) Sends a request to the web server.
-
Constructor Details
-
WebUtil
public WebUtil()
-
-
Method Details
-
getRequestFromURL
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 serverport
- Port of web serverreq
- 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 serverport
- Port of web serverreq
- 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
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
-