Class HttpResponse

java.lang.Object
com.invirgance.convirgance.web.http.HttpResponse

public class HttpResponse extends Object
Wrapper for HTTP servlet response objects.
 Provides access to common HTTP response elements:
 - Status codes and headers
 - Response body output streams
 - Redirect and error handling
 
Author:
jbanes
  • Constructor Details

    • HttpResponse

      public HttpResponse(Object response)
      Creates a new HttpResponse based on the object.
      Parameters:
      response - The response.
  • Method Details

    • containsHeader

      public boolean containsHeader(String name)
      Checks if the header with the provided name is set.
      Parameters:
      name - The header name.
      Returns:
      True if the object contains name.
    • sendError

      public void sendError(int code, String message)
      Sends an the error code with the provided message.
      Parameters:
      code - The error code.
      message - The message.
    • sendRedirect

      public void sendRedirect(String location)
      Sends a redirect response with the provided location.
      Parameters:
      location - A URL to redirect to.
    • addDateHeader

      public void addDateHeader(String name, long time)
      Add a date header using the provided name, assigning time to its value.
      Parameters:
      name - The header name.
      time - Time as milliseconds from epoch.
    • setDateHeader

      public void setDateHeader(String name, long time)
      Sets/overwrites the date header with the provided name. Time should be in milliseconds since epoch.
      Parameters:
      name - Header name.
      time - Milliseconds.
    • addHeader

      public void addHeader(String name, String value)
      Adds a header with the given name and value.
      Parameters:
      name - Header name.
      value - The value for the header.
    • setHeader

      public void setHeader(String name, String value)
      Sets/overwrites the header with the given name.
      Parameters:
      name - The name.
      value - The value.
    • addIntHeader

      public void addIntHeader(String name, int value)
      Adds a header with an integer value.
      Parameters:
      name - The name.
      value - The int value.
    • setIntHeader

      public void setIntHeader(String name, int value)
      Sets/overwrites the integer headers value.
      Parameters:
      name - The name of the header.
      value - The new value.
    • addLongHeader

      public void addLongHeader(String name, long value)
      Adds a header with the provided name, assigning the long value. The format of the value may change depending on the systems locale.
      Parameters:
      name - The header name.
      value - A long value.
    • setLongHeader

      public void setLongHeader(String name, long value)
      Sets/overwrites the header with the given name. The format of the value may change depending on the systems locale.
      Parameters:
      name - The header name.
      value - The new value to assign.
    • getStatus

      public int getStatus()
      Gets the status code.
      Returns:
      The response status code.
    • setStatus

      public void setStatus(int code)
      Sets the status code of the response.
      Parameters:
      code - The status code.
    • getHeader

      public String getHeader(String name)
      Gets the header with the provided name.
      Parameters:
      name - The header name.
      Returns:
      The value of the header.
    • getHeaders

      public Iterable<String> getHeaders(String name)
      An iterable of the values for the header with the given name.
      Parameters:
      name - The header name.
      Returns:
      An iterable containing the values
    • getHeaderNames

      public Iterable<String> getHeaderNames()
      Returns the header names.
      Returns:
      The header names of the response.
    • setContentType

      public void setContentType(String name)
      Updates the content type value.
      Parameters:
      name - The value for content-type.
    • getOutputStream

      public OutputStream getOutputStream()
      Gets a OutputStream to the responses body.
      Returns:
      An output stream to the body.
    • getLocale

      public Locale getLocale()
      Gets the responses value of locale.
      Returns:
      The locale
    • setLocale

      public void setLocale(Locale locale)
      Sets the responses locale.
      Parameters:
      locale - The language locale.