Class 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 Detail

      • AbstractRequest

        public AbstractRequest()
    • Method Detail

      • getParameter

        public String getParameter​(String key)
        Returns the value of a request parameter as a String, or null 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 interface Request
        Parameters:
        key - a String 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 of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

        If the parameter has a single value, the array has a length of 1.

        Specified by:
        getParameterValues in interface Request
        Parameters:
        key - a String 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 interface Request
        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 parsed FileItem[].
        Specified by:
        getFileItems in interface Request
        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 parsed FileItem.
        Specified by:
        getFileItem in interface Request
        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 interface Request
        Returns:
        an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.
      • containsSameData

        public boolean containsSameData​(Request other)
        Indicates whether the given request contains the same set of parameters as this one.
        Specified by:
        containsSameData in interface Request
        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 interface Request
        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 interface Request
        See Also:
        AbstractContainerHelper.redirectForLogout()
      • uploadFileItems

        @Deprecated
        protected static void uploadFileItems​(List fileItems,
                                              Map<String,​String[]> parameters,
                                              Map<String,​org.apache.commons.fileupload.FileItem[]> files)

        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 of FileItems 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
        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 specific
        This method contains no logic. Subclasses which need to perform event handling logic (eg. WPortletRequest) should override this method.
        Specified by:
        setEvent in interface Request
        Parameters:
        actionName - the name of the action that is invoking the event
        parameter - the key of the parameter to store in the eventMap
        value - the value of the parameter to store in the eventMap
        Since:
        1.0.0
      • setEvent

        @Deprecated
        public void setEvent​(String action,
                             HashMap<String,​Serializable> eventMap)
        Deprecated.
        portal specific
        This method contains no logic. Subclasses which need to perform event handling logic (eg. WPortletRequest) should override this method.
        Specified by:
        setEvent in interface Request
        Parameters:
        action - name of the publishing event to trigger
        eventMap - the key/value pair for the event payload
        Since:
        1.0.0