org.elkoserver.foundation.actor
Class JSONHTTPFramer

java.lang.Object
  extended by org.elkoserver.foundation.net.HTTPFramer
      extended by org.elkoserver.foundation.actor.JSONHTTPFramer

public class JSONHTTPFramer
extends HTTPFramer

HTTP message framer for JSON messages transported via HTTP.

This class treats the content of each HTTP POST to the /xmit/ URL as a bundle of one or more JSON messages to be handled.


Constructor Summary
JSONHTTPFramer(Trace appTrace)
          Constructor.
 
Method Summary
 String makeSelectReplySegment(Object message, int seqNumber, boolean start, boolean end)
          Produce the HTTP for responding to an HTTP GET of the /select/ URL by sending a message to the client.
 Iterator postBodyUnpacker(String body)
          Get an iterator that can extract the JSON message or messages (if any) from the body of an HTTP message.
 
Methods inherited from class org.elkoserver.foundation.net.HTTPFramer
makeBadURLReply, makeConnectReply, makeDisconnectReply, makeSequenceErrorReply, makeXmitReply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONHTTPFramer

public JSONHTTPFramer(Trace appTrace)
Constructor.

Method Detail

makeSelectReplySegment

public String makeSelectReplySegment(Object message,
                                     int seqNumber,
                                     boolean start,
                                     boolean end)
Produce the HTTP for responding to an HTTP GET of the /select/ URL by sending a message to the client.

The actual HTTP reply body sent is constructed by concatenating the results of one or more coordinated calls to this method, one call for each message that is to be sent. In the first of these calls, the 'start' flag must be true. In the last, the 'end' flag must be true. (If only one message is being sent, this method should be called exactly once with both 'start' and 'end' set to true.)

Overrides:
makeSelectReplySegment in class HTTPFramer
Parameters:
message - The message to be sent.
seqNumber - The sequence number for the next select request.
start - true if this message is the first in a batch of messages.
end - true if this message is the last in a batch of messages.
Returns:
an appropriate HTTP reply body string for responding to a /select/ GET, delivering 'message' to the client.

postBodyUnpacker

public Iterator postBodyUnpacker(String body)
Get an iterator that can extract the JSON message or messages (if any) from the body of an HTTP message.

Overrides:
postBodyUnpacker in class HTTPFramer
Parameters:
body - The HTTP message body in question.
Returns:
an iterator that can be called upon to return the JSON message(s) contained within 'body'.