Class AbstractRequest
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractRequest
-
- All Implemented Interfaces:
Request
- Direct Known Subclasses:
MockRequest
,ServletRequest
public abstract class AbstractRequest extends Object implements Request
This abstract class is intended to support all the various request implementations.- Author:
- Martin Shevchenko
-
-
Constructor Summary
Constructors Constructor Description AbstractRequest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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.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)
If the request parameter is a file attachment, use this method to access the parsedFileItem
.org.apache.commons.fileupload.FileItem[]
getFileItems(String key)
If the request parameter is a file attachment, use this method to access the parsedFileItem
[].String
getParameter(String key)
Returns the value of a request parameter as aString
, ornull
if the parameter does not exist.Enumeration
getParameterNames()
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.boolean
isLogout()
void
logout()
Signal to the servlet that we want to log out (terminate the session).protected static byte[]
readBytes(InputStream stream)
Deprecated.UseStreamUtil.getBytes(java.io.InputStream)
instead.void
setEvent(String actionName, String parameter, Serializable value)
Deprecated.portal specificvoid
setEvent(String action, HashMap<String,Serializable> eventMap)
Deprecated.portal specificprotected static void
uploadFileItems(List fileItems, Map<String,String[]> parameters, Map<String,org.apache.commons.fileupload.FileItem[]> files)
Deprecated.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.Request
getAppSessionAttribute, getAttribute, getFiles, getMaxInactiveInterval, getMethod, getParameters, getRenderParameter, getSessionAttribute, isUserInRole, setAppSessionAttribute, setAttribute, setRenderParameter, setSessionAttribute
-
-
-
-
Method Detail
-
getParameter
public 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
Request.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
.- Specified by:
getParameter
in interfaceRequest
- Parameters:
key
- aString
specifying the key/name of the parameter- Returns:
- a
String
representing the single value of the parameter - See Also:
Request.getParameterValues(java.lang.String)
-
getParameterValues
public 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.
- Specified by:
getParameterValues
in interfaceRequest
- 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:
Request.getParameter(java.lang.String)
-
getFileContents
public byte[] getFileContents(String key)
If the request parameter is a file attachment, use this method to access the content of the attached file.- Specified by:
getFileContents
in interfaceRequest
- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
- the binary data for the uploaded file.
-
getFileItems
public org.apache.commons.fileupload.FileItem[] getFileItems(String key)
If the request parameter is a file attachment, use this method to access the parsedFileItem
[].- Specified by:
getFileItems
in interfaceRequest
- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
FileItem
[] representing the uploaded files.
-
getFileItem
public org.apache.commons.fileupload.FileItem getFileItem(String key)
If the request parameter is a file attachment, use this method to access the parsedFileItem
.- Specified by:
getFileItem
in interfaceRequest
- Parameters:
key
- the name of the parameter used to pass the file content.- Returns:
FileItem
representing the uploaded file.
-
getParameterNames
public Enumeration getParameterNames()
- Specified by:
getParameterNames
in interfaceRequest
- 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
.
-
containsSameData
public boolean containsSameData(Request other)
Indicates whether the given request contains the same set of parameters as this one.- Specified by:
containsSameData
in interfaceRequest
- Parameters:
other
- the request to check.- Returns:
- true if the other request contains the same parameters as this one.
-
getAppPreferenceParameter
public 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.- Specified by:
getAppPreferenceParameter
in interfaceRequest
- Parameters:
key
- the preference parameter key.- Returns:
- the app preference parameter, or null if not found.
-
logout
public 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.- Specified by:
logout
in interfaceRequest
- See Also:
AbstractContainerHelper.redirectForLogout()
-
isLogout
public boolean isLogout()
- Specified by:
isLogout
in interfaceRequest
- Returns:
- true if
Request.logout()
has been called
-
uploadFileItems
@Deprecated protected static void uploadFileItems(List fileItems, Map<String,String[]> parameters, Map<String,org.apache.commons.fileupload.FileItem[]> files)
Deprecated.FileItem
classes (if attachements) will be kept as part of the request. The default behaviour of the file item is to store the upload in memory until it reaches a certain size, after which the content is streamed to a temp file.If, in the future, performance of uploads becomes a focus we can instead look into using the Jakarta Commons Streaming API. In this case, the content of the upload isn't stored anywhere. It will be up to the user to read/store the content of the stream.
- Parameters:
fileItems
- a list ofFileItem
s corresponding to POSTed form data.parameters
- the map to store non-file request parameters in.files
- the map to store the uploaded file parameters in.
-
readBytes
@Deprecated protected static byte[] readBytes(InputStream stream) throws IOException
Deprecated.UseStreamUtil.getBytes(java.io.InputStream)
instead.Returns a byte array containing all the information contained in the given input stream.- Parameters:
stream
- the input stream to read from.- Returns:
- the stream contents as a byte array.
- Throws:
IOException
- if there is an error reading from the stream.
-
setEvent
@Deprecated public void setEvent(String actionName, String parameter, Serializable value)
Deprecated.portal specificThis method contains no logic. Subclasses which need to perform event handling logic (eg.WPortletRequest
) should override this method.
-
setEvent
@Deprecated public void setEvent(String action, HashMap<String,Serializable> eventMap)
Deprecated.portal specificThis method contains no logic. Subclasses which need to perform event handling logic (eg.WPortletRequest
) should override this method.
-
-