Package spark

Class Response

  • Direct Known Subclasses:
    ResponseWrapper

    public class Response
    extends java.lang.Object
    Provides functionality for modifying the response
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String body  
      private static org.slf4j.Logger LOG
      The logger.
      private javax.servlet.http.HttpServletResponse response  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Response()  
      (package private) Response​(javax.servlet.http.HttpServletResponse response)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String body()
      returns the body
      void body​(java.lang.String body)
      Sets the body
      void cookie​(java.lang.String name, java.lang.String value)
      Adds not persistent cookie to the response.
      void cookie​(java.lang.String name, java.lang.String value, int maxAge)
      Adds cookie to the response.
      void cookie​(java.lang.String name, java.lang.String value, int maxAge, boolean secured)
      Adds cookie to the response.
      void cookie​(java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
      Adds cookie to the response.
      void cookie​(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured)
      Adds cookie to the response.
      void cookie​(java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
      Adds cookie to the response.
      void cookie​(java.lang.String domain, java.lang.String path, java.lang.String name, java.lang.String value, int maxAge, boolean secured, boolean httpOnly)
      Adds cookie to the response.
      void header​(java.lang.String header, int value)
      Adds/Sets a response header
      void header​(java.lang.String header, java.lang.String value)
      Adds/Sets a response header
      void header​(java.lang.String header, java.sql.Date value)
      Adds/Sets a response header
      void header​(java.lang.String header, java.time.Instant value)
      Adds/Sets a response header
      void header​(java.lang.String header, java.util.Date value)
      Adds/Sets a response header
      javax.servlet.http.HttpServletResponse raw()  
      void redirect​(java.lang.String location)
      Trigger a browser redirect
      void redirect​(java.lang.String location, int httpStatusCode)
      Trigger a browser redirect with specific http 3XX status code.
      void removeCookie​(java.lang.String name)
      Removes the cookie.
      void removeCookie​(java.lang.String path, java.lang.String name)
      Removes the cookie with given path and name.
      int status()
      Returns the status code
      void status​(int statusCode)
      Sets the status code for the
      java.lang.String type()
      Returns the content type
      void type​(java.lang.String contentType)
      Sets the content type for the response
      • Methods inherited from class java.lang.Object

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

      • LOG

        private static final org.slf4j.Logger LOG
        The logger.
      • response

        private javax.servlet.http.HttpServletResponse response
      • body

        private java.lang.String body
    • Constructor Detail

      • Response

        protected Response()
      • Response

        Response​(javax.servlet.http.HttpServletResponse response)
    • Method Detail

      • status

        public void status​(int statusCode)
        Sets the status code for the
        Parameters:
        statusCode - the status code
      • status

        public int status()
        Returns the status code
        Returns:
        the status code
      • type

        public void type​(java.lang.String contentType)
        Sets the content type for the response
        Parameters:
        contentType - the content type
      • type

        public java.lang.String type()
        Returns the content type
        Returns:
        the content type
      • body

        public void body​(java.lang.String body)
        Sets the body
        Parameters:
        body - the body
      • body

        public java.lang.String body()
        returns the body
        Returns:
        the body
      • raw

        public javax.servlet.http.HttpServletResponse raw()
        Returns:
        the raw response object handed in by Jetty
      • redirect

        public void redirect​(java.lang.String location)
        Trigger a browser redirect
        Parameters:
        location - Where to redirect
      • redirect

        public void redirect​(java.lang.String location,
                             int httpStatusCode)
        Trigger a browser redirect with specific http 3XX status code.
        Parameters:
        location - Where to redirect permanently
        httpStatusCode - the http status code
      • header

        public void header​(java.lang.String header,
                           java.lang.String value)
        Adds/Sets a response header
        Parameters:
        header - the header
        value - the value
      • header

        public void header​(java.lang.String header,
                           int value)
        Adds/Sets a response header
        Parameters:
        header - the header
        value - the value
      • header

        public void header​(java.lang.String header,
                           java.util.Date value)
        Adds/Sets a response header
        Parameters:
        header - the header
        value - the value
      • header

        public void header​(java.lang.String header,
                           java.sql.Date value)
        Adds/Sets a response header
        Parameters:
        header - the header
        value - the value
      • header

        public void header​(java.lang.String header,
                           java.time.Instant value)
        Adds/Sets a response header
        Parameters:
        header - the header
        value - the value
      • cookie

        public void cookie​(java.lang.String name,
                           java.lang.String value)
        Adds not persistent cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        name - name of the cookie
        value - value of the cookie
      • cookie

        public void cookie​(java.lang.String name,
                           java.lang.String value,
                           int maxAge)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
      • cookie

        public void cookie​(java.lang.String name,
                           java.lang.String value,
                           int maxAge,
                           boolean secured)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
        secured - if true : cookie will be secured
      • cookie

        public void cookie​(java.lang.String name,
                           java.lang.String value,
                           int maxAge,
                           boolean secured,
                           boolean httpOnly)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
        secured - if true : cookie will be secured
        httpOnly - if true: cookie will be marked as http only
      • cookie

        public void cookie​(java.lang.String path,
                           java.lang.String name,
                           java.lang.String value,
                           int maxAge,
                           boolean secured)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        path - path of the cookie
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
        secured - if true : cookie will be secured
      • cookie

        public void cookie​(java.lang.String path,
                           java.lang.String name,
                           java.lang.String value,
                           int maxAge,
                           boolean secured,
                           boolean httpOnly)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        path - path of the cookie
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
        secured - if true : cookie will be secured
        httpOnly - if true: cookie will be marked as http only
      • cookie

        public void cookie​(java.lang.String domain,
                           java.lang.String path,
                           java.lang.String name,
                           java.lang.String value,
                           int maxAge,
                           boolean secured,
                           boolean httpOnly)
        Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
        Parameters:
        domain - domain of the cookie
        path - path of the cookie
        name - name of the cookie
        value - value of the cookie
        maxAge - max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
        secured - if true : cookie will be secured
        httpOnly - if true: cookie will be marked as http only
      • removeCookie

        public void removeCookie​(java.lang.String name)
        Removes the cookie.
        Parameters:
        name - name of the cookie
      • removeCookie

        public void removeCookie​(java.lang.String path,
                                 java.lang.String name)
        Removes the cookie with given path and name.
        Parameters:
        path - path of the cookie
        name - name of the cookie