netapp.manage.http
Class HTTPMessage

java.lang.Object
  extended bynetapp.manage.http.HTTPMessage
Direct Known Subclasses:
HTTPRequest, HTTPResponse

public abstract class HTTPMessage
extends java.lang.Object

This class represents a HTTP message.


Field Summary
protected  byte[] _contents
           
protected  java.util.Map _header
           
protected  java.util.Map _headerLowerCase
           
protected  int _version
           
static int METHOD_GET
          A constant that specifies the HTTP GET method.
static int METHOD_POST
          A constant that specifies the HTTP POST method.
static int VERSION_1_0
          A constant that specifies version HTTP/1.0.
static int VERSION_1_1
          A constant that specifies version HTTP/1.1.
 
Constructor Summary
protected HTTPMessage(int version)
          Constructs a HTTPMessage.
 
Method Summary
protected abstract  java.lang.String firstLine()
          Get the first (status) line of this HTTP message.
 byte[] getContents()
          Return the contents of the message body of this message.
 java.lang.String getHeader(java.lang.String key)
          Return the contents of one HTTP header from this message.
protected  java.lang.String headersString()
          Get the HTTP headers.
protected static int methodFromString(java.lang.String s)
          Parse a HTTP method string
protected static java.lang.String methodToString(int method)
          Get the string representation of a HTTP method.
protected  void processHeaderLine(java.lang.String line)
          Set a header based on a line of text.
protected  void readContents(java.io.InputStream in)
          Read the message-body of this message.
protected static java.lang.String readLine(java.io.InputStream in)
          Read one line of text.
 java.lang.String removeHeader(java.lang.String key)
          Remove one HTTP header from this message.
 void setContents(byte[] contents)
          Set the contents of the message-body of this message.
 void setHeader(java.lang.String key, java.lang.String value)
          Set the contents of one HTTP header in this message.
 java.lang.String toString()
          Return a String representation of this HTTPMessage.
protected static int versionFromString(java.lang.String s)
          Parse a HTTP version string.
protected static java.lang.String versionToString(int version)
          Get the string representation of a HTTP version.
 void write(java.io.OutputStream out)
          Write this message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION_1_0

public static final int VERSION_1_0
A constant that specifies version HTTP/1.0.

See Also:
Constant Field Values

VERSION_1_1

public static final int VERSION_1_1
A constant that specifies version HTTP/1.1.

See Also:
Constant Field Values

METHOD_GET

public static final int METHOD_GET
A constant that specifies the HTTP GET method.

See Also:
Constant Field Values

METHOD_POST

public static final int METHOD_POST
A constant that specifies the HTTP POST method.

See Also:
Constant Field Values

_version

protected int _version

_headerLowerCase

protected java.util.Map _headerLowerCase

_header

protected java.util.Map _header

_contents

protected byte[] _contents
Constructor Detail

HTTPMessage

protected HTTPMessage(int version)
Constructs a HTTPMessage.

Parameters:
version - the HTTP version.
Method Detail

setContents

public void setContents(byte[] contents)
Set the contents of the message-body of this message. The contents are represented as a byte array.

Parameters:
contents - the message-body.

getContents

public byte[] getContents()
Return the contents of the message body of this message. The contents are represented as a byte array.

Returns:
the message-body.

getHeader

public java.lang.String getHeader(java.lang.String key)
Return the contents of one HTTP header from this message.

Parameters:
key - which HTTP header.
Returns:
the value of the header.

setHeader

public void setHeader(java.lang.String key,
                      java.lang.String value)
Set the contents of one HTTP header in this message.

Parameters:
key - which HTTP header.
value - the new value of the header.

removeHeader

public java.lang.String removeHeader(java.lang.String key)
Remove one HTTP header from this message.

Parameters:
key - which HTTP header.

versionFromString

protected static int versionFromString(java.lang.String s)
                                throws HTTPException
Parse a HTTP version string.

Parameters:
s - a version string.
Returns:
either VERSION_1_0 or VERSION_1_1.
Throws:
HTTPException - if the string is not a valid HTTP version string.

versionToString

protected static java.lang.String versionToString(int version)
Get the string representation of a HTTP version. Invalid version are represented by the empty string.

Parameters:
version - the version.
Returns:
string representation of the version.

methodFromString

protected static int methodFromString(java.lang.String s)
                               throws HTTPException
Parse a HTTP method string

Parameters:
s - a method string.
Returns:
either METHOD_GET or METHOD_POST.
Throws:
HTTPException - if the string is not a valid HTTP method string.

methodToString

protected static java.lang.String methodToString(int method)
Get the string representation of a HTTP method.

Parameters:
method - the method.
Returns:
string representation of the method.

readLine

protected static java.lang.String readLine(java.io.InputStream in)
                                    throws java.io.IOException
Read one line of text. This is a utility function that reads RFC2616 compliant lines of text from socket (using the platform's default charset).

Parameters:
in - the input stream (which is presumably connected to a HTTP socket).
Returns:
a line of text.
Throws:
java.io.IOException - if there is a communication problem on the socket or if an invalid line terminator is encountered.

readContents

protected void readContents(java.io.InputStream in)
                     throws java.io.IOException
Read the message-body of this message. This is a utility function that reads the message-body from a socket assuming that the message was created from the headers immediately preceding the message-body. The message-body is stored in the contents of this message.

Parameters:
in - the input stream (which is presumably connected to a HTTP socket).
Throws:
java.io.IOException - if there is a communication problem on the socket.

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Write this message. Write this entire HTTP message to a socket.

Parameters:
out - the output stream stream (which is presumably connected to a HTTP socket).
Throws:
java.io.IOException - if there is a communication problem on the socket.

processHeaderLine

protected void processHeaderLine(java.lang.String line)
                          throws HTTPException
Set a header based on a line of text. Parses a line of text representing a HTTP header, and store the header in this message.

Parameters:
line - a line of text.
Throws:
HTTPException - if the line is not a valid HTTP header.

firstLine

protected abstract java.lang.String firstLine()
Get the first (status) line of this HTTP message.

Returns:
a string representing one line.

headersString

protected java.lang.String headersString()
Get the HTTP headers. Returns a string representing several lines of text containing all the HTTP headers in this message.

Returns:
a string representing many lines of text.

toString

public java.lang.String toString()
Return a String representation of this HTTPMessage. The first line (status line) plus the HTTP headers are included in the string.

Returns:
a string representing the first line and headers.