|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ibisph.util.NetLib
public abstract class NetLib
NetLib is an abstract library class with various utility methods used for odd ball HTML and URL related helper functions.
URLConnections vs. URLs - Can send output as well as read input - Can post data to CGIs - Can read headers from a connection
| Constructor Summary | |
|---|---|
NetLib()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
base64Encode(byte[] octetString)
David W. |
static java.lang.String |
base64Encode(java.lang.String string)
David W. |
static java.lang.String |
encode(java.lang.String url,
java.lang.String characterEncoding)
Helper that simply localizes the URLEncoder with UTF-8. |
static java.lang.String |
getCookieValue(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
Get's a cookie value from the request's header. |
static java.lang.String |
getCookieValue(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName,
java.lang.String defaultValue)
Get's a cookie value from the request's header. |
static java.net.URLConnection |
getHTTPPostURLConnection(java.lang.String urlAddress)
See getHTTPPostURLConnection(String urlAddress, String contentType);
with the default value of "text/plain". |
static java.net.URLConnection |
getHTTPPostURLConnection(java.lang.String urlAddress,
java.lang.String contentType)
Sets up a URLConnection for an HTTP Post Request. |
static java.lang.String |
getURLContent(java.lang.String address)
|
static java.lang.String |
getURLContent(java.lang.String address,
java.lang.String username,
java.lang.String password)
|
static java.lang.String |
getURLContent(java.net.URL baseContext,
java.lang.String address)
|
static java.lang.String |
getURLContent(java.net.URL baseContext,
java.lang.String address,
java.lang.String username,
java.lang.String password)
Opens the specified URL and returns the request's contents as a string. |
static java.io.InputStream |
getURLResponseInputStream(java.net.URL baseContext,
java.lang.String address)
Gets a URL input stream connection. |
static java.io.InputStream |
getURLResponseInputStream(java.net.URL baseContext,
java.lang.String address,
java.lang.String username,
java.lang.String password)
Gets a URL input stream connection with optional username/password. |
static java.io.InputStream |
httpPostContent(java.lang.String urlAddress,
java.lang.String content)
Same as httpPostContent(String urlAddress, null, String content);. |
static java.io.InputStream |
httpPostContent(java.lang.String urlAddress,
java.lang.String contentType,
java.lang.String content)
Sends data to a URL via an HTTP post (a get type request is simply a URL with a query string suffix). |
static void |
logCookies(javax.servlet.http.HttpServletRequest request)
Shows all of the available request's header cookies by name and value. |
static int |
saveURLResponse(java.lang.String address,
java.lang.String filename)
Save the specified URL address to a file named with the filename. |
static boolean |
sendHTML(javax.servlet.http.HttpServletResponse response,
java.lang.String html)
Simple helper which sets the response's content type to text/html
and writes the contents. |
static void |
sendText(javax.servlet.http.HttpServletResponse response,
java.lang.String text)
Simple helper which sets the response's content type to text/plain
and writes the contents. |
static void |
sendTextAsHTML(javax.servlet.http.HttpServletResponse response,
java.lang.String text)
Simple helper which sets the response's content type to text/html
and writes the contents wrapped between
tags. |
static void |
sendTHMLErrorPage(javax.servlet.http.HttpServletResponse response,
java.lang.String errorTitle,
java.lang.String errorMessage)
Creates a simply formatted error HTML page. |
static void |
setNoCacheHTTPHeaders(javax.servlet.http.HttpServletResponse response)
Sets HTTP Meta tag headers that tells servers/browsers that this response should not be cached. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NetLib()
| Method Detail |
|---|
public static java.lang.String base64Encode(byte[] octetString)
octetString - Byte array to be encoded.
public static java.lang.String base64Encode(java.lang.String string)
string - Text to be encoded.
public static java.lang.String encode(java.lang.String url,
java.lang.String characterEncoding)
throws java.io.UnsupportedEncodingException
url - URL to be encoded.characterEncoding - Optional character Encoding to be used.
Defaults to UTF-8.
java.io.UnsupportedEncodingException
public static java.io.InputStream getURLResponseInputStream(java.net.URL baseContext,
java.lang.String address,
java.lang.String username,
java.lang.String password)
throws java.io.IOException,
java.net.MalformedURLException,
java.net.URISyntaxException
baseContext - Optional context to base the address from. If
baseContext != null then the address is relative to this
base context.address - URL address. if baseContext != null then
treated as relative, else the address must be an explicit URL
complete with protocol, server name, port, and context.username - Optional username to authenticate with.password - Optional password to authenticate with.
java.io.IOException - Stream and connection related.
java.net.MalformedURLException - URL related.
java.net.URISyntaxException
public static java.io.InputStream getURLResponseInputStream(java.net.URL baseContext,
java.lang.String address)
throws java.io.IOException,
java.net.MalformedURLException,
java.net.URISyntaxException
baseContext - Optional context to base the address from. If
baseContext != null then the address is relative to this
base context.address - URL address. if baseContext != null then
treated as relative, else the address must be an explicit URL
complete with protocol, server name, port, and context.
java.io.IOException - Stream and connection related.
java.net.MalformedURLException - URL related.
java.net.URISyntaxException
public static java.lang.String getURLContent(java.net.URL baseContext,
java.lang.String address,
java.lang.String username,
java.lang.String password)
throws java.io.IOException,
java.net.URISyntaxException
baseContext - Optional context to base the address from. If
baseContext != null then the address is relative to this
base context.address - URL address. if baseContext != null then
treated as relative, else the address must be an explicit URL
complete with protocol, server name, port, and context.username - Optional username to authenticate with.password - Optional password to authenticate with.
java.io.IOException - Stream and connection related.
java.net.URISyntaxException
public static java.lang.String getURLContent(java.net.URL baseContext,
java.lang.String address)
throws java.io.IOException,
java.net.URISyntaxException
java.io.IOException
java.net.URISyntaxException
public static java.lang.String getURLContent(java.lang.String address,
java.lang.String username,
java.lang.String password)
throws java.io.IOException,
java.net.URISyntaxException
java.io.IOException
java.net.URISyntaxException
public static java.lang.String getURLContent(java.lang.String address)
throws java.io.IOException,
java.net.URISyntaxException
java.io.IOException
java.net.URISyntaxException
public static int saveURLResponse(java.lang.String address,
java.lang.String filename)
throws java.io.IOException,
java.net.MalformedURLException
address - URL address complete with protocol, server name, port,
and context.filename - Complete path and filename of where to save the URL
request's response content to.
java.io.IOException - File and stream related.
java.net.MalformedURLException - URL address related.
public static void sendText(javax.servlet.http.HttpServletResponse response,
java.lang.String text)
throws java.io.IOException
text/plain
and writes the contents.
response - Destination response to write the contents to.text - Contents to write.
java.io.IOException - Response writer related.
public static boolean sendHTML(javax.servlet.http.HttpServletResponse response,
java.lang.String html)
throws java.io.IOException
text/html
and writes the contents.
response - Destination response to write the contents to.html - Contents to write.
java.io.IOException - Response writer related.
public static void sendTextAsHTML(javax.servlet.http.HttpServletResponse response,
java.lang.String text)
throws java.io.IOException
text/html
and writes the contents wrapped between
tags.
response - Destination response to write the contents to.text - Contents to wrap within an tag and
written to the response.
java.io.IOException - Response writer related.
public static void sendTHMLErrorPage(javax.servlet.http.HttpServletResponse response,
java.lang.String errorTitle,
java.lang.String errorMessage)
throws java.lang.Exception
text/html, a page title is set, and the error message is wrapped
within tags.
response - Destination response to write the contents to.errorTitle - Text used for the page title and displayed as the main
problem message.errorMessage - Detailed error message text displayed.
java.lang.Exception - Response print writer related.public static void setNoCacheHTTPHeaders(javax.servlet.http.HttpServletResponse response)
response - Response which will be modified/have headers set.
public static java.net.URLConnection getHTTPPostURLConnection(java.lang.String urlAddress,
java.lang.String contentType)
throws java.io.IOException,
java.net.MalformedURLException
urlAddress - Complete explicit URL address to be used for a request.contentType - HTTP content type. If null, this value defaults to
"text/plain".
java.io.IOException - URL connection related.
java.net.MalformedURLException - URL address related.
public static java.net.URLConnection getHTTPPostURLConnection(java.lang.String urlAddress)
throws java.io.IOException,
java.net.MalformedURLException
getHTTPPostURLConnection(String urlAddress, String contentType);
with the default value of "text/plain".
java.io.IOException
java.net.MalformedURLException
public static java.io.InputStream httpPostContent(java.lang.String urlAddress,
java.lang.String contentType,
java.lang.String content)
throws java.io.IOException
urlAddress - Complete destination URL address to post content to.contentType - Type of HTTP content to be streamed to destination.
Any valid HTTP Content Type such as "text/plain" etc.content - Text to be posted/streamed.
java.io.IOException - Stream and connection related.
public static java.io.InputStream httpPostContent(java.lang.String urlAddress,
java.lang.String content)
throws java.io.IOException
httpPostContent(String urlAddress, null, String content);.
java.io.IOException
public static java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName,
java.lang.String defaultValue)
request - Source which should contain all available domain and
context cookies.cookieName - Key value used to locate the cookie value.defaultValue - Value to be returned if the cookie is not found.
public static java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
request - Source which should contain all available domain and
context cookies.cookieName - Key value used to locate the cookie value.
public static void logCookies(javax.servlet.http.HttpServletRequest request)
request - Source which should contain all available domain and
context cookies.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||