net.groboclown.util.http.v1
Class SimpleHttpGet

java.lang.Object
  |
  +--net.groboclown.util.http.v1.SimpleHttpGet

public class SimpleHttpGet
extends Object

This class is used to replace the HTTPConnection. It has several improvements:

Since:
Alpha 0.9.0
Version:
Alpha 0.9.1
Author:
Matt Albrecht

Field Summary
private static int CHUNKED
           
private static int DEFAULT_HTTP_PORT
           
private static String HTTP1_0
           
private static String HTTP1_1
           
private  Socket m_connection
           
private  int m_contentLength
           
private  boolean m_isOpen
           
protected  boolean m_isProxy
           
private  int m_messageFormat
           
private  boolean m_persist
           
protected  String m_serverName
           
protected  int m_serverPort
           
private  InputStream m_socketIn
           
private  Writer m_socketOut
           
private static int PLAIN
           
private static int UNKNOWN_FORMAT
           
private static int UNTILCLOSED
           
 
Constructor Summary
SimpleHttpGet(String serverName)
          Constructor based on a server, through a non-proxy connection on port 80.
SimpleHttpGet(String serverName, int serverPort)
          Constructor based on a server with a non-default port.
SimpleHttpGet(String serverName, int serverPort, boolean isProxy)
          Constructor based on a connection to the given server with the given port number, which may be a proxy connection if isProxy is true.
 
Method Summary
static void addHeader(Hashtable headers, String n, String v)
          Adds a header entry to the hashtable, creating an array entry if an entry already exists.
static void addUniqueHeader(Hashtable headers, String n, String v)
          Adds a header entry to the given hashtable only if an entry for that name does not already exist.
protected  void appendHeader(StringBuffer sb, String name, String value)
           
protected  void buildHeaders(Hashtable headers, String message)
           
 void close()
          Perform an absolute close on the connection.
 void connect()
           
protected  void finalize()
           
protected  String generateRequest(String type, URL url, Hashtable headers, String message)
           
protected  void getResponse(HttpResponseMessageImpl hrm)
          This must be accessed only in a synchronized block.
 byte[] getURLMessage(URL url)
          Sends a request of the given URL, and returns the server's message.
 IHttpResponseMessage getURLResponse(URL url)
          Returns all the response data sent back by the server.
 IHttpResponseMessage getURLResponse(URL url, String method, Hashtable headers, String messageData)
          Returns all the response data sent back by the server.
 boolean isConnectionOpen()
          Checks if the connection to the server is open.
static void main(String[] args)
           
protected  void processHead(HttpResponseMessageImpl hrm, StringBuffer linebuffer)
           
protected  void processStatus(HttpResponseMessageImpl hrm, StringBuffer statusline)
           
protected  void receiveHead(HttpResponseMessageImpl hrm)
          This must be accessed only in a synchronized block.
protected  byte[] receiveMessage(HttpResponseMessageImpl hrm)
           
protected  void sendRequest(String requestMessage)
           
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_serverName

protected String m_serverName

m_serverPort

protected int m_serverPort

m_isProxy

protected boolean m_isProxy

HTTP1_1

private static final String HTTP1_1

HTTP1_0

private static final String HTTP1_0

PLAIN

private static final int PLAIN

CHUNKED

private static final int CHUNKED

UNTILCLOSED

private static final int UNTILCLOSED

UNKNOWN_FORMAT

private static final int UNKNOWN_FORMAT

DEFAULT_HTTP_PORT

private static final int DEFAULT_HTTP_PORT

m_connection

private Socket m_connection

m_isOpen

private boolean m_isOpen

m_socketOut

private Writer m_socketOut

m_socketIn

private InputStream m_socketIn

m_persist

private boolean m_persist

m_messageFormat

private int m_messageFormat

m_contentLength

private int m_contentLength
Constructor Detail

SimpleHttpGet

public SimpleHttpGet(String serverName)
              throws IOException
Constructor based on a server, through a non-proxy connection on port 80.

SimpleHttpGet

public SimpleHttpGet(String serverName,
                     int serverPort)
              throws IOException
Constructor based on a server with a non-default port.

SimpleHttpGet

public SimpleHttpGet(String serverName,
                     int serverPort,
                     boolean isProxy)
              throws IOException
Constructor based on a connection to the given server with the given port number, which may be a proxy connection if isProxy is true.
Method Detail

main

public static void main(String[] args)
                 throws Exception

isConnectionOpen

public boolean isConnectionOpen()
Checks if the connection to the server is open.
Returns:
true if the connection to the server is open, otherwise false.

connect

public void connect()
             throws IOException

getURLResponse

public IHttpResponseMessage getURLResponse(URL url)
                                    throws IOException
Returns all the response data sent back by the server.

getURLResponse

public IHttpResponseMessage getURLResponse(URL url,
                                           String method,
                                           Hashtable headers,
                                           String messageData)
                                    throws IOException
Returns all the response data sent back by the server.

getURLMessage

public byte[] getURLMessage(URL url)
                     throws IOException
Sends a request of the given URL, and returns the server's message.

close

public void close()
Perform an absolute close on the connection.

addUniqueHeader

public static void addUniqueHeader(Hashtable headers,
                                   String n,
                                   String v)
Adds a header entry to the given hashtable only if an entry for that name does not already exist.

addHeader

public static void addHeader(Hashtable headers,
                             String n,
                             String v)
Adds a header entry to the hashtable, creating an array entry if an entry already exists. If the existing entry is already a String Array entry, then the given value is appended to the array.

sendRequest

protected void sendRequest(String requestMessage)
                    throws IOException

getResponse

protected void getResponse(HttpResponseMessageImpl hrm)
                    throws IOException
This must be accessed only in a synchronized block.

generateRequest

protected String generateRequest(String type,
                                 URL url,
                                 Hashtable headers,
                                 String message)
                          throws IOException

appendHeader

protected void appendHeader(StringBuffer sb,
                            String name,
                            String value)

buildHeaders

protected void buildHeaders(Hashtable headers,
                            String message)

receiveHead

protected void receiveHead(HttpResponseMessageImpl hrm)
                    throws IOException
This must be accessed only in a synchronized block.

processStatus

protected void processStatus(HttpResponseMessageImpl hrm,
                             StringBuffer statusline)
                      throws IOException

processHead

protected void processHead(HttpResponseMessageImpl hrm,
                           StringBuffer linebuffer)
                    throws IOException

receiveMessage

protected byte[] receiveMessage(HttpResponseMessageImpl hrm)
                         throws IOException

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object


Written under the LGPL