Class ResponseUtil


  • public final class ResponseUtil
    extends java.lang.Object
    Response util that sets content type and header for various formats and has util methods for setting headers controlling cache.
    Author:
    Jakub Kulaviak
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void setCSVContentType​(javax.servlet.http.HttpServletResponse response)
      Sets comma separated values content type.
      static void setCSVHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets response header and content type for comma separated values output.
      static void setCustomContentType​(javax.servlet.http.HttpServletResponse response, java.lang.String contentType)
      Sets content type to the parameter specified
      static void setCustomTypeHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName, java.lang.String contentType)
      Sets response header and content type for a custom content type.
      static void setFileName​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets the content disposition filename.
      static void setGzippedContentType​(javax.servlet.http.HttpServletResponse response)
      Sets gzip content type ("application/octet-stream")
      static void setGzippedHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets response header and content type for gzipped output.
      static void setHTMLContentType​(javax.servlet.http.HttpServletResponse response)
      Sets HTML content type.
      static void setJSONContentType​(javax.servlet.http.HttpServletResponse response)
      Sets the content type to "application/json"
      static void setJSONHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String filename)
      Sets the response header and content type for json output
      static void setJSONHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String filename, boolean isJSONP)
      Sets the response header and content type for json output
      static void setJSONPContentType​(javax.servlet.http.HttpServletResponse response)
      Sets the content type to "text/javascript"
      static void setJSONPHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String filename)
      Sets the response header and content type for jsonp output
      static void setJSONSchemaContentType​(javax.servlet.http.HttpServletResponse response)
      Sets the content type to "application/schema+json"
      static void setJSONSchemaHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String filename)
      Set the header for a JSON-schema response.
      static void setNoCache​(javax.servlet.http.HttpServletResponse response)
      Sets that the result must not be cached.
      static void setNoCacheEnforced​(javax.servlet.http.HttpServletResponse response)
      Sets enforced no-cache headers to completely disable cache for this response.
      static void setPlainTextContentType​(javax.servlet.http.HttpServletResponse response)
      Sets plain text content type.
      static void setPlainTextHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets response header and content type for plain text output.
      static void setTabContentType​(javax.servlet.http.HttpServletResponse response)
      Sets tab separated values content type.
      static void setTabHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets response header and content type for tab separated values output.
      static void setXMLContentType​(javax.servlet.http.HttpServletResponse response)
      Sets XML content type.
      static void setXMLHeader​(javax.servlet.http.HttpServletResponse response, java.lang.String fileName)
      Sets response header and content type for XML output.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setTabHeader

        public static void setTabHeader​(javax.servlet.http.HttpServletResponse response,
                                        java.lang.String fileName)
        Sets response header and content type for tab separated values output.
        Parameters:
        response - response
        fileName - file name of downloaded file
      • setCSVHeader

        public static void setCSVHeader​(javax.servlet.http.HttpServletResponse response,
                                        java.lang.String fileName)
        Sets response header and content type for comma separated values output.
        Parameters:
        response - response
        fileName - file name of downloaded file
      • setXMLHeader

        public static void setXMLHeader​(javax.servlet.http.HttpServletResponse response,
                                        java.lang.String fileName)
        Sets response header and content type for XML output.
        Parameters:
        response - response
        fileName - file name of downloaded file
      • setPlainTextHeader

        public static void setPlainTextHeader​(javax.servlet.http.HttpServletResponse response,
                                              java.lang.String fileName)
        Sets response header and content type for plain text output.
        Parameters:
        response - response
        fileName - file name of downloaded file
      • setGzippedHeader

        public static void setGzippedHeader​(javax.servlet.http.HttpServletResponse response,
                                            java.lang.String fileName)
        Sets response header and content type for gzipped output.
        Parameters:
        response - response
        fileName - file name of downloaded file
      • setJSONHeader

        public static void setJSONHeader​(javax.servlet.http.HttpServletResponse response,
                                         java.lang.String filename)
        Sets the response header and content type for json output
        Parameters:
        response - The response we are sending into the world
        filename - The filename this response should have
      • setJSONHeader

        public static void setJSONHeader​(javax.servlet.http.HttpServletResponse response,
                                         java.lang.String filename,
                                         boolean isJSONP)
        Sets the response header and content type for json output
        Parameters:
        response - The response we are sending into the world
        filename - The filename this response should have
        isJSONP - Whether this request is being handled as JSONP
      • setJSONSchemaHeader

        public static void setJSONSchemaHeader​(javax.servlet.http.HttpServletResponse response,
                                               java.lang.String filename)
        Set the header for a JSON-schema response.
        Parameters:
        response - The response.
        filename - The file-name.
      • setJSONPHeader

        public static void setJSONPHeader​(javax.servlet.http.HttpServletResponse response,
                                          java.lang.String filename)
        Sets the response header and content type for jsonp output
        Parameters:
        response - Our response to this request
        filename - The name this response should have
      • setCustomTypeHeader

        public static void setCustomTypeHeader​(javax.servlet.http.HttpServletResponse response,
                                               java.lang.String fileName,
                                               java.lang.String contentType)
        Sets response header and content type for a custom content type.
        Parameters:
        response - response
        fileName - file name of downloaded file
        contentType - the content type to use
      • setNoCache

        public static void setNoCache​(javax.servlet.http.HttpServletResponse response)
        Sets that the result must not be cached. Old implementation was set Cache-Control to no-cache,no-store,max-age=0. But this caused problems in IE. File couldn't be opened directly.
        Parameters:
        response - response
      • setNoCacheEnforced

        public static void setNoCacheEnforced​(javax.servlet.http.HttpServletResponse response)
        Sets enforced no-cache headers to completely disable cache for this response. Page is reloaded always, for example when the user uses Go Back button.
        Parameters:
        response - response
      • setTabContentType

        public static void setTabContentType​(javax.servlet.http.HttpServletResponse response)
        Sets tab separated values content type.
        Parameters:
        response - response
      • setCSVContentType

        public static void setCSVContentType​(javax.servlet.http.HttpServletResponse response)
        Sets comma separated values content type.
        Parameters:
        response - response
      • setPlainTextContentType

        public static void setPlainTextContentType​(javax.servlet.http.HttpServletResponse response)
        Sets plain text content type.
        Parameters:
        response - response
      • setXMLContentType

        public static void setXMLContentType​(javax.servlet.http.HttpServletResponse response)
        Sets XML content type.
        Parameters:
        response - response
      • setHTMLContentType

        public static void setHTMLContentType​(javax.servlet.http.HttpServletResponse response)
        Sets HTML content type.
        Parameters:
        response - response
      • setGzippedContentType

        public static void setGzippedContentType​(javax.servlet.http.HttpServletResponse response)
        Sets gzip content type ("application/octet-stream")
        Parameters:
        response - response
      • setCustomContentType

        public static void setCustomContentType​(javax.servlet.http.HttpServletResponse response,
                                                java.lang.String contentType)
        Sets content type to the parameter specified
        Parameters:
        response - response
        contentType - custom MIME type to set as content type specified
      • setFileName

        public static void setFileName​(javax.servlet.http.HttpServletResponse response,
                                       java.lang.String fileName)
        Sets the content disposition filename.
        Parameters:
        response - response
        fileName - the name of the downloaded file
      • setJSONContentType

        public static void setJSONContentType​(javax.servlet.http.HttpServletResponse response)
        Sets the content type to "application/json"
        Parameters:
        response - The response we are sending out into the world
      • setJSONSchemaContentType

        public static void setJSONSchemaContentType​(javax.servlet.http.HttpServletResponse response)
        Sets the content type to "application/schema+json"
        Parameters:
        response - The response we are sending out into the world
      • setJSONPContentType

        public static void setJSONPContentType​(javax.servlet.http.HttpServletResponse response)
        Sets the content type to "text/javascript"
        Parameters:
        response - The response we are sending out into the world