Interface Request
-
- All Known Implementing Classes:
AbstractRequest
,MockRequest
,ServletRequest
public interface Request
The interface that the Web framework needs to see from the HttpServletRequest. The support for "session scope" variables should not be used except for communicating between separate WComponent trees (e.g. in separate servlets).The
WServlet
class is the generic servlet that sits between the servlet container and the WComponent framework. The WServlet class is responsible for creating Request objects that represent the incoming HTTP requests, and for dispatching them to the WComponent tree.- Since:
- 1.0.0
- Author:
- James Gifford
- See Also:
WServlet
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description boolean
containsSameData(Request other)
Indicates whether the given request contains the same set of parameters as this one.String
getAppPreferenceParameter(String key)
Gets the parameter for the given key.Serializable
getAppSessionAttribute(String key)
Deprecated.portlet specificSerializable
getAttribute(String key)
Returns the value of the named attribute as anObject
, ornull
if no attribute of the given name exists.byte[]
getFileContents(String key)
If the request parameter is a file attachment, use this method to access the content of the attached file.org.apache.commons.fileupload.FileItem
getFileItem(String key)
Deprecated.As of 25/05/2015, replaced bygetFileItems(java.lang.String)
org.apache.commons.fileupload.FileItem[]
getFileItems(String key)
If the request parameter is a file attachment, use this method to access the parsedFileItem
[].Map<String,org.apache.commons.fileupload.FileItem[]>
getFiles()
Retrieves the files which were uploaded in this request.int
getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.String
getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.String
getParameter(String key)
Returns the value of a request parameter as aString
, ornull
if the parameter does not exist.Enumeration
getParameterNames()
Map<String,String[]>
getParameters()
String[]
getParameterValues(String key)
Returns an array ofString
objects containing all of the values the given request parameter has, ornull
if the parameter does not exist.Serializable
getRenderParameter(String key)
Deprecated.portal specific. usergetSessionAttribute(String)
Serializable
getSessionAttribute(String key)
Returns the object bound with the specified name in this session, ornull
if no object is bound under the name.boolean
isLogout()
boolean
isUserInRole(String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role".void
logout()
Signal to the servlet that we want to log out (terminate the session).void
setAppSessionAttribute(String key, Serializable value)
Deprecated.portlet specificvoid
setAttribute(String key, Serializable value)
Stores an attribute in this request.void
setEvent(String action, String parameter, Serializable value)
Deprecated.portal specificvoid
setEvent(String action, HashMap<String,Serializable> eventMap)
Deprecated.portal specificvoid
setRenderParameter(String key, Serializable value)
Deprecated.portal specific. usersetSessionAttribute(String, Serializable)
void
setSessionAttribute(String key, Serializable value)
Binds an object to this session, using the name specified.
-
-
-
Method Detail
-
getParameter
String getParameter(String key)
Returns the value of a request parameter as aString
, ornull
if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use
getParameterValues(java.lang.String)
.If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by
getParameterValues
.- Parameters:
key
- aString
specifying the key/name of the parameter- Returns:
- a
String
representing the single value of the parameter - See Also:
getParameterValues(java.lang.String)
-
getParameterValues
String[] getParameterValues(String key)
Returns an array ofString
objects containing all of the values the given request parameter has, ornull
if the parameter does not exist.If the parameter has a single value, the array has a length of 1.
- Parameters:
key
- aString
containing the key/name of the parameter whose value is requested- Returns:
- an array of
String
objects containing the parameter's values - See Also:
getParameter(java.lang.String)
-
getFileContents
byte[] getFileContents(String key)
If the request parameter is a file attachment, use this method to access the content of the attached file.- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
- the binary data for the uploaded file.
-
getFileItem
org.apache.commons.fileupload.FileItem getFileItem(String key)
Deprecated.As of 25/05/2015, replaced bygetFileItems(java.lang.String)
If the request parameter is a file attachment, use this method to access the parsedFileItem
.- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
FileItem
representing the uploaded file.- Since:
- 1.0.0
-
getFileItems
org.apache.commons.fileupload.FileItem[] getFileItems(String key)
If the request parameter is a file attachment, use this method to access the parsedFileItem
[].- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
FileItem
[] representing the uploaded files.- Since:
- 1.0.0
-
getParameterNames
Enumeration getParameterNames()
- Returns:
- an
Enumeration
ofString
objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an emptyEnumeration
.
-
getParameters
Map<String,String[]> getParameters()
- Returns:
- the complete list of parameters contained in this request. If the request contains no parameters, the
method returns an empty
Map
.
-
getFiles
Map<String,org.apache.commons.fileupload.FileItem[]> getFiles()
Retrieves the files which were uploaded in this request.- Returns:
- the uploaded files.
-
containsSameData
boolean containsSameData(Request other)
Indicates whether the given request contains the same set of parameters as this one.- Parameters:
other
- the request to check.- Returns:
- true if the other request contains the same parameters as this one.
-
getAttribute
Serializable getAttribute(String key)
Returns the value of the named attribute as an
Object
, ornull
if no attribute of the given name exists.Attributes can be set two ways. The container may set attributes to make available custom information about a request. Attributes can also be set programatically using setAttribute.
- Parameters:
key
- the request attribute key- Returns:
- an
Object
containing the value of the attribute, ornull
if the attribute does not exist
-
setAttribute
void setAttribute(String key, Serializable value)
Stores an attribute in this request. Attributes are reset between requests. If the object passed in is null, the effect is the same as removing the attribute.- Parameters:
key
- the attribute keyvalue
- the attribute value
-
getSessionAttribute
Serializable getSessionAttribute(String key)
Returns the object bound with the specified name in this session, ornull
if no object is bound under the name.- Parameters:
key
- the session attribute key- Returns:
- an
Object
containing the value of the attribute, ornull
if the attribute does not exist
-
getAppSessionAttribute
@Deprecated Serializable getAppSessionAttribute(String key)
Deprecated.portlet specificReturns the object bound with the specified name in the application session, ornull
if no object is bound under the name.This method is relevant for portlets in which case getAppSessionAttribute accesses a portlet scoped session, while getSessionAttribute accesses the global session.
- Parameters:
key
- the session attribute key- Returns:
- an
Object
containing the value of the attribute, ornull
if the attribute does not exist
-
setSessionAttribute
void setSessionAttribute(String key, Serializable value)
Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.If the value passed in is null, this has the same effect as removing the attribute.
- Parameters:
key
- the session attribute key.value
- anObject
containing the value of the attribute.
-
setAppSessionAttribute
@Deprecated void setAppSessionAttribute(String key, Serializable value)
Deprecated.portlet specificBinds an object to the application session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.If the value passed in is null, this has the same effect as removing the attribute.
This method is relevant for portlets in which case getAppSessionAttribute accesses a portlet scoped session, while getSessionAttribute accesses the global session.
- Parameters:
key
- the session attribute key.value
- anObject
containing the value of the attribute.
-
getAppPreferenceParameter
String getAppPreferenceParameter(String key)
Gets the parameter for the given key. If no such parameter is defined, returns null. This method differs from Parameters.getInstance().get(key) in that the value returned may be customised to suit the "app". In a portlet environment an "app" is represented by a portlet.- Parameters:
key
- the preference parameter key.- Returns:
- the app preference parameter, or null if not found.
-
logout
void logout()
Signal to the servlet that we want to log out (terminate the session). The container should react by invalidating the session and redirecting the client to some suitable page.
-
isLogout
boolean isLogout()
- Returns:
- true if
logout()
has been called
-
setEvent
void setEvent(String action, String parameter, Serializable value)
Deprecated.portal specificTriggers the publishing event using thevalue
as the event payload.- Parameters:
action
- name of the publishing event to triggerparameter
- the key for the event payload valuevalue
- the value of the event payload- Since:
- 1.0.0
-
setEvent
void setEvent(String action, HashMap<String,Serializable> eventMap)
Deprecated.portal specificTriggers the publishing event using theeventMap
as the event payload.- Parameters:
action
- name of the publishing event to triggereventMap
- the key/value pair for the event payload- Since:
- 1.0.0
-
setRenderParameter
void setRenderParameter(String key, Serializable value)
Deprecated.portal specific. usersetSessionAttribute(String, Serializable)
Support for Public Render Parameters in Portal. In a Servlet environment, this will be the same as the session.- Parameters:
key
- The key for the parameter.value
- The value of the parameter.- Since:
- 1.0.0
-
getRenderParameter
Serializable getRenderParameter(String key)
Deprecated.portal specific. usergetSessionAttribute(String)
Support for Public Render Parameters in Portal. In a Servlet environment, this will be the same as the session.- Parameters:
key
- The key for the parameter.- Returns:
- The value of the parameter.
- Since:
- 1.0.0
-
isUserInRole
boolean isUserInRole(String role)
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.- 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.
- Since:
- 1.0.0
-
getMethod
String getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.- Returns:
- a
String
specifying the name of the method with which this request was made
-
getMaxInactiveInterval
int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.- Returns:
- an int specifying the maximum inactive interval in seconds. Negative if the session never expires.
-
-