Java HTTP Proxy Library Project Page
SourceForge.net Logo

com.wpg.proxy
Class HttpMessage

java.lang.Object
  extended by com.wpg.proxy.HttpMessage
Direct Known Subclasses:
HttpMessageRequest, HttpMessageResponse

public abstract class HttpMessage
extends java.lang.Object

Class to manage the HTTP message headers and body content, which could be anything at this point This class should be extended by HttpMessageRequest and HttpMessageResponse classes and never used directly


Field Summary
protected  byte[] body
           
protected  java.nio.ByteBuffer data
           
protected  java.lang.String fromHost
           
protected  int fromPort
           
static java.lang.String HEADER_ACCEPT
           
static java.lang.String HEADER_ACCEPT_CHARSET
           
static java.lang.String HEADER_ACCEPT_ENCODING
           
static java.lang.String HEADER_ACCEPT_LANGUAGE
           
static java.lang.String HEADER_CONNECTION
           
static java.lang.String HEADER_CONTENT_LENGTH
           
static java.lang.String HEADER_CONTENT_TYPE
           
static java.lang.String HEADER_COOKIE
           
static java.lang.String HEADER_DATE
           
static java.lang.String HEADER_KEEP_ALIVE
           
static java.lang.String HEADER_PROXY_CONNECTION
           
static java.lang.String HEADER_REFERER
           
static java.lang.String HEADER_SERVER
           
static java.lang.String HEADER_SET_COOKIE
           
static java.lang.String HEADER_TRANSFER_ENCODING
           
static java.lang.String HEADER_USER_AGENT
           
protected  java.util.Vector<java.lang.String> headerOrder
           
protected  java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers
           
protected  boolean isSecure
           
protected static Logger logger
           
protected  java.lang.String protocol
           
protected  java.lang.String protocolVersion
           
protected  java.lang.String startLine
           
protected  java.lang.String toHost
           
protected  int toPort
           
 
Constructor Summary
HttpMessage()
           
 
Method Summary
 void addHeader(java.lang.String h, java.lang.String item)
          Add to a specific Header from a String
 void addToBody(byte[] b, int s)
          Add byte[] to body content
 byte[] getBodyContent()
          Get raw content as an Array of Bytes
 java.io.ByteArrayInputStream getBodyContentStream()
          Get the content as a Stream of Bytes
 int getContentLength()
          Get the size of the stated content length
 java.nio.ByteBuffer getData()
          Get entire message as a ByteBuffer containing the header and body if any
 java.lang.String getFromHost()
          Get From Host, or the host initiating this request
 int getFromPort()
          Get From Port, or the port on the host initiating this request
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
          Get All Headers as a Map
 java.lang.String getHeadersAsString()
          Return a String with the headers printed in their RFC compliant final version
 java.util.List<java.lang.String> getHeaderValues(java.lang.String header)
          Get a specific Header as a List
 java.lang.String getProtocol()
          Get the protocol of this request as a string
 java.lang.String getStartLine()
          Get the Start Line of the Message
 java.lang.String getToHost()
          Get To Host, or the host which is the target of this request
 int getToPort()
          Get To Port, or the port on the host which is the target of this request
 java.lang.String getVersion()
          Get the protocol version of this request as a string
 boolean isContentLengthSet()
          Return true|false if the content length header is set
 void setBodyContent(byte[] b)
          Set body content to input byte[]
 void setFromHost(java.lang.String h)
          Set From Host, or the host initiating this request
 void setFromPort(int p)
          Set From Port, or the port on the host initiating this request
 void setHeader(java.lang.String h, java.util.Vector<java.lang.String> l)
          Set a specific Header from a List
 void setHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> m)
          Set All Headers from a Map
 void setHeaders(java.util.Vector v)
          Add Headers from a Vector of raw lines
 void setProtocol(java.lang.String s)
          Set the protocol of this request
abstract  void setStartLine(java.lang.String s)
          Set the Start Line of the Message
 void setToHost(java.lang.String h)
          Set To Host, or the host which is the target of this request
 void setToPort(int p)
          Set To Port, or the port on the host which is the target of this request
 void setVersion(java.lang.String s)
          Set the protocol version of this request
protected  void updateContentLength()
          Update the content length header to the size of the new body
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_ACCEPT

public static final java.lang.String HEADER_ACCEPT
See Also:
Constant Field Values

HEADER_ACCEPT_CHARSET

public static final java.lang.String HEADER_ACCEPT_CHARSET
See Also:
Constant Field Values

HEADER_ACCEPT_ENCODING

public static final java.lang.String HEADER_ACCEPT_ENCODING
See Also:
Constant Field Values

HEADER_ACCEPT_LANGUAGE

public static final java.lang.String HEADER_ACCEPT_LANGUAGE
See Also:
Constant Field Values

