org.melati.util
Class HttpServletRequestCompat

Package class diagram package HttpServletRequestCompat
java.lang.Object
  extended by org.melati.util.HttpServletRequestCompat

public final class HttpServletRequestCompat
extends Object

NOTE This is no longer used, but it is so cool it is still around to marvel at The HttpServletRequestCompat class enables Melati to compile, without warnings, with the Servlet API versions 2.0 to 2.5. The core methods are those present in the 2.0 API all methods added since are established as static members. These are then available to be invoked if present or a RuntimeException is thrown otherwise. However, if you use a method which is not in your version of the API then you will get a runtime exception.

See Also:
DelegatedHttpServletRequest

Nested Class Summary
static class HttpServletRequestCompat.MissingMethodError
          Thrown when a method that is not available is invoked.
 
Method Summary
static Enumeration getAttributeNames(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API.
static String getAuthType(javax.servlet.http.HttpServletRequest it)
          Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.
static String getContextPath(javax.servlet.http.HttpServletRequest it)
          Returns the empty string when run against 2.0 API.
static javax.servlet.http.Cookie[] getCookies(javax.servlet.http.HttpServletRequest it)
          Returns an array containing all of the Cookie objects the client sent with this request.
static long getDateHeader(javax.servlet.http.HttpServletRequest it, String a)
          Returns the value of the specified request header as a long value that represents a Date object.
static String getHeader(javax.servlet.http.HttpServletRequest it, String a)
          Returns the value of the specified request header as a String.
static Enumeration<String> getHeaderNames(javax.servlet.http.HttpServletRequest it)
          Returns an enumeration of all the header names this request contains.
static Enumeration getHeaders(javax.servlet.http.HttpServletRequest it, String arg)
          Throws MissingMethodError when run against 2.0 API.
static int getIntHeader(javax.servlet.http.HttpServletRequest it, String a)
          Returns the value of the specified request header as an int.
static String getLocalAddr(javax.servlet.http.HttpServletRequest it)
           
static Locale getLocale(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API.
static Enumeration getLocales(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API.
static String getLocalName(javax.servlet.http.HttpServletRequest it)
           
static int getLocalPort(javax.servlet.http.HttpServletRequest it)
           
static String getMethod(javax.servlet.http.HttpServletRequest it)
           
static Map getParameterMap(javax.servlet.http.HttpServletRequest it)
           
static String getPathInfo(javax.servlet.http.HttpServletRequest it)
           
static String getPathTranslated(javax.servlet.http.HttpServletRequest it)
           
static String getQueryString(javax.servlet.http.HttpServletRequest it)
           
static String getRealPath(javax.servlet.http.HttpServletRequest it, String arg)
          Deprecated. Servlet API 2.1
static int getRemotePort(javax.servlet.http.HttpServletRequest it)
           
static String getRemoteUser(javax.servlet.http.HttpServletRequest it)
           
static javax.servlet.RequestDispatcher getRequestDispatcher(javax.servlet.http.HttpServletRequest it, String arg)
          Throws MissingMethodError when run against 2.0 API.
static String getRequestedSessionId(javax.servlet.http.HttpServletRequest it)
           
static String getRequestURI(javax.servlet.http.HttpServletRequest it)
           
static StringBuffer getRequestURL(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.2 API.
static String getServletPath(javax.servlet.http.HttpServletRequest it)
           
static javax.servlet.http.HttpSession getSession(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API, introduced in 2.1.
static javax.servlet.http.HttpSession getSession(javax.servlet.http.HttpServletRequest it, boolean a)
           
static Principal getUserPrincipal(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API.
static boolean isRequestedSessionIdFromCookie(javax.servlet.http.HttpServletRequest it)
           
static boolean isRequestedSessionIdFromUrl(javax.servlet.http.HttpServletRequest it)
          Deprecated. Servlet API 2.1
static boolean isRequestedSessionIdFromURL(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API, introduced in 2.1.
static boolean isRequestedSessionIdValid(javax.servlet.http.HttpServletRequest it)
           
static boolean isSecure(javax.servlet.http.HttpServletRequest it)
          Throws MissingMethodError when run against 2.0 API.
static boolean isUserInRole(javax.servlet.http.HttpServletRequest it, String arg)
          Throws MissingMethodError when run against 2.0 API.
static void removeAttribute(javax.servlet.http.HttpServletRequest it, String arg)
          Throws MissingMethodError when run against 2.0 API.
static void setAttribute(javax.servlet.http.HttpServletRequest it, String arg1, Object arg2)
          Throws MissingMethodError when run against 2.0 API.
static void setCharacterEncoding(javax.servlet.http.HttpServletRequest it, String arg)
          Throws MissingMethodError when run against 2.2 API.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAuthType

public static String getAuthType(javax.servlet.http.HttpServletRequest it)
Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.

Same as the value of the CGI variable AUTH_TYPE.

Parameters:
it - the HttpServletRequest
Returns:
a String specifying the name of the authentication scheme, or null if the request was not authenticated
Since:
2.0
See Also:
HttpServletRequest.getAuthType()

getCookies

public static javax.servlet.http.Cookie[] getCookies(javax.servlet.http.HttpServletRequest it)
Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies were sent.

Parameters:
it - the HttpServletRequest
Returns:
an array of all the Cookies included with this request, or null if the request has no cookies
Since:
2.0
See Also:
HttpServletRequest.getCookies()

getDateHeader

public static long getDateHeader(javax.servlet.http.HttpServletRequest it,
                                 String a)
Returns the value of the specified request header as a long value that represents a Date object. Use this method with headers that contain dates, such as If-Modified-Since.

The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

Parameters:
it - the HttpServletRequest
Returns:
a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request
Since:
2.0
See Also:
HttpServletRequest.getDateHeader(String)

getHeader

public static String getHeader(javax.servlet.http.HttpServletRequest it,
                               String a)
Returns the value of the specified request header as a String. If the request did not include a header of the specified name, this method returns null. The header name is case insensitive. You can use this method with any request header.

Parameters:
it - the HttpServletRequest
Returns:
a String containing the value of the requested header, or null if the request does not have a header of that name
Since:
2.0
See Also:
HttpServletRequest.getHeader(String)

getHeaderNames

public static Enumeration<String> getHeaderNames(javax.servlet.http.HttpServletRequest it)
Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration.

Some servlet containers do not allow do not allow servlets to access headers using this method, in which case this method returns null

Parameters:
it - the HttpServletRequest
Returns:
an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the servlet container does not allow servlets to use this method, null
Since:
2.0
See Also:
HttpServletRequest.getHeaderNames()

getIntHeader

public static int getIntHeader(javax.servlet.http.HttpServletRequest it,
                               String a)
Returns the value of the specified request header as an int. If the request does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws a NumberFormatException.

The header name is case insensitive.

Parameters:
it - the HttpServletRequest
Returns:
an integer expressing the value of the request header or -1 if the request doesn't have a header of this name
Since:
2.0
See Also:
HttpServletRequest.getIntHeader(String)

getMethod

public static String getMethod(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String specifying the name of the method with which this request was made
Since:
2.0
See Also:
HttpServletRequest.getMethod()

getPathInfo

public static String getPathInfo(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String specifying extra path information that comes after the servlet path but before the query string in the request URL; or null if the URL does not have any extra path information
Since:
2.0
See Also:
HttpServletRequest.getPathInfo()

getPathTranslated

public static String getPathTranslated(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String specifying the real path, or null if the URL does not have any extra path information
Since:
2.0
See Also:
HttpServletRequest.getPathTranslated()

getQueryString

public static String getQueryString(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String containing the query string or null if the URL contains no query string
Since:
2.0
See Also:
HttpServletRequest.getQueryString()

getRemoteUser

public static String getRemoteUser(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String specifying the login of the user making this request, or null if the user login is not known
Since:
2.0
See Also:
HttpServletRequest.getRemoteUser()

getRequestURI

public static String getRequestURI(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String containing the part of the URL from the protocol name up to the query string
Since:
2.0
See Also:
HttpServletRequest.getRequestURI()

getRequestedSessionId

public static String getRequestedSessionId(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String specifying the session ID, or null if the request did not specify a session ID
Since:
2.0
See Also:
HttpServletRequest.getRequestedSessionId()

getServletPath

public static String getServletPath(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
a String containing the name or path of the servlet being called, as specified in the request URL
Since:
2.0
See Also:
HttpServletRequest.getServletPath()

getSession

public static javax.servlet.http.HttpSession getSession(javax.servlet.http.HttpServletRequest it,
                                                        boolean a)
Parameters:
it - the HttpServletRequest
a -
Returns:
the HttpSession associated with this request
Since:
2.0
See Also:
HttpServletRequest.getSession()

isRequestedSessionIdValid

public static boolean isRequestedSessionIdValid(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
true if this request has an id for a valid session in the current session context; false otherwise
Since:
2.0
See Also:
HttpServletRequest.isRequestedSessionIdValid()

isRequestedSessionIdFromCookie

public static boolean isRequestedSessionIdFromCookie(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
true if the session ID came in as a cookie; otherwise, false
Since:
2.0
See Also:
HttpServletRequest.isRequestedSessionIdFromCookie()

getRealPath

public static String getRealPath(javax.servlet.http.HttpServletRequest it,
                                 String arg)
Deprecated. Servlet API 2.1

Parameters:
it - the HttpServletRequest
arg - url String
Returns:
the real path
Since:
2.0
See Also:
ServletRequest.getRealPath(String)

isRequestedSessionIdFromUrl

public static boolean isRequestedSessionIdFromUrl(javax.servlet.http.HttpServletRequest it)
Deprecated. Servlet API 2.1

Parameters:
it - the HttpServletRequest
Returns:
whether id is from url
Since:
2.0
See Also:
HttpServletRequest.isRequestedSessionIdFromUrl()

getContextPath

public static String getContextPath(javax.servlet.http.HttpServletRequest it)
Returns the empty string when run against 2.0 API.

Parameters:
it - the HttpServletRequest
Returns:
the Context path or empty string
Since:
2.1
See Also:
HttpServletRequest.getContextPath()

getUserPrincipal

public static Principal getUserPrincipal(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API.

Parameters:
it - the HttpServletRequest
Returns:
a java.security.Principal containing the name of the user making this request; null if the user has not been authenticated
Since:
2.1
See Also:
HttpServletRequest.getUserPrincipal()

getHeaders

public static Enumeration getHeaders(javax.servlet.http.HttpServletRequest it,
                                     String arg)
Throws MissingMethodError when run against 2.0 API.

Parameters:
it - the HttpServletRequest
arg -
Returns:
a Enumeration containing the values of the requested header, or null if the request does not have any headers of that name
Since:
2.1
See Also:
HttpServletRequest.getHeaders(java.lang.String)

getSession

public static javax.servlet.http.HttpSession getSession(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API, introduced in 2.1.

Parameters:
it - the HttpServletRequest
Returns:
the HttpSession associated with this request
Since:
2.1
See Also:
HttpServletRequest.getSession()

isRequestedSessionIdFromURL

public static boolean isRequestedSessionIdFromURL(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API, introduced in 2.1.

Parameters:
it - the HttpServletRequest
Returns:
true if the session ID came in as part of a URL; otherwise, false
Since:
2.1
See Also:
HttpServletRequest.isRequestedSessionIdFromURL()

isUserInRole

public static boolean isUserInRole(javax.servlet.http.HttpServletRequest it,
                                   String arg)
Throws MissingMethodError when run against 2.0 API.

Parameters:
it - the HttpServletRequest
arg -
Returns:
a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated
Since:
2.2
See Also:
HttpServletRequest.isUserInRole(java.lang.String)

getAttributeNames

public static Enumeration getAttributeNames(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API. Returns an Enumeration containing the names of the attributes available to this request. This method returns an empty Enumeration if the request has no attributes available to it.

Parameters:
it - the HttpServletRequest
Returns:
an Enumeration of strings containing the names of the request's attributes
Since:
2.2
See Also:
ServletRequest.getAttributeNames()

getLocale

public static Locale getLocale(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API. Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

Parameters:
it - the HttpServletRequest
Returns:
the preferred Locale for the client
Since:
2.2
See Also:
ServletRequest.getLocale()

getLocales

public static Enumeration getLocales(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API. Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.

Parameters:
it - the HttpServletRequest
Returns:
an Enumeration of preferred Locale objects for the client
Since:
2.2
See Also:
ServletRequest.getLocales()

getRequestDispatcher

public static javax.servlet.RequestDispatcher getRequestDispatcher(javax.servlet.http.HttpServletRequest it,
                                                                   String arg)
Throws MissingMethodError when run against 2.0 API. If you get compile errors for this method, it's probably because (a) you are compiling against the 2.0 servlet API. Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static. The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher. The difference between this method and ServletContext#getRequestDispatcher is that this method can take a relative path.

Parameters:
it - the HttpServletRequest
arg - a String specifying the pathname to the resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path
Since:
2.2
See Also:
RequestDispatcher, ServletRequest.getRequestDispatcher(String)

isSecure

public static boolean isSecure(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.0 API. Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Parameters:
it - the HttpServletRequest
Returns:
a boolean indicating if the request was made using a secure channel
Since:
2.2
See Also:
ServletRequest.isSecure()

removeAttribute

public static void removeAttribute(javax.servlet.http.HttpServletRequest it,
                                   String arg)
Throws MissingMethodError when run against 2.0 API. Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.

Attribute names should follow the same conventions as package names. Names beginning with java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems.

Parameters:
it - the HttpServletRequest
arg - a String specifying the name of the attribute to remove
Since:
2.2
See Also:
javax.servlet.http.HttpServletRequest#removeAttribute()

setAttribute

public static void setAttribute(javax.servlet.http.HttpServletRequest it,
                                String arg1,
                                Object arg2)
Throws MissingMethodError when run against 2.0 API. Stores an attribute in this request. Attributes are reset between requests. This method is most often used in conjunction with RequestDispatcher.

Attribute names should follow the same conventions as package names. Names beginning with java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems.

Parameters:
it - the HttpServletRequest
arg1 - a String specifying the name of the attribute
arg2 - the Object to be stored
Since:
2.2
See Also:
ServletRequest.setAttribute(java.lang.String, java.lang.Object)

getRequestURL

public static StringBuffer getRequestURL(javax.servlet.http.HttpServletRequest it)
Throws MissingMethodError when run against 2.2 API.

Parameters:
it - the HttpServletRequest
Returns:
request url as a String buffer
Since:
2.3
See Also:
HttpServletRequest.getRequestURL()

setCharacterEncoding

public static void setCharacterEncoding(javax.servlet.http.HttpServletRequest it,
                                        String arg)
Throws MissingMethodError when run against 2.2 API.

Parameters:
it - the HttpServletRequest
arg - encoding name
Since:
2.3
See Also:
ServletRequest.setCharacterEncoding(String)

getParameterMap

public static Map getParameterMap(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
map of parameters
Since:
2.3
See Also:
ServletRequest.getParameterMap()

getRemotePort

public static int getRemotePort(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
the remote address
See Also:
ServletRequest.getRemotePort()

getLocalPort

public static int getLocalPort(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
the receiving local port
See Also:
ServletRequest.getLocalPort()

getLocalName

public static String getLocalName(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
the local host name
See Also:
ServletRequest.getLocalName()

getLocalAddr

public static String getLocalAddr(javax.servlet.http.HttpServletRequest it)
Parameters:
it - the HttpServletRequest
Returns:
the receiving, local, IP address
See Also:
ServletRequest.getLocalAddr()


Copyright © 2000-2010 PanEris. All Rights Reserved.