org.clazzes.util.http
Class RequestHelper

java.lang.Object
  extended by org.clazzes.util.http.RequestHelper

public abstract class RequestHelper
extends Object

Static helper function for extracting special information from requests.


Constructor Summary
RequestHelper()
           
 
Method Summary
static Boolean getBooleanParameter(javax.servlet.http.HttpServletRequest req, String key)
          Get the value of the servlet parameter key and parse it using Boolean.parseBoolean(String) if a value for this servlet parameter has been found.
static Double getDoubleParameter(javax.servlet.http.HttpServletRequest req, String key)
          Get the value of the servlet parameter key and parse it using Double.parseDouble(String) if a value for this servlet parameter has been found.
static Integer getIntegerParameter(javax.servlet.http.HttpServletRequest req, String key)
          Get the value of the servlet parameter key and parse it using Integer.parseInt(String) if a value for this servlet parameter has been found.
static Long getLongParameter(javax.servlet.http.HttpServletRequest req, String key)
          Get the value of the servlet parameter key and parse it using Long.parseLong(String) if a value for this servlet parameter has been found.
static String getRealRemoteIP(javax.servlet.http.HttpServletRequest request)
          Get the remote IP address of the client taking the X-Forwarded-for header into account.
static String getResolvedPath(javax.servlet.http.HttpServletRequest req)
          Get the server-side path which may have been resolved by a delegating servlet.
static void setResolvedPath(javax.servlet.http.HttpServletRequest req, String resolvedPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestHelper

public RequestHelper()
Method Detail

setResolvedPath

public static void setResolvedPath(javax.servlet.http.HttpServletRequest req,
                                   String resolvedPath)
Parameters:
req - The request to inform about path resolution.
resolvedPath - The resolved server-side path to be propagted to a delegate servlet.

getResolvedPath

public static String getResolvedPath(javax.servlet.http.HttpServletRequest req)
Get the server-side path which may have been resolved by a delegating servlet.

Parameters:
req - The request to query.
Returns:
The resolved path stored in the RESOLVED_PATH_ATTR attribute or The result of HttpServletRequest.getPathInfo(), if no such attribute is present.

getRealRemoteIP

public static String getRealRemoteIP(javax.servlet.http.HttpServletRequest request)

Get the remote IP address of the client taking the X-Forwarded-for header into account.

If no X-Forwarded-for header is present, the value of ServletRequest.getRemoteAddr() is returned.

If a X-Forwarded-for header is present, the leftmost value in the comma-separated list of X-Forwarded-for-addresses is returned. The rationale for returning the leftmost address is, that this is the original address of the client.

Parameters:
request - A HTTP servlet request.
Returns:
The remote IP address of the client.

getDoubleParameter

public static Double getDoubleParameter(javax.servlet.http.HttpServletRequest req,
                                        String key)
                                 throws NumberFormatException

Get the value of the servlet parameter key and parse it using Double.parseDouble(String) if a value for this servlet parameter has been found.

Warning: For POST requests with a Content-Type application/x-www-form-urlencoded this method triggers a parsing of the all posted query parameters. To avoid this, use UrlHelper.parseQuery(String) together with UrlHelper.getDoubleParameter(java.util.Map, String).

Parameters:
req - The HTTP servlet request to query.
key - The key of the double parameter to parse.
Returns:
The double value of the request parameter with the given key or null if no request parameter with name key is given.
Throws:
NumberFormatException - If the value of the servlet parameter is not a double value as per Double.parseDouble(String).

getLongParameter

public static Long getLongParameter(javax.servlet.http.HttpServletRequest req,
                                    String key)
                             throws NumberFormatException

Get the value of the servlet parameter key and parse it using Long.parseLong(String) if a value for this servlet parameter has been found.

Warning: For POST requests with a Content-Type application/x-www-form-urlencoded this method triggers a parsing of the all posted query parameters. To avoid this, use UrlHelper.parseQuery(String) together with UrlHelper.getLongParameter(java.util.Map, String).

Parameters:
req - The HTTP servlet request to query.
key - The key of the long parameter to parse.
Returns:
The long value of the request parameter with the given key or null if no request parameter with name key is given.
Throws:
NumberFormatException - If the value of the servlet parameter is not a long value as per Long.parseLong(String).

getIntegerParameter

public static Integer getIntegerParameter(javax.servlet.http.HttpServletRequest req,
                                          String key)
                                   throws NumberFormatException

Get the value of the servlet parameter key and parse it using Integer.parseInt(String) if a value for this servlet parameter has been found.

Warning: For POST requests with a Content-Type application/x-www-form-urlencoded this method triggers a parsing of the all posted query parameters. To avoid this, use UrlHelper.parseQuery(String) together with UrlHelper.getIntegerParameter(java.util.Map, String).

Parameters:
req - The HTTP servlet request to query.
key - The key of the integer parameter to parse.
Returns:
The integer value of the request parameter with the given key or null if no request parameter with name key is given.
Throws:
NumberFormatException - If the value of the servlet parameter is not an integer value as per Integer.parseInt(String).

getBooleanParameter

public static Boolean getBooleanParameter(javax.servlet.http.HttpServletRequest req,
                                          String key)

Get the value of the servlet parameter key and parse it using Boolean.parseBoolean(String) if a value for this servlet parameter has been found.

Warning: For POST requests with a Content-Type application/x-www-form-urlencoded this method triggers a parsing of the all posted query parameters. To avoid this, use UrlHelper.parseQuery(String) together with UrlHelper.getBooleanParameter(java.util.Map, String).

Parameters:
req - The HTTP servlet request to query.
key - The key of the boolean parameter to parse.
Returns:
The boolean value of the request parameter with the given key or null if no request parameter with name key is given.
Throws:
NumberFormatException - If the value of the servlet parameter is not an integer value as per Boolean.parseBoolean(String).


Copyright © 2013. All Rights Reserved.