Class WebConsoleUtil

  • @Deprecated(since="2021-04-30")
    public final class WebConsoleUtil
    extends Object
    The Apache Felix Webconsole is not supported in Cloud environments.
    The WebConsoleUtil provides various utility methods for use by Web Console plugins.
    • Method Detail

      • getParameter

        public static final String getParameter​(HttpServletRequest request,
                                                String name)
        An utility method, that is used to filter out simple parameter from file parameter when multipart transfer encoding is used. This method processes the request and sets a request attribute AbstractWebConsolePlugin.ATTR_FILEUPLOAD. The attribute value is a Map where the key is a String specifying the field name and the value is a FileItem.
        request - the HTTP request coming from the user
        name - the name of the parameter
        if not multipart transfer encoding is used - the value is the parameter value or null if not set. If multipart is used, and the specified parameter is field - then the value of the parameter is returned.
      • sendRedirect

        public static final void sendRedirect​(HttpServletRequest request,
                                              HttpServletResponse response,
                                              String redirectUrl)
                                       throws IOException
        Utility method to handle relative redirects. Some application servers like Web Sphere handle relative redirects differently therefore we should make an absolute URL before invoking send redirect.
        request - the HTTP request coming from the user
        response - the HTTP response, where data is rendered
        redirectUrl - the redirect URI.
        IOException - If an input or output exception occurs
        IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL
      • setNoCache

        public static final void setNoCache​(HttpServletResponse response)
        Sets response headers to force the client to not cache the response sent back. This method must be called before the response is committed otherwise it will have no effect.

        This method sets the Cache-Control, Expires, and Pragma headers.

        response - The response for which to set the cache prevention
      • escapeHtml

        public static final String escapeHtml​(String text)
        Escapes HTML special chars like: <>&\r\n and space
        text - the text to escape
        the escaped text
      • getParameterInt

        public static final int getParameterInt​(HttpServletRequest request,
                                                String name,
                                                int _default)
        Retrieves a request parameter and converts it to int.
        request - the HTTP request
        name - the name of the request parameter
        _default - the default value returned if the parameter is not set or is not a valid integer.
        the request parameter if set and is valid integer, or the default value
      • urlDecode

        public static String urlDecode​(String value)
        Decode the given value expected to be URL encoded.

        This method first tries to use the Java 1.4 method URLDecoder.decode(String, String) method and falls back to the now deprecated URLDecoder.decode(String, String) which uses the platform character set to decode the string. This is because the platforms before 1.4 and most notably some OSGi Execution Environments (such as Minimum EE) do not provide the newer method.

        value - the value to decode
        the decoded string
      • toString

        public static final String toString​(Object value)
        This method will stringify a Java object. It is mostly used to print the values of unknown properties. This method will correctly handle if the passed object is array and will property display it. If the value is byte[] the elements are shown as Hex
        value - the value to convert
        the string representation of the value