org.apache.tapestry.web
Class ServletWebRequest

java.lang.Object
  extended by org.apache.tapestry.web.ServletWebRequest
All Implemented Interfaces:
Describable, AttributeHolder, WebRequest

public class ServletWebRequest
extends Object
implements WebRequest

Adapter from HttpServletRequest to WebRequest.

Since:
4.0
Author:
Howard M. Lewis Ship

Constructor Summary
ServletWebRequest(HttpServletRequest request, HttpServletResponse response)
           
 
Method Summary
 void describeTo(DescriptionReceiver receiver)
          Invoked to have the receiver describe itself (largely in terms of properties and values).
 void forward(String URL)
          Redirects to the indicated URL.
 String getActivationPath()
          Returns HttpServletRequest.getServletPath().
 Object getAttribute(String name)
          Returns the named object, or null if no attribute has been stored with the given name.
 List getAttributeNames()
          Returns a list of all known attributes in ascending alphabetical order.
 String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 long getDateHeader(String name)
          Returns the value of the specified request header as a long value that represents a Date object.
 String getHeader(String name)
          Returns the value of the specified request header.
 int getIntHeader(String name)
          Returns the value of the specified request header as an int.
 Locale getLocale()
          Returns the preferred locale to which content should be localized, as specified by the client or by the container.
 List getParameterNames()
          Returns the names of all query parameters for this request.
 String getParameterValue(String parameterName)
          Returns a parameter value.
 String[] getParameterValues(String parameterName)
          Returns all parameter values for a particular parameter name.
 String getPathInfo()
          Return any additional path info beyond the servlet path itself.
 String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 String getRequestURI()
          Returns the path portion of the request which triggered this request.
 String getScheme()
          Returns the name of the scheme used to make this request.
 String getServerName()
          Returns the host name of the server that received the request.
 int getServerPort()
          Returns the port number on which this request was received.
 WebSession getSession(boolean create)
          Returns the current WebSessionassociated with this request, possibly creating it if it does not already exist.
 Principal getUserPrincipal()
          Returns a java.security.Principal object containing the name of the current authenticated user.
 boolean isSecure()
          Taken from HttpServletRequest.
 boolean isUserInRole(String role)
          * Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
 void setAttribute(String name, Object attribute)
          Updates the attribute, replacing (or removing) its value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletWebRequest

public ServletWebRequest(HttpServletRequest request,
                         HttpServletResponse response)
Method Detail

getParameterNames

public List getParameterNames()
Description copied from interface: WebRequest
Returns the names of all query parameters for this request. Note that this may return an empty list if an HTML form submission uploads files (with a request encoding of multipart/form-data). Accessing query parameters in such an event requires parsing of the request input stream.

Specified by:
getParameterNames in interface WebRequest
Returns:
List of Strings, in ascending alphabetical order

getParameterValue

public String getParameterValue(String parameterName)
Description copied from interface: WebRequest
Returns a parameter value. If the parameter was submitted with multiple values, then the first submitted value is returned. May return null if no parameter was submitted with the given name.

Specified by:
getParameterValue in interface WebRequest
Parameters:
parameterName - name of parameter to obtain
Returns:
the corresponding value, or null if a value for the parameter was not submitted in the request
See Also:
WebRequest.getParameterValues(String)

getParameterValues

public String[] getParameterValues(String parameterName)
Description copied from interface: WebRequest
Returns all parameter values for a particular parameter name. May return null.

The caller should not modify the returned value.

Specified by:
getParameterValues in interface WebRequest
Parameters:
parameterName - name of parameter to obtain
Returns:
the corresponding values, or null if no values for the parameter were submitted in the request
See Also:
WebRequest.getParameterValue(String)

getContextPath

public String getContextPath()
Description copied from interface: WebRequest
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character.

Specified by:
getContextPath in interface WebRequest
Returns:
The servlet context path.

getSession

public WebSession getSession(boolean create)
Description copied from interface: WebRequest
Returns the current WebSessionassociated with this request, possibly creating it if it does not already exist. If create is false and the request has no valid session, this method returns null. To make sure the session is properly maintained, you must call this method before the response is committed.

Specified by:
getSession in interface WebRequest
Parameters:
create - if true, the session will be created and returned if it does not already exist
Returns:
The session, or null if it does not exist (and create is false)

getAttributeNames