HEADER_CONNECTION

public static final java.lang.String HEADER_CONNECTION
See Also:
Constant Field Values

HEADER_CONTENT_LENGTH

public static final java.lang.String HEADER_CONTENT_LENGTH
See Also:
Constant Field Values

HEADER_CONTENT_TYPE

public static final java.lang.String HEADER_CONTENT_TYPE
See Also:
Constant Field Values

HEADER_COOKIE

public static final java.lang.String HEADER_COOKIE
See Also:
Constant Field Values

HEADER_DATE

public static final java.lang.String HEADER_DATE
See Also:
Constant Field Values

HEADER_KEEP_ALIVE

public static final java.lang.String HEADER_KEEP_ALIVE
See Also:
Constant Field Values

HEADER_PROXY_CONNECTION

public static final java.lang.String HEADER_PROXY_CONNECTION
See Also:
Constant Field Values

HEADER_REFERER

public static final java.lang.String HEADER_REFERER
See Also:
Constant Field Values

HEADER_SERVER

public static final java.lang.String HEADER_SERVER
See Also:
Constant Field Values

HEADER_SET_COOKIE

public static final java.lang.String HEADER_SET_COOKIE
See Also:
Constant Field Values

HEADER_TRANSFER_ENCODING

public static final java.lang.String HEADER_TRANSFER_ENCODING
See Also:
Constant Field Values

HEADER_USER_AGENT

public static final java.lang.String HEADER_USER_AGENT
See Also:
Constant Field Values

logger

protected static final Logger logger

body

protected byte[] body

data

protected java.nio.ByteBuffer data

fromHost

protected java.lang.String fromHost

fromPort

protected int fromPort

toHost

protected java.lang.String toHost

toPort

protected int toPort

startLine

protected java.lang.String startLine

protocol

protected java.lang.String protocol

protocolVersion

protected java.lang.String protocolVersion

isSecure

protected boolean isSecure

headers

protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers

headerOrder

protected java.util.Vector<java.lang.String> headerOrder
Constructor Detail

HttpMessage

public HttpMessage()
Method Detail

setBodyContent

public void setBodyContent(byte[] b)
Set body content to input byte[]


addToBody

public void addToBody(byte[] b,
                      int s)
Add byte[] to body content


updateContentLength

protected void updateContentLength()
Update the content length header to the size of the new body


getBodyContent

public byte[] getBodyContent()
Get raw content as an Array of Bytes


getBodyContentStream

public java.io.ByteArrayInputStream getBodyContentStream()
Get the content as a Stream of Bytes


getData

public java.nio.ByteBuffer getData()
Get entire message as a ByteBuffer containing the header and body if any


getFromHost

public java.lang.String getFromHost()
Get From Host, or the host initiating this request


setFromHost

public void setFromHost(java.lang.String h)
Set From Host, or the host initiating this request


getFromPort

public int getFromPort()
Get From Port, or the port on the host initiating this request


setFromPort

public void setFromPort(int p)
Set From Port, or the port on the host initiating this request


getToHost

public java.lang.String getToHost()
Get To Host, or the host which is the target of this request


setToHost

public void setToHost(java.lang.String h)
Set To Host, or the host which is the target of this request


getToPort

public int getToPort()
Get To Port, or the port on the host which is the target of this request


setToPort

public void setToPort(int p)
Set To Port, or the port on the host which is the target of this request


getStartLine

public java.lang.String getStartLine()
Get the Start Line of the Message


setStartLine

public abstract void setStartLine(java.lang.String s)
Set the Start Line of the Message


getProtocol

public java.lang.String getProtocol()
Get the protocol of this request as a string


setProtocol

public void setProtocol(java.lang.String s)
Set the protocol of this request


getVersion

public java.lang.String getVersion()
Get the protocol version of this request as a string


setVersion

public void setVersion(java.lang.String s)
Set the protocol version of this request


getHeaders

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Get All Headers as a Map


setHeaders

public void setHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> m)
Set All Headers from a Map


getHeaderValues

public java.util.List<java.lang.String> getHeaderValues(java.lang.String header)
Get a specific Header as a List


setHeader

public void setHeader(java.lang.String h,
                      java.util.Vector<java.lang.String> l)
Set a specific Header from a List


addHeader

public void addHeader(java.lang.String h,
                      java.lang.String item)
Add to a specific Header from a String


setHeaders

public void setHeaders(java.util.Vector v)
Add Headers from a Vector of raw lines


getHeadersAsString

public java.lang.String getHeadersAsString()
Return a String with the headers printed in their RFC compliant final version


isContentLengthSet

public boolean isContentLengthSet()
Return true|false if the content length header is set


getContentLength

public int getContentLength()
Get the size of the stated content length


Java HTTP Proxy Library Project Page
SourceForge.net Logo