public interface HttpResponse
HttpResponse
for the ServerHttpConnection
.Modifier and Type | Method and Description |
---|---|
HttpHeader |
addHeader(String name,
String value)
Adds a
HttpHeader for the response. |
Charset |
getContentCharset()
Obtains the
Charset for the content. |
String |
getContentType()
Obtains the
Content-Type . |
ServerOutputStream |
getEntity()
Obtains the
ServerOutputStream to write the entity of the
response. |
ServerWriter |
getEntityWriter()
Obtains the
ServerWriter to write the entity of the response. |
HttpHeader |
getHeader(String name)
Obtains the first
HttpHeader by the name. |
HttpHeader[] |
getHeaders()
Obtains all the
HttpHeader instances for the response. |
int |
getStatus()
Obtains the status.
|
String |
getStatusMessage()
Obtains the current status message.
|
String |
getVersion()
Obtains the HTTP version.
|
void |
removeHeader(HttpHeader header)
Removes the particular
HttpHeader from the response. |
void |
removeHeaders(String name)
Removes all
HttpHeader instances by the name. |
void |
reset()
Resets the
HttpResponse by clearing HttpHeader instances
and the entity. |
void |
send()
Sends this
HttpResponse . |
void |
setContentType(String contentType,
Charset charset)
Specifies the
Content-Type and optionally the
Charset . |
void |
setStatus(int status)
Specifies the status of the response with the default status message.
|
void |
setStatus(int status,
String statusMessage)
Specifies the status of the response including specifying the status
human readable message.
|
void |
setVersion(String version)
Allows specifying the HTTP version on the response.
|
void setVersion(String version)
Allows specifying the HTTP version on the response. Values should be either HTTP/1.0 or HTTP/1.1.
This defaults to value on HttpRequest
.
version
- HTTP version.String getVersion()
void setStatus(int status)
Specifies the status of the response with the default status message.
This defaults to 200 assuming the request was processed successfully.
status
- Status of the response.int getStatus()
Obtains the status.
This is the current status. The status may changed based on particular HTTP rules (e.g. 200 becoming 204 due to no entity) or there being a failure in processing the message.
void setStatus(int status, String statusMessage)
status
- Status of the response.statusMessage
- Human readable status message.setStatus(int)
String getStatusMessage()
getStatus()
void reset() throws IOException
HttpResponse
by clearing HttpHeader
instances
and the entity.IOException
- If committed to send the HttpResponse
.HttpHeader addHeader(String name, String value) throws IllegalArgumentException
Adds a HttpHeader
for the response.
HttpHeader
instances are provided on the response in the order
they are added.
name
- Name of HttpHeader
.value
- Value of HttpHeader
.HttpHeader
instance added.IllegalArgumentException
- Should the HttpHeader
be managed by the
HttpResponse
.HttpHeader getHeader(String name)
HttpHeader
by the name.name
- Name of the HttpHeader
.HttpHeader
by the name.HttpHeader[] getHeaders()
HttpHeader
instances for the response.HttpHeader
instances for the response.void removeHeader(HttpHeader header)
HttpHeader
from the response.header
- HttpHeader
to be removed from the response.void removeHeaders(String name)
Removes all HttpHeader
instances by the name.
This method compliments addHeader(String, String)
to allow
adding a new single HttpHeader
instance by name.
name
- Name of the HttpHeader
instances to remove.void setContentType(String contentType, Charset charset) throws IOException
Specifies the Content-Type
and optionally the
Charset
. The charset
parameter will automatically be
added to the Content-Type
on using the
getEntityWriter()
.
This must be specified before calling getEntityWriter()
.
contentType
- Content-Type
. May be null
to unset
the Content-Type
.charset
- Charset
for the Content-Type
. This may be
null
to use the default Charset
. Also use
null
for Content-Type
s that do not
require character encoding.IOException
- If attempting to specify after calling
getEntityWriter()
.String getContentType()
Content-Type
.Content-Type
. May be null
if no
Content-Type
has been specified.Charset getContentCharset()
Obtains the Charset
for the content.
If no Charset
has been specified, the default Charset
will be returned.
Charset
.ServerOutputStream getEntity() throws IOException
Obtains the ServerOutputStream
to write the entity of the
response.
Only one of getEntity()
or getEntityWriter()
may be
called.
Closing the returned ServerOutputStream
is similar to calling
send()
.
ServerOutputStream
to write the entity of the response.IOException
- Should getEntityWriter()
already be provided.getEntityWriter()
,
send()
ServerWriter getEntityWriter() throws IOException
Obtains the ServerWriter
to write the entity of the response.
Only one of getEntity()
or getEntityWriter()
may be
called.
Closing the returned ServerOutputStream
is similar to calling
send()
.
ServerWriter
to write the entity of the response.IOException
- Should getEntity()
already be provided.getEntity()
,
send()
void send() throws IOException
IOException
- If fails to send this HttpResponse
.Copyright © 2005–2016. All rights reserved.