com.continuuity.http
Class InternalHttpResponder

java.lang.Object
  extended by com.continuuity.http.InternalHttpResponder
All Implemented Interfaces:
HttpResponder

public class InternalHttpResponder
extends Object
implements HttpResponder

InternalHttpResponder is used when a handler is being called internally by some other handler, and thus there is no need to go through the network. It stores the status code and content in memory and returns them when asked.


Constructor Summary
InternalHttpResponder()
           
 
Method Summary
 InternalHttpResponse getResponse()
           
 void sendByteArray(org.jboss.netty.handler.codec.http.HttpResponseStatus status, byte[] bytes, com.google.common.collect.Multimap<String,String> headers)
          Send a response containing raw bytes.
 void sendBytes(org.jboss.netty.handler.codec.http.HttpResponseStatus status, ByteBuffer buffer, com.google.common.collect.Multimap<String,String> headers)
          Sends a response containing raw bytes.
 void sendChunk(org.jboss.netty.buffer.ChannelBuffer content)
          Add a chunk of data to the response.
 void sendChunkEnd()
          Called after all chunks are done.
 void sendChunkStart(org.jboss.netty.handler.codec.http.HttpResponseStatus status, com.google.common.collect.Multimap<String,String> headers)
          Respond to the client saying the response will be in chunks.
 void sendContent(org.jboss.netty.handler.codec.http.HttpResponseStatus status, org.jboss.netty.buffer.ChannelBuffer content, String contentType, com.google.common.collect.Multimap<String,String> headers)
          Send response back to client.
 void sendError(org.jboss.netty.handler.codec.http.HttpResponseStatus status, String errorMessage)
          Sends error message back to the client.
 void sendFile(File file, com.google.common.collect.Multimap<String,String> headers)
          Sends a file content back to client.
 void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status, Object object)
          Sends json response back to the client.
 void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status, Object object, Type type)
          Sends json response back to the client.
 void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status, Object object, Type type, com.google.gson.Gson gson)
          Sends json response back to the client using the given gson object.
 void sendStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus status)
          Send only a status code back to client without any content.
 void sendStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus status, com.google.common.collect.Multimap<String,String> headers)
          Send only a status code back to client without any content.
 void sendString(org.jboss.netty.handler.codec.http.HttpResponseStatus status, String data)
          Send a string response back to the http client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InternalHttpResponder

public InternalHttpResponder()
Method Detail

sendJson

public void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                     Object object)
Description copied from interface: HttpResponder
Sends json response back to the client.

Specified by:
sendJson in interface HttpResponder
Parameters:
status - Status of the response.
object - Object that will be serialized into Json and sent back as content.

sendJson

public void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                     Object object,
                     Type type)
Description copied from interface: HttpResponder
Sends json response back to the client.

Specified by:
sendJson in interface HttpResponder
Parameters:
status - Status of the response.
object - Object that will be serialized into Json and sent back as content.
type - Type of object.

sendJson

public void sendJson(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                     Object object,
                     Type type,
                     com.google.gson.Gson gson)
Description copied from interface: HttpResponder
Sends json response back to the client using the given gson object.

Specified by:
sendJson in interface HttpResponder
Parameters:
status - Status of the response.
object - Object that will be serialized into Json and sent back as content.
type - Type of object.
gson - Gson object for serialization.

sendString

public void sendString(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                       String data)
Description copied from interface: HttpResponder
Send a string response back to the http client.

Specified by:
sendString in interface HttpResponder
Parameters:
status - status of the Http response.
data - string data to be sent back.

sendStatus

public void sendStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus status)
Description copied from interface: HttpResponder
Send only a status code back to client without any content.

Specified by:
sendStatus in interface HttpResponder
Parameters:
status - status of the Http response.

sendStatus

public void sendStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                       com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Send only a status code back to client without any content.

Specified by:
sendStatus in interface HttpResponder
Parameters:
status - status of the Http response.
headers - Headers to send.

sendByteArray

public void sendByteArray(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                          byte[] bytes,
                          com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Send a response containing raw bytes. Sets "application/octet-stream" as content type header.

Specified by:
sendByteArray in interface HttpResponder
Parameters:
status - status of the Http response.
bytes - bytes to be sent back.
headers - headers to be sent back. This will overwrite any headers set by the framework.

sendBytes

public void sendBytes(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                      ByteBuffer buffer,
                      com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Sends a response containing raw bytes. Default content type is "application/octet-stream", but can be overridden in the headers.

Specified by:
sendBytes in interface HttpResponder
Parameters:
status - status of the Http response
buffer - bytes to send
headers - Headers to send.

sendError

public void sendError(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                      String errorMessage)
Description copied from interface: HttpResponder
Sends error message back to the client.

Specified by:
sendError in interface HttpResponder
Parameters:
status - Status of the response.
errorMessage - Error message sent back to the client.

sendChunkStart

public void sendChunkStart(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                           com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Respond to the client saying the response will be in chunks. Add chunks to response using HttpResponder.sendChunk(ChannelBuffer) and HttpResponder.sendChunkEnd().

Specified by:
sendChunkStart in interface HttpResponder
Parameters:
status - the status code to respond with. Defaults to 200-OK if null.
headers - additional headers to send with the response. May be null.

sendChunk

public void sendChunk(org.jboss.netty.buffer.ChannelBuffer content)
Description copied from interface: HttpResponder
Add a chunk of data to the response. HttpResponder.sendChunkStart(HttpResponseStatus, Multimap) should be called before calling this method. HttpResponder.sendChunkEnd() should be called after all chunks are done.

Specified by:
sendChunk in interface HttpResponder
Parameters:
content - the chunk of content to send

sendChunkEnd

public void sendChunkEnd()
Description copied from interface: HttpResponder
Called after all chunks are done. This keeps the connection alive unless specified otherwise in the original request.

Specified by:
sendChunkEnd in interface HttpResponder

sendContent

public void sendContent(org.jboss.netty.handler.codec.http.HttpResponseStatus status,
                        org.jboss.netty.buffer.ChannelBuffer content,
                        String contentType,
                        com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Send response back to client.

Specified by:
sendContent in interface HttpResponder
Parameters:
status - Status of the response.
content - Content to be sent back.
contentType - Type of content.
headers - Headers to be sent back.

sendFile

public void sendFile(File file,
                     com.google.common.collect.Multimap<String,String> headers)
Description copied from interface: HttpResponder
Sends a file content back to client.

Specified by:
sendFile in interface HttpResponder

getResponse

public InternalHttpResponse getResponse()


Copyright 2013 Continuuity, Inc. Licensed under the Apache License, Version 2.0