Class ProcessAwareHttpResponse<B>
- java.lang.Object
-
- net.officefloor.server.http.impl.ProcessAwareHttpResponse<B>
-
- All Implemented Interfaces:
HttpResponse
,CloseHandler
public class ProcessAwareHttpResponse<B> extends java.lang.Object implements HttpResponse, CloseHandler
Serializable
HttpResponse
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description ProcessAwareHttpResponse(ProcessAwareServerHttpConnectionManagedObject<B> serverHttpConnection, HttpVersion version, ManagedObjectContext managedObjectContext)
Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Handles the close.void
flushResponseToHttpResponseWriter(java.lang.Throwable escalation)
Flushes theHttpResponse
to theHttpResponseWriter
.java.nio.charset.Charset
getContentCharset()
Obtains theCharset
for the content.java.lang.String
getContentType()
Obtains theContent-Type
.HttpResponseCookies
getCookies()
Obtains theHttpResponseCookies
.ServerOutputStream
getEntity()
Obtains theServerOutputStream
to write the entity of the response.ServerWriter
getEntityWriter()
Obtains theServerWriter
to write the entity of the response.HttpEscalationHandler
getEscalationHandler()
Obtains theHttpEscalationHandler
.HttpResponseHeaders
getHeaders()
Obtains theHttpResponseHeaders
.HttpStatus
getStatus()
Obtains theHttpStatus
.HttpVersion
getVersion()
Obtains theHttpVersion
.boolean
isClosed()
Indicates if closed.void
reset()
Resets theHttpResponse
by clearingHttpHeader
instances and the entity.void
send()
Sends thisHttpResponse
.void
setContentType(java.lang.String contentType, java.nio.charset.Charset charset)
Specifies theContent-Type
and optionally theCharset
.void
setContentType(HttpHeaderValue contentTypeAndCharsetValue, java.nio.charset.Charset charset)
Provides means to useHttpHeaderValue
to specify both theContent-Type
andcharset
for more efficiency.void
setEscalationHandler(HttpEscalationHandler escalationHandler)
Sets theHttpEscalationHandler
for the response.void
setStatus(HttpStatus status)
Specifies theHttpStatus
.void
setVersion(HttpVersion version)
Override theHttpVersion
.
-
-
-
Constructor Detail
-
ProcessAwareHttpResponse
public ProcessAwareHttpResponse(ProcessAwareServerHttpConnectionManagedObject<B> serverHttpConnection, HttpVersion version, ManagedObjectContext managedObjectContext)
Instantiate.- Parameters:
serverHttpConnection
-ServerHttpConnection
.version
-HttpVersion
.managedObjectContext
-ManagedObjectContext
.
-
-
Method Detail
-
flushResponseToHttpResponseWriter
public void flushResponseToHttpResponseWriter(java.lang.Throwable escalation) throws java.io.IOException
Flushes theHttpResponse
to theHttpResponseWriter
.- Parameters:
escalation
- Possible escalation in servicing. Will benull
if successful.- Throws:
java.io.IOException
- If fails to flushHttpResponse
to theHttpResponseWriter
.
-
getVersion
public HttpVersion getVersion()
Description copied from interface:HttpResponse
Obtains theHttpVersion
.- Specified by:
getVersion
in interfaceHttpResponse
- Returns:
HttpVersion
.
-
setVersion
public void setVersion(HttpVersion version)
Description copied from interface:HttpResponse
Override the
HttpVersion
.This defaults to value on
HttpRequest
.- Specified by:
setVersion
in interfaceHttpResponse
- Parameters:
version
-HttpVersion
.
-
getStatus
public HttpStatus getStatus()
Description copied from interface:HttpResponse
Obtains the
HttpStatus
.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.
- Specified by:
getStatus
in interfaceHttpResponse
- Returns:
- Current
HttpStatus
.
-
setStatus
public void setStatus(HttpStatus status)
Description copied from interface:HttpResponse
Specifies the
HttpStatus
.This defaults to
HttpStatus.OK
assuming the request was processed successfully.- Specified by:
setStatus
in interfaceHttpResponse
- Parameters:
status
-HttpStatus
.
-
getHeaders
public HttpResponseHeaders getHeaders()
Description copied from interface:HttpResponse
Obtains theHttpResponseHeaders
.- Specified by:
getHeaders
in interfaceHttpResponse
- Returns:
HttpResponseHeaders
.
-
getCookies
public HttpResponseCookies getCookies()
Description copied from interface:HttpResponse
Obtains theHttpResponseCookies
.- Specified by:
getCookies
in interfaceHttpResponse
- Returns:
HttpResponseCookies
.
-
setContentType
public void setContentType(java.lang.String contentType, java.nio.charset.Charset charset) throws java.io.IOException
Description copied from interface:HttpResponse
Specifies the
Content-Type
and optionally theCharset
. Thecharset
parameter will automatically be added to theContent-Type
on using theHttpResponse.getEntityWriter()
.This must be specified before calling
HttpResponse.getEntityWriter()
.- Specified by:
setContentType
in interfaceHttpResponse
- Parameters:
contentType
-Content-Type
. May benull
to unset theContent-Type
.charset
-Charset
for theContent-Type
. This may benull
to use the defaultCharset
. Also usenull
forContent-Type
s that do not require character encoding (including the default HTTP content encoding).- Throws:
java.io.IOException
- If attempting to specify after callingHttpResponse.getEntityWriter()
.
-
setContentType
public void setContentType(HttpHeaderValue contentTypeAndCharsetValue, java.nio.charset.Charset charset) throws java.io.IOException
Description copied from interface:HttpResponse
Provides means to use
HttpHeaderValue
to specify both theContent-Type
andcharset
for more efficiency.Note that
HttpHeaderValue
will require the inclusion of thecharset
, as thecharset
will not be appended.- Specified by:
setContentType
in interfaceHttpResponse
- Parameters:
contentTypeAndCharsetValue
-HttpHeaderValue
for theContent-Type
andcharset
.charset
-Charset
to configure theServerWriter
.- Throws:
java.io.IOException
- If attempting to specify after callingHttpResponse.getEntityWriter()
.
-
getContentType
public java.lang.String getContentType()
Description copied from interface:HttpResponse
Obtains theContent-Type
.- Specified by:
getContentType
in interfaceHttpResponse
- Returns:
Content-Type
. May benull
if noContent-Type
has been specified.
-
getContentCharset
public java.nio.charset.Charset getContentCharset()
Description copied from interface:HttpResponse
Obtains the
Charset
for the content.If no
Charset
has been specified, the defaultCharset
will be returned.- Specified by:
getContentCharset
in interfaceHttpResponse
- Returns:
Charset
.
-
getEntity
public ServerOutputStream getEntity() throws java.io.IOException
Description copied from interface:HttpResponse
Obtains the
ServerOutputStream
to write the entity of the response.Only one of
HttpResponse.getEntity()
orHttpResponse.getEntityWriter()
may be called.Closing the returned
ServerOutputStream
is similar to callingHttpResponse.send()
.- Specified by:
getEntity
in interfaceHttpResponse
- Returns:
ServerOutputStream
to write the entity of the response.- Throws:
java.io.IOException
- ShouldHttpResponse.getEntityWriter()
already be provided.- See Also:
HttpResponse.getEntityWriter()
,HttpResponse.send()
-
getEntityWriter
public ServerWriter getEntityWriter() throws java.io.IOException
Description copied from interface:HttpResponse
Obtains the
ServerWriter
to write the entity of the response.Only one of
HttpResponse.getEntity()
orHttpResponse.getEntityWriter()
may be called.Closing the returned
ServerOutputStream
is similar to callingHttpResponse.send()
.- Specified by:
getEntityWriter
in interfaceHttpResponse
- Returns:
ServerWriter
to write the entity of the response.- Throws:
java.io.IOException
- ShouldHttpResponse.getEntity()
already be provided.- See Also:
HttpResponse.getEntity()
,HttpResponse.send()
-
getEscalationHandler
public HttpEscalationHandler getEscalationHandler()
Description copied from interface:HttpResponse
Obtains theHttpEscalationHandler
.- Specified by:
getEscalationHandler
in interfaceHttpResponse
- Returns:
HttpEscalationHandler
ornull
if noHttpEscalationHandler
configured.
-
setEscalationHandler
public void setEscalationHandler(HttpEscalationHandler escalationHandler)
Description copied from interface:HttpResponse
Sets theHttpEscalationHandler
for the response.- Specified by:
setEscalationHandler
in interfaceHttpResponse
- Parameters:
escalationHandler
-HttpEscalationHandler
for the response.
-
reset
public void reset() throws java.io.IOException
Description copied from interface:HttpResponse
Resets theHttpResponse
by clearingHttpHeader
instances and the entity.- Specified by:
reset
in interfaceHttpResponse
- Throws:
java.io.IOException
- If committed to send theHttpResponse
.
-
send
public void send() throws java.io.IOException
Description copied from interface:HttpResponse
- Specified by:
send
in interfaceHttpResponse
- Throws:
java.io.IOException
- If fails to send thisHttpResponse
.
-
isClosed
public boolean isClosed()
Description copied from interface:CloseHandler
Indicates if closed.- Specified by:
isClosed
in interfaceCloseHandler
- Returns:
true
if closed.
-
close
public void close() throws java.io.IOException
Description copied from interface:CloseHandler
Handles the close.- Specified by:
close
in interfaceCloseHandler
- Throws:
java.io.IOException
- If fails to close.
-
-