javawebparts.request
Class RequestHelpers

java.lang.Object
  |
  +--javawebparts.request.RequestHelpers

public final class RequestHelpers
extends java.lang.Object

This class contains static methods that are too small to warrant their own class. General request-related utility methods.

Author:
Frank W. Zammetti, with contributions from Wendy Smoak.

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
 
Constructor Summary
private RequestHelpers()
          This is a utility class, so we want a private noarg constructor so instances cannot be created.
 
Method Summary
static java.lang.String generateGUID(javax.servlet.http.HttpServletRequest request)
          Returns a 32 character string uniquely identifying the given request object.
static java.util.Map getAllRequestInfo(javax.servlet.http.HttpServletRequest request)
          This method is a convenience method that calls the other three and returns a Map containing all request attributes, parameters and headers.
static java.lang.String getBodyContent(javax.servlet.http.HttpServletRequest request)
          This method will return the body content of an HTTP request as a String.
static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, java.lang.String cookieName)
          This method will return the Cookie with the provided name, if it is present in the request.
static java.util.Map getCookies(javax.servlet.http.HttpServletRequest request)
          This method will return a Map of all cookies in the request.
static java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request, java.lang.String cookieName)
          This method will return the value of the Cookie with the provided name, if it is present in the request.
static java.util.Map getRequestAttributes(javax.servlet.http.HttpServletRequest request)
          This method will return a Map that can be displayed which contains all request attributes.
static java.util.Map getRequestHeaders(javax.servlet.http.HttpServletRequest request)
          This method will return a Map that can be displayed which contains all request headers.
static java.util.Map getRequestParameters(javax.servlet.http.HttpServletRequest request)
          This method will return a Map that can be displayed which contains all request parameters.
static void logAllRequestInfo(javax.servlet.http.HttpServletRequest request)
          This method is a convenience method that calls the other three and dumps all headers, attributes and request to the log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.

Constructor Detail

RequestHelpers

private RequestHelpers()
This is a utility class, so we want a private noarg constructor so instances cannot be created.

Method Detail

logAllRequestInfo

public static void logAllRequestInfo(javax.servlet.http.HttpServletRequest request)
This method is a convenience method that calls the other three and dumps all headers, attributes and request to the log.

Parameters:
request - A valid HTTPServletRequest object.

getAllRequestInfo

public static java.util.Map getAllRequestInfo(javax.servlet.http.HttpServletRequest request)
This method is a convenience method that calls the other three and returns a Map containing all request attributes, parameters and headers.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
A Map containing three HashMaps, one each for headers, attributes and parameters. Returns null if request is null.

getRequestAttributes

public static java.util.Map getRequestAttributes(javax.servlet.http.HttpServletRequest request)
This method will return a Map that can be displayed which contains all request attributes.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
A Map of all request attributes. Returns null if request is null;

getRequestParameters

public static java.util.Map getRequestParameters(javax.servlet.http.HttpServletRequest request)
This method will return a Map that can be displayed which contains all request parameters.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
A Map of all request parameters. Returns null if request is null.

getRequestHeaders

public static java.util.Map getRequestHeaders(javax.servlet.http.HttpServletRequest request)
This method will return a Map that can be displayed which contains all request headers.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
A Map of all request headers. Returns null if request is null.

getCookie

public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String cookieName)
This method will return the Cookie with the provided name, if it is present in the request. Contributed by Wendy Smoak. Null is returned if the cookie is not found.

Parameters:
request - A valid HTTPServletRequest object.
cookieName - The name of the Cookie
Returns:
The Cookie with the provided name. Returns null if request is null or the Cookie is not present.

getCookieValue

public static java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request,
                                              java.lang.String cookieName)
This method will return the value of the Cookie with the provided name, if it is present in the request. Contributed by Wendy Smoak.

Parameters:
request - A valid HTTPServletRequest object.
cookieName - The name of the Cookie
Returns:
The String value of the Cookie with the provided name. Returns null if request is null or the Cookie is not present.

getCookies

public static java.util.Map getCookies(javax.servlet.http.HttpServletRequest request)
This method will return a Map of all cookies in the request.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
Map of all cookies.

generateGUID

public static java.lang.String generateGUID(javax.servlet.http.HttpServletRequest request)
Returns a 32 character string uniquely identifying the given request object.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
Map of all cookies.

getBodyContent

public static java.lang.String getBodyContent(javax.servlet.http.HttpServletRequest request)
                                       throws java.io.IOException
This method will return the body content of an HTTP request as a String.

Parameters:
request - A valid HTTPServletRequest object.
Returns:
A String containing the body content of the request.
Throws:
java.io.IOException - Catch-all exception.


Copyright 2005 Frank W. Zammetti