net.officefloor.plugin.socket.server.http.conversation.impl
Class HttpResponseImpl

java.lang.Object
  extended by net.officefloor.plugin.socket.server.http.conversation.impl.HttpResponseImpl
All Implemented Interfaces:
HttpResponse

public class HttpResponseImpl
extends Object
implements HttpResponse

HttpResponse.

Author:
Daniel Sagenschneider

Constructor Summary
HttpResponseImpl(HttpConversationImpl conversation, Connection connection, BufferSquirtFactory squirtFactory, String httpVersion, boolean isCloseConnectionAfterSending)
          Initiate by defaulting from the HttpRequest.
 
Method Summary
 HttpHeader addHeader(String name, String value)
           Adds a HttpHeader for the response.
 OutputBufferStream getBody()
           Obtains the OutputBufferStream to write the body of the response.
 HttpHeader getHeader(String name)
          Obtains the first HttpHeader by the name.
 HttpHeader[] getHeaders()
          Obtains all the HttpHeader instances for the response.
 void removeHeader(HttpHeader header)
          Removes the particular HttpHeader from the response.
 void removeHeaders(String name)
           Removes all HttpHeader instances by the name.
 void send()
          Sends this HttpResponse.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResponseImpl

public HttpResponseImpl(HttpConversationImpl conversation,
                        Connection connection,
                        BufferSquirtFactory squirtFactory,
                        String httpVersion,
                        boolean isCloseConnectionAfterSending)
Initiate by defaulting from the HttpRequest.

Parameters:
conversation - HttpConversationImpl.
connection - Connection.
squirtFactory - BufferSquirtFactory.
httpVersion - HTTP version.
isCloseConnectionAfterSending - Flag indicating to close the Connection when this HttpResponse is sent.
Method Detail

setVersion

public void setVersion(String version)
Description copied from interface: HttpResponse

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.

Specified by:
setVersion in interface HttpResponse
Parameters:
version - HTTP version.

setStatus

public void setStatus(int status)
Description copied from interface: HttpResponse

Specifies the status of the response with the default status message.

This defaults to 200 assuming the request was processed successfully.

Specified by:
setStatus in interface HttpResponse
Parameters:
status - Status of the response.

setStatus

public void setStatus(int status,
                      String statusMessage)
Description copied from interface: HttpResponse
Specifies the status of the response including specifying the status human readable message.

Specified by:
setStatus in interface HttpResponse
Parameters:
status - Status of the response.
statusMessage - Human readable status message.
See Also:
HttpResponse.setStatus(int)

addHeader

public HttpHeader addHeader(String name,
                            String value)
Description copied from interface: HttpResponse

Adds a HttpHeader for the response.

HttpHeader instances are provided on the response in the order they are added.

Specified by:
addHeader in interface HttpResponse
Parameters:
name - Name of HttpHeader.
value - Value of HttpHeader.
Returns:
HttpHeader instance added.

getHeader

public HttpHeader getHeader(String name)
Description copied from interface: HttpResponse
Obtains the first HttpHeader by the name.

Specified by:
getHeader in interface HttpResponse
Parameters:
name - Name of the HttpHeader.
Returns:
First HttpHeader by the name.

getHeaders

public HttpHeader[] getHeaders()
Description copied from interface: HttpResponse
Obtains all the HttpHeader instances for the response.

Specified by:
getHeaders in interface HttpResponse
Returns:
All the HttpHeader instances for the response.

removeHeader

public void removeHeader(HttpHeader header)
Description copied from interface: HttpResponse
Removes the particular HttpHeader from the response.

Specified by:
removeHeader in interface HttpResponse
Parameters:
header - HttpHeader to be removed from the response.

removeHeaders

public void removeHeaders(String name)
Description copied from interface: HttpResponse

Removes all HttpHeader instances by the name.

This method compliments HttpResponse.addHeader(String, String) to allow adding a new single HttpHeader instance by name.

Specified by:
removeHeaders in interface HttpResponse
Parameters:
name - Name of the HttpHeader instances to remove.

getBody

public OutputBufferStream getBody()
Description copied from interface: HttpResponse

Obtains the OutputBufferStream to write the body of the response.

Closing the returned OutputBufferStream is similar to calling HttpResponse.send().

Specified by:
getBody in interface HttpResponse
Returns:
OutputBufferStream to write the body of the response.
See Also:
HttpResponse.send()

send

public void send()
          throws IOException
Description copied from interface: HttpResponse
Sends this HttpResponse. After calling this HttpResponse.getBody() is closed and the corresponding HttpRequest.getBody() is closed.

Specified by:
send in interface HttpResponse
Throws:
IOException - If fails to send this HttpResponse.


Copyright © 2005-2011. All Rights Reserved.