de.netseeker.ejoe.http
Class HttpRequest

java.lang.Object
  extended by de.netseeker.ejoe.http.HttpRequest
Direct Known Subclasses:
HttpResponse

public class HttpRequest
extends java.lang.Object

A simple container encapsulating a HTTP header. Additional methods are provided to convert such a header into ByteBuffer and/or String representations

Since:
0.3.9.1
Author:
netseeker

Field Summary
protected  ConnectionHeader _header
           
protected  ByteBufferOutputStream _out
           
protected static java.lang.String CHARSET
           
static java.lang.String HTTP_GET
           
static java.lang.String HTTP_HEAD
           
static java.lang.String HTTP_POST
           
protected static java.lang.String LINE_SEP
           
 
Constructor Summary
HttpRequest(ConnectionHeader header, java.lang.String method)
          Creates a new HTTP request using the given connection header and the given HTTP method (HEAD, POST).
HttpRequest(ConnectionHeader header, java.lang.String contentType, java.lang.String method)
          Creates a new HTTP request using the given connection header, the given HTTP method (HEAD, POST) and the given content (mime) type.
HttpRequest(ConnectionHeader header, java.lang.String host, java.lang.String contentType, java.lang.String method)
          Creates a new HTTP request using the given connection header, the given host name, the given content (mime) type and the given HTTP method (HEAD, POST).
 
Method Summary
 void addData(byte data)
           
 void addData(byte[] data)
           
 void addData(java.nio.ByteBuffer data)
           
 void addData(int data)
           
 void addData(java.lang.String data)
           
 java.lang.String getContentType()
           
 java.lang.String getHost()
           
 java.lang.String getMethod()
           
 ByteBufferOutputStream getOutputStream()
           
 void reset()
          Resets all data appended to this request
 java.nio.ByteBuffer toByteBuffer()
          Transforms this HTTP request into a ByteBuffer
protected  java.lang.String toHeaderString()
          Transforms only the contained HTTP header into a string representation
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTTP_GET

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

HTTP_POST

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

HTTP_HEAD

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

CHARSET

protected static final java.lang.String CHARSET
See Also:
Constant Field Values

LINE_SEP

protected static final java.lang.String LINE_SEP
See Also:
Constant Field Values

_out

protected ByteBufferOutputStream _out

_header

protected ConnectionHeader _header
Constructor Detail

HttpRequest

public HttpRequest(ConnectionHeader header,
                   java.lang.String method)
Creates a new HTTP request using the given connection header and the given HTTP method (HEAD, POST). The host name will be taken from the given connection header. The content (mime) type will be determined from the SerializeAdapter as declared in the connection header. If the connection header does not declare a SerializeAdapter the default content type will be used.

Parameters:
header - a valid connection header
method - a valid HTTP method string

HttpRequest

public HttpRequest(ConnectionHeader header,
                   java.lang.String contentType,
                   java.lang.String method)
Creates a new HTTP request using the given connection header, the given HTTP method (HEAD, POST) and the given content (mime) type. The host name will be taken from the given connection header.

Parameters:
header - a valid connection header
contentType - a valid mime type string
method - a valid HTTP method string

HttpRequest

public HttpRequest(ConnectionHeader header,
                   java.lang.String host,
                   java.lang.String contentType,
                   java.lang.String method)
Creates a new HTTP request using the given connection header, the given host name, the given content (mime) type and the given HTTP method (HEAD, POST).

Parameters:
header - a valid connection header
host - name of the target HOST
contentType - a valid mime type string
method - a valid HTTP method string
Method Detail

getContentType

public java.lang.String getContentType()
Returns:
the content type

getHost

public java.lang.String getHost()
Returns:
the host

getMethod

public java.lang.String getMethod()
Returns:
the HTTP method

addData

public void addData(byte data)
Parameters:
data -

addData

public void addData(int data)
Parameters:
data -

addData

public void addData(byte[] data)
Parameters:
data -

addData

public void addData(java.lang.String data)
Parameters:
data -

addData

public void addData(java.nio.ByteBuffer data)
Parameters:
data -

toByteBuffer

public java.nio.ByteBuffer toByteBuffer()
Transforms this HTTP request into a ByteBuffer

Returns:
a ByteBuffer containing the encoded HTTP request data

toHeaderString

protected java.lang.String toHeaderString()
Transforms only the contained HTTP header into a string representation

Returns:
a string representation of this HTTP header

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

reset

public void reset()
Resets all data appended to this request


getOutputStream

public final ByteBufferOutputStream getOutputStream()
Returns:
the underlying OutputStream used to append request data


Copyright © 2005-2007 netseeker. All Rights Reserved.