jason.framework.protocol.http
Class HttpRequestParserImpl

java.lang.Object
  |
  +--jason.framework.protocol.http.HttpRequestParserImpl
All Implemented Interfaces:
HttpRequestParser

public class HttpRequestParserImpl
extends java.lang.Object
implements HttpRequestParser

This class is responsible for parsing a HTTP request and obtain the following information

1) Fully qualified resource name 2) Header names 3) Header values 4) Request message body It takes a InputStream to access the client request.

TO DO : Support Transfer-Encoding, multipart/byteranges for the Body content Taking into account Keep-Alive for too long process

See Also:
HttpParser

Field Summary
protected  java.io.InputStream clientIStream
           
protected  java.util.Hashtable headerTable
           
protected  java.lang.String method
           
protected  java.util.Hashtable parameterTable
           
protected  java.lang.String protocol
           
protected  java.lang.String requestURI
           
 
Constructor Summary
HttpRequestParserImpl()
          This constructor is to be used while instances of this class is put into the ThreadPool individually or as a part of a different object
HttpRequestParserImpl(java.io.InputStream clientIStream)
           
 
Method Summary
 java.lang.String getHeader(java.lang.String header)
           
 java.util.Enumeration getHeaderNames()
           
 byte[] getMessageBody()
           
 java.lang.String getMethod()
           
 java.lang.String getParameter(java.lang.String parameter)
           
 java.util.Enumeration getParameterNames()
           
 java.lang.String getProtocol()
           
 java.lang.String getRequestURI()
           
 java.lang.String getRequestURIQuery()
           
 boolean isParsed()
           
 void parse(java.io.InputStream clientIStream)
          Parses an HTTP request from the RFC 2068.
protected  void parseGenericLine(java.lang.String line, java.lang.String separator, java.util.Hashtable fields, boolean resolve, boolean lowerCase)
          Parse a line based on Property Value.
protected  void parseHeaderLine(java.lang.String line, java.util.Hashtable fields, boolean resolve)
          Parses a single field=value line
protected  void parseHeaders(java.io.BufferedReader bufr, java.util.Hashtable fields, boolean resolve)
          Parses headers following the requestLine.
protected  void parseParameters(java.lang.String requestLine, java.io.InputStream content)
          Parses parameters from the requestLine and from the buffer content.
protected  void parseRequest(java.lang.String requestLine)
          Parse a request line From the RFC 2068 : request-line = Method SP Request-URI SP HTTP-Version CRLF
protected  void parseRequestParameter(java.lang.String parameter)
          Parses the request-uri from the request-line ?
protected  void parseRequestParameterItem(java.lang.String parameterValue)
          Parses a single field=value from the request-line
 void setClientIStream(java.io.InputStream clientIStream)
          Pass an inputStream for parsing the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

protocol

protected java.lang.String protocol

method

protected java.lang.String method

headerTable

protected java.util.Hashtable headerTable

parameterTable

protected java.util.Hashtable parameterTable

requestURI

protected java.lang.String requestURI

clientIStream

protected java.io.InputStream clientIStream
Constructor Detail

HttpRequestParserImpl

public HttpRequestParserImpl(java.io.InputStream clientIStream)
                      throws HttpParsingException

HttpRequestParserImpl

public HttpRequestParserImpl()
                      throws HttpParsingException
This constructor is to be used while instances of this class is put into the ThreadPool individually or as a part of a different object

Method Detail

setClientIStream

public void setClientIStream(java.io.InputStream clientIStream)
Pass an inputStream for parsing the request. User must call the parse method for activation.

Parameters:
clientIStream - inputStream contains an HTTP request

getProtocol

public java.lang.String getProtocol()
Specified by:
getProtocol in interface HttpRequestParser
Returns:
the protocol used for this request with version

getMethod

public java.lang.String getMethod()
Specified by:
getMethod in interface HttpRequestParser
Returns:
the Method of the HTTP request

getRequestURI

public java.lang.String getRequestURI()
Specified by:
getRequestURI in interface HttpRequestParser
Returns:
the page request of the HTTP request

getRequestURIQuery

public java.lang.String getRequestURIQuery()
Specified by:
getRequestURIQuery in interface HttpRequestParser
Returns:
the query tied with the URI

getHeader

public java.lang.String getHeader(java.lang.String header)
Specified by:
getHeader in interface HttpRequestParser
Returns:
the value of a header if present in the request - otherwise returns "null".

getHeaderNames

public java.util.Enumeration getHeaderNames()
Specified by:
getHeaderNames in interface HttpRequestParser
Returns:
the names of the headers of the client request as an Enumeration

getParameter

public java.lang.String getParameter(java.lang.String parameter)
Specified by:
getParameter in interface HttpRequestParser
Parameters:
parameter - A parameter name
Returns:
the value of the specific parameter or null if the parameter is not present in the request

getParameterNames

public java.util.Enumeration getParameterNames()
Specified by:
getParameterNames in interface HttpRequestParser
Returns:
the name of the parameters in form of an Enumeration

isParsed

public boolean isParsed()
Returns:
true if the request had been parsed

parseHeaders

protected void parseHeaders(java.io.BufferedReader bufr,
                            java.util.Hashtable fields,
                            boolean resolve)
                     throws java.io.IOException
Parses headers following the requestLine. An empty line follow the set of headers, this is the marker for terminating the processing. From the RFC 2068 : message-header = field-name ":" [ field-value ] CRLF field-name = token field-value = *( field-content | LWS ) field-content =

Parameters:
bufr - Buffer with fields
fields - hashtable with the result
resolve - if true, replace content %AA entity with real caracter value
java.io.IOException

parseHeaderLine

protected void parseHeaderLine(java.lang.String line,
                               java.util.Hashtable fields,
                               boolean resolve)
Parses a single field=value line

Parameters:
line - field=value
fields - Stores the key and value from the field=value
resolve - Chooses to resolve Entity %HH value

parseGenericLine

protected void parseGenericLine(java.lang.String line,
                                java.lang.String separator,
                                java.util.Hashtable fields,
                                boolean resolve,
                                boolean lowerCase)
Parse a line based on Property Value. if resolve is true, then all entity %HH are replaced by an ASCII value It stores the result in the fields hashtable

Parameters:
line - Line to parse
separator - Property Value, like ':' or '='
fields - Store Property and Value in it
resolve - Resolve entity in the Value

parse

public void parse(java.io.InputStream clientIStream)
           throws HttpParsingException
Parses an HTTP request from the RFC 2068. It's not the role of this method to decide not to support a particular method

Specified by:
parse in interface HttpRequestParser
Throws:
HttpParsingException - for an error while parsing

parseRequest

protected void parseRequest(java.lang.String requestLine)
Parse a request line From the RFC 2068 : request-line = Method SP Request-URI SP HTTP-Version CRLF

Parameters:
requestLine -

parseParameters

protected void parseParameters(java.lang.String requestLine,
                               java.io.InputStream content)
                        throws java.io.IOException
Parses parameters from the requestLine and from the buffer content. When it exists an content-length value in the header then the content can be parsed. It is possible to receive parameters from the command line and from the buffer content.

java.io.IOException

getMessageBody

public byte[] getMessageBody()
Specified by:
getMessageBody in interface HttpRequestParser

parseRequestParameter

protected void parseRequestParameter(java.lang.String parameter)
Parses the request-uri from the request-line ?name=value&... Stores the result in the parameterTable


parseRequestParameterItem

protected void parseRequestParameterItem(java.lang.String parameterValue)
Parses a single field=value from the request-line