public List getAttributeNames()
Description copied from interface: AttributeHolder
Returns a list of all known attributes in ascending alphabetical order. May be empty (but won't be null).

Specified by:
getAttributeNames in interface AttributeHolder

getAttribute

public Object getAttribute(String name)
Description copied from interface: AttributeHolder
Returns the named object, or null if no attribute has been stored with the given name.

Specified by:
getAttribute in interface AttributeHolder

setAttribute

public void setAttribute(String name,
                         Object attribute)
Description copied from interface: AttributeHolder
Updates the attribute, replacing (or removing) its value. For certain implementations, the attribute may need to be serializable (for example, a WebSession  attribute in a clustered application).

Specified by:
setAttribute in interface AttributeHolder
Parameters:
name - the name of the attribute to update
attribute - the new value for the attribute, or null to delete the attribute entirely.

getScheme

public String getScheme()
Description copied from interface: WebRequest
Returns the name of the scheme used to make this request. For example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

Specified by:
getScheme in interface WebRequest
Returns:
The scheme.

getServerName

public String getServerName()
Description copied from interface: WebRequest
Returns the host name of the server that received the request. Note that behind a firewall, this may be obscured (i.e., it may be the name of the firewall server, which is not necessarily visible to clients outside the firewall).

Specified by:
getServerName in interface WebRequest
Returns:
The name of the server.
See Also:
IRequestDecoder

getServerPort

public int getServerPort()
Description copied from interface: WebRequest
Returns the port number on which this request was received.

Specified by:
getServerPort in interface WebRequest
Returns:
The port number this request is acting on.

getRequestURI

public String getRequestURI()
Description copied from interface: WebRequest
Returns the path portion of the request which triggered this request. Query parameters, scheme, server and port are omitted.

Note: portlets do not know their request URI.

Specified by:
getRequestURI in interface WebRequest
Returns:
The requested URI.

forward

public void forward(String URL)
Description copied from interface: WebRequest
Redirects to the indicated URL. If the URL is local, then a forward occurs. Otherwise, a client side redirect is returned to the client browser.

Specified by:
forward in interface WebRequest
Parameters:
URL - The url to forward the request to.

getActivationPath

public String getActivationPath()
Returns HttpServletRequest.getServletPath().

Specified by:
getActivationPath in interface WebRequest
Returns:
The full servlet path (for servlet requests), or a blank string (for portlet requests).

getPathInfo

public String getPathInfo()
Description copied from interface: WebRequest
Return any additional path info beyond the servlet path itself. Path info, if non-null, begins with a path.

Specified by:
getPathInfo in interface WebRequest
Returns:
path info, or null if no path info

getLocale

public Locale getLocale()
Description copied from interface: WebRequest
Returns the preferred locale to which content should be localized, as specified by the client or by the container. May return null.

Specified by:
getLocale in interface WebRequest
Returns:
The locale associated with the request, may be null.

describeTo

public void describeTo(DescriptionReceiver receiver)
Description copied from interface: Describable
Invoked to have the receiver describe itself (largely in terms of properties and values). If the caller does not invoke any methods on the receiver, then the a default description of the caller will be used (based on toString().

Specified by:
describeTo in interface Describable

getHeader

public String getHeader(String name)
Description copied from interface: WebRequest
Returns the value of the specified request header.

Specified by:
getHeader in interface WebRequest
Parameters:
name - the name of the header to retrieve
Returns:
the header value as a string, or null if the header is not in the request.

getDateHeader

public long getDateHeader(String name)
Description copied from interface: WebRequest
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.

Specified by:
getDateHeader in interface WebRequest
Parameters:
name - a String specifying the name of the header
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 reqest

getIntHeader

public int getIntHeader(String name)
Description copied from interface: WebRequest
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.

Specified by:
getIntHeader in interface WebRequest
Parameters:
name - a String specifying the name of a request header
Returns:
an integer expressing the value of the request header or -1 if the request doesn't have a header of this name

getRemoteUser

public String getRemoteUser()
Description copied from interface: WebRequest
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Specified by:
getRemoteUser in interface WebRequest
Returns:
a String specifying the login of the user making this request, or null if the user login is not known.

getUserPrincipal

public Principal getUserPrincipal()
Description copied from interface: WebRequest
Returns a java.security.Principal object containing the name of the current authenticated user.

Specified by:
getUserPrincipal in interface WebRequest
Returns:
a java.security.Principal containing the name of the user making this request, or null if the user has not been authenticated.

isUserInRole

public boolean isUserInRole(String role)
Description copied from interface: WebRequest
* Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.

Specified by:
isUserInRole in interface WebRequest
Parameters:
role - a String specifying the name of the role
Returns:
a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated.

isSecure

public boolean isSecure()
Description copied from interface: WebRequest
Taken from HttpServletRequest. Indicates if this request is coming in on a SSL/secure connection.

Specified by:
isSecure in interface WebRequest
Returns:
True if secure, false otherwise.


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.