Class HttpResponse
java.lang.Object
com.invirgance.convirgance.web.http.HttpResponse
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 Summary
ConstructorsConstructorDescriptionHttpResponse
(Object response) Creates a new HttpResponse based on the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDateHeader
(String name, long time) Add a date header using the provided name, assigning time to its value.void
Adds a header with the given name and value.void
addIntHeader
(String name, int value) Adds a header with an integer value.void
addLongHeader
(String name, long value) Adds a header with the provided name, assigning the long value.boolean
containsHeader
(String name) Checks if the header with the provided name is set.Gets the header with the provided name.Returns the header names.getHeaders
(String name) An iterable of the values for the header with the given name.Gets the responses value of locale.Gets aOutputStream
to the responses body.int
Gets the status code.void
Sends an the error code with the provided message.void
sendRedirect
(String location) Sends a redirect response with the provided location.void
setContentType
(String name) Updates the content type value.void
setDateHeader
(String name, long time) Sets/overwrites the date header with the provided name.void
Sets/overwrites the header with the given name.void
setIntHeader
(String name, int value) Sets/overwrites the integer headers value.void
Sets the responses locale.void
setLongHeader
(String name, long value) Sets/overwrites the header with the given name.void
setStatus
(int code) Sets the status code of the response.
-
Constructor Details
-
HttpResponse
Creates a new HttpResponse based on the object.- Parameters:
response
- The response.
-
-
Method Details
-
containsHeader
Checks if the header with the provided name is set.- Parameters:
name
- The header name.- Returns:
- True if the object contains name.
-
sendError
Sends an the error code with the provided message.- Parameters:
code
- The error code.message
- The message.
-
sendRedirect
Sends a redirect response with the provided location.- Parameters:
location
- A URL to redirect to.
-
addDateHeader
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
Sets/overwrites the date header with the provided name. Time should be in milliseconds since epoch.- Parameters:
name
- Header name.time
- Milliseconds.
-
addHeader
Adds a header with the given name and value.- Parameters:
name
- Header name.value
- The value for the header.
-
setHeader
Sets/overwrites the header with the given name.- Parameters:
name
- The name.value
- The value.
-
addIntHeader
Adds a header with an integer value.- Parameters:
name
- The name.value
- The int value.
-
setIntHeader
Sets/overwrites the integer headers value.- Parameters:
name
- The name of the header.value
- The new value.
-
addLongHeader
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
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
Gets the header with the provided name.- Parameters:
name
- The header name.- Returns:
- The value of the header.
-
getHeaders
An iterable of the values for the header with the given name.- Parameters:
name
- The header name.- Returns:
- An iterable containing the values
-
getHeaderNames
Returns the header names.- Returns:
- The header names of the response.
-
setContentType
Updates the content type value.- Parameters:
name
- The value for content-type.
-
getOutputStream
Gets aOutputStream
to the responses body.- Returns:
- An output stream to the body.
-
getLocale
Gets the responses value of locale.- Returns:
- The locale
-
setLocale
Sets the responses locale.- Parameters:
locale
- The language locale.
-