org.webbitserver.wrapper
Class HttpResponseWrapper

java.lang.Object
  extended by org.webbitserver.wrapper.HttpResponseWrapper
All Implemented Interfaces:
HttpResponse

public class HttpResponseWrapper
extends Object
implements HttpResponse


Constructor Summary
HttpResponseWrapper(HttpResponse response)
           
 
Method Summary
 Charset charset()
          Current Charset used to encode to response as.
 HttpResponseWrapper charset(Charset charset)
          For text based responses, sets the Charset to encode the response as.
 boolean containsHeader(String name)
          Test to see if this response has a header of the specified name
 HttpResponseWrapper content(byte[] content)
          Write binary based content back to the client.
 HttpResponseWrapper content(ByteBuffer buffer)
          Write binary based content back to the client.
 HttpResponseWrapper content(String content)
          Write text based content back to the client.
 HttpResponseWrapper cookie(HttpCookie httpCookie)
          Adds a cookie
 HttpResponseWrapper end()
          Marks the response as ended.
 HttpResponseWrapper error(Throwable error)
          Marks the response as erroneous.
 HttpResponseWrapper header(String name, Date value)
          Adds a Date (RFC 1123 format) HTTP header.
 HttpResponseWrapper header(String name, long value)
          Adds a numeric HTTP header.
 HttpResponseWrapper header(String name, String value)
          Adds an HTTP header.
 HttpResponse originalResponse()
           
 int status()
          Retrieve HTTP status code that this response is going to return.
 HttpResponseWrapper status(int status)
          Sets the HTTP status code.
 HttpResponse underlyingResponse()
           
 HttpResponseWrapper underlyingResponse(HttpResponse response)
           
 HttpResponseWrapper write(String content)
          Writes immediately to the client without closing the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResponseWrapper

public HttpResponseWrapper(HttpResponse response)
Method Detail

underlyingResponse

public HttpResponse underlyingResponse()

underlyingResponse

public HttpResponseWrapper underlyingResponse(HttpResponse response)

originalResponse

public HttpResponse originalResponse()

charset

public HttpResponseWrapper charset(Charset charset)
Description copied from interface: HttpResponse
For text based responses, sets the Charset to encode the response as.

If not set, defaults to UTF8.

Specified by:
charset in interface HttpResponse

charset

public Charset charset()
Description copied from interface: HttpResponse
Current Charset used to encode to response as.

Specified by:
charset in interface HttpResponse
See Also:
HttpResponse.charset(Charset)

status

public HttpResponseWrapper status(int status)
Description copied from interface: HttpResponse
Sets the HTTP status code.

Defaults to 200 (OK).

Specified by:
status in interface HttpResponse

status

public int status()
Description copied from interface: HttpResponse
Retrieve HTTP status code that this response is going to return.

Specified by:
status in interface HttpResponse
See Also:
HttpResponse.status(int)

header

public HttpResponseWrapper header(String name,
                                  String value)
Description copied from interface: HttpResponse
Adds an HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

header

public HttpResponseWrapper header(String name,
                                  long value)
Description copied from interface: HttpResponse
Adds a numeric HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

cookie

public HttpResponseWrapper cookie(HttpCookie httpCookie)
Description copied from interface: HttpResponse
Adds a cookie

Specified by:
cookie in interface HttpResponse
Parameters:
httpCookie - the cookie

content

public HttpResponseWrapper content(String content)
Description copied from interface: HttpResponse
Write text based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.charset(Charset), HttpResponse.content(byte[])

write

public HttpResponseWrapper write(String content)
Description copied from interface: HttpResponse
Writes immediately to the client without closing the connection. (The HttpResponse.content(String) method caches content until HttpResponse.end() is called()

TODO: Make content write immediately instead and remove this method?

Specified by:
write in interface HttpResponse
Parameters:
content - what to write

content

public HttpResponseWrapper content(byte[] content)
Description copied from interface: HttpResponse
Write binary based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.content(String)

content

public HttpResponseWrapper content(ByteBuffer buffer)
Description copied from interface: HttpResponse
Write binary based content back to the client.

Specified by:
content in interface HttpResponse
See Also:
HttpResponse.content(String)

error

public HttpResponseWrapper error(Throwable error)
Description copied from interface: HttpResponse
Marks the response as erroneous. The error shall be displayed to the user (500 SERVER ERROR) and the connection closed.

Every response should have either HttpResponse.end() or HttpResponse.error(Throwable) called. No more operations should be performed on a response after these.

Specified by:
error in interface HttpResponse

end

public HttpResponseWrapper end()
Description copied from interface: HttpResponse
Marks the response as ended. At this point any remaining data shall be flushed and the connection closed.

Every response should have either HttpResponse.end() or HttpResponse.error(Throwable) called. No more operations should be performed on a response after these.

Specified by:
end in interface HttpResponse

header

public HttpResponseWrapper header(String name,
                                  Date value)
Description copied from interface: HttpResponse
Adds a Date (RFC 1123 format) HTTP header. Multiple HTTP headers can be added with the same name.

Specified by:
header in interface HttpResponse

containsHeader

public boolean containsHeader(String name)
Description copied from interface: HttpResponse
Test to see if this response has a header of the specified name

Specified by:
containsHeader in interface HttpResponse


Copyright © 2012. All Rights Reserved.