Package spark

Class Response

java.lang.Object
spark.Response
Direct Known Subclasses:
ResponseWrapper

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

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private static final org.slf4j.Logger
    The logger.
    private javax.servlet.http.HttpServletResponse
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    returns the body
    void
    body(String body)
    Sets the body
    void
    cookie(String name, String value)
    Adds not persistent cookie to the response.
    void
    cookie(String name, String value, int maxAge)
    Adds cookie to the response.
    void
    cookie(String name, String value, int maxAge, boolean secured)
    Adds cookie to the response.
    void
    cookie(String name, String value, int maxAge, boolean secured, boolean httpOnly)
    Adds cookie to the response.
    void
    cookie(String path, String name, String value, int maxAge, boolean secured)
    Adds cookie to the response.
    void
    cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly)
    Adds cookie to the response.
    void
    cookie(String domain, String path, String name, String value, int maxAge, boolean secured, boolean httpOnly)
    Adds cookie to the response.
    void
    header(String header, int value)
    Adds/Sets a response header
    void
    header(String header, String value)
    Adds/Sets a response header
    void
    header(String header, Date value)
    Adds/Sets a response header
    void
    header(String header, Instant value)
    Adds/Sets a response header
    void
    header(String header, Date value)
    Adds/Sets a response header
    javax.servlet.http.HttpServletResponse
    raw()
     
    void
    redirect(String location)
    Trigger a browser redirect
    void
    redirect(String location, int httpStatusCode)
    Trigger a browser redirect with specific http 3XX status code.
    void
    Removes the cookie.
    void
    removeCookie(String path, String name)
    Removes the cookie with given path and name.
    int
    Returns the status code
    void
    status(int statusCode)
    Sets the status code for the
    Returns the content type
    void
    type(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 Details

    • LOG

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

      private javax.servlet.http.HttpServletResponse response
    • body

      private String body
  • Constructor Details

    • Response

      protected Response()
    • Response

      Response(javax.servlet.http.HttpServletResponse response)
  • Method Details

    • 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(String contentType)
      Sets the content type for the response
      Parameters:
      contentType - the content type
    • type

      public String type()
      Returns the content type
      Returns:
      the content type
    • body

      public void body(String body)
      Sets the body
      Parameters:
      body - the body
    • body

      public 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(String location)
      Trigger a browser redirect
      Parameters:
      location - Where to redirect
    • redirect

      public void redirect(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(String header, String value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

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

      public void header(String header, Date value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

      public void header(String header, Date value)
      Adds/Sets a response header
      Parameters:
      header - the header
      value - the value
    • header

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

      public void cookie(String name, 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(String name, 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(String name, 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(String name, 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(String path, String name, 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(String path, String name, 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(String domain, String path, String name, 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(String name)
      Removes the cookie.
      Parameters:
      name - name of the cookie
    • removeCookie

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