com.faunos.util.net.http
Class RequestStage

java.lang.Object
  extended by com.faunos.util.net.http.RequestStage
All Implemented Interfaces:
Handlet, RequestHeader, Stagelet

public class RequestStage
extends Object
implements Stagelet, RequestHeader

The first stage in the implementation of HTTP. This class reads the HTTP request headers, and dispatches the processing to the next stage.

Author:
Babak Farhang
See Also:
ResponseFactory

Constructor Summary
RequestStage(StageletStack stack, ResponseFactory responseFactory)
           
RequestStage(StageletStack stack, ResponseFactory responseFactory, long maxHeaderSize)
           
 
Method Summary
 void discard()
          Discards the instance.
 Map<String,String> getProperties()
          Returns a name/value map encapsulating the HTTP request headers received.
 String getUri()
          Returns the URI referenced in the first line of the HTTP request.
 Verb getVerb()
          Returns the HTTP verb.
 String getVersion()
          Returns the HTTP version string in the first line of the HTTP request.
 IoState init(HandletContext context)
          Initializes the handlet.
 boolean isPersistentConnection()
          Determines whether this will be a persistent connection.
 IoState read(ScatteringByteChannel in)
          Reads from the specified channel and returns the possibly new state of the instance.
 void setCloseConnection()
           
 IoState state()
          Returns the state of the handlet.
 IoState unwind(IoState preState)
          Callback method invoked when the previous stage[let] returned DONE.
 IoState write(GatheringByteChannel out)
          Writes to the specified channel and returns the possibly new state of the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestStage

public RequestStage(StageletStack stack,
                    ResponseFactory responseFactory)

RequestStage

public RequestStage(StageletStack stack,
                    ResponseFactory responseFactory,
                    long maxHeaderSize)
Method Detail

getVerb

public Verb getVerb()
Description copied from interface: RequestHeader
Returns the HTTP verb.

Specified by:
getVerb in interface RequestHeader

getUri

public String getUri()
Description copied from interface: RequestHeader
Returns the URI referenced in the first line of the HTTP request.

Specified by:
getUri in interface RequestHeader
Returns:
a string of the form "/path1/path2/app1?name1=value1&name2=value2"

getVersion

public String getVersion()
Description copied from interface: RequestHeader
Returns the HTTP version string in the first line of the HTTP request.

Specified by:
getVersion in interface RequestHeader
Returns:
HTTP/1.1 or HTTP/1.0

getProperties

public Map<String,String> getProperties()
Description copied from interface: RequestHeader
Returns a name/value map encapsulating the HTTP request headers received. These are of the form

      ${name}: ${value} CRLF
 

Specified by:
getProperties in interface RequestHeader

isPersistentConnection

public boolean isPersistentConnection()
Description copied from interface: RequestHeader
Determines whether this will be a persistent connection. Persistent connections allow for HTTP requests to be pipelined over a same socket. This property is explicitly exposed because it affects the HTTP response headers.

Specified by:
isPersistentConnection in interface RequestHeader

setCloseConnection

public void setCloseConnection()

discard

public void discard()
Description copied from interface: Handlet
Discards the instance.

Specified by:
discard in interface Handlet

init

public IoState init(HandletContext context)
Description copied from interface: Handlet
Initializes the handlet.

Specified by:
init in interface Handlet
Parameters:
context - the context supplied by the instance's container (e.g. server

read

public IoState read(ScatteringByteChannel in)
             throws IOException
Description copied from interface: Handlet
Reads from the specified channel and returns the possibly new state of the instance. Note that if the return value is IoState.PROCESSING, then a later invocation of Handlet.state() may return a value other than PROCESSING, if the asynchronous task completes before the call to state().

The implementation must read from the channel in non-blocking manner. The behavior of this method is undefined if the state of the instance is not IoState.READING.

Specified by:
read in interface Handlet
Throws:
IOException

state

public IoState state()
Description copied from interface: Handlet
Returns the state of the handlet.

Specified by:
state in interface Handlet

unwind

public IoState unwind(IoState preState)
Description copied from interface: Stagelet
Callback method invoked when the previous stage[let] returned DONE. In the event this method returns DONE, the stack will call the Handlet.discard() method on the super interface.

Specified by:
unwind in interface Stagelet
Parameters:
preState - the state of the previous stage prior to its flipping to DONE
Returns:
the state of this stage. If DONE, and there is another Stagelet on the execution stack, then that stage's unwind() method will also be invoked with the same preState argument.

write

public IoState write(GatheringByteChannel out)
              throws IOException,
                     UnsupportedOperationException
Description copied from interface: Handlet
Writes to the specified channel and returns the possibly new state of the instance. Note that if the return value is IoState.PROCESSING, then a later invocation of Handlet.state() may return a value other than PROCESSING, if the asynchronous task completes before the call to state().

The implementation must write to the channel in non-blocking manner. The behavior of this method is undefined if the state of the instance is not IoState.WRITING.

Specified by:
write in interface Handlet
Throws:
IOException
UnsupportedOperationException


SourceForge.net Logo