Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.dinopolis.gpstool.util
Class HttpRequester  view HttpRequester download HttpRequester.java

java.lang.Object
  extended byorg.dinopolis.gpstool.util.HttpRequester

public class HttpRequester
extends java.lang.Object

The HttpRequester is able perform a HTTP get request and set any HTTP-Headers wanted. The response headers and the content is read and stored in a map that can be used afterwards. This class is not so powerful as the java.net.URLConnection but does not hide anything from the programmer. It respects the proxy settings in the system properties. This class is especially usefull if you want to request more than one url from the same server. Do not forget to set "Keep-Alive" in the http header!

Version:
$Revision: 1.3 $

Field Summary
static int BUFFER_SIZE
          the buffer size to use when reading from the socket
protected  java.lang.String host_
           
protected  int port_
           
protected  java.lang.String proxy_host_
           
protected  int proxy_port_
           
protected  java.net.Socket socket_
           
protected  java.io.BufferedReader socket_reader_
           
protected  java.io.Writer socket_writer_
           
protected  boolean use_proxy_
           
protected  java.util.Map web_request_
           
protected  java.util.Map web_response_
           
 
Constructor Summary
HttpRequester(java.lang.String hostname)
          Constructor connection to the given hostname and the default port for http (80).
HttpRequester(java.lang.String hostname, int port)
          Constructor
 
Method Summary
protected  void initProxy()
          Reads the proxy settings from the system's properties.
protected  void openConnection()
          Opens the connection to the host or to the proxy.
protected  void printMap(java.util.Map map)
           
 java.util.Map requestUrl(java.net.URL url, java.util.Map http_headers)
          Requests the given url from the host or the proxy and uses the given headers (and no other headers!).
protected  void writeToSocket(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
the buffer size to use when reading from the socket

See Also:
Constant Field Values

host_

protected java.lang.String host_

port_

protected int port_

proxy_host_

protected java.lang.String proxy_host_

proxy_port_

protected int proxy_port_

use_proxy_

protected boolean use_proxy_

web_request_

protected java.util.Map web_request_

web_response_

protected java.util.Map web_response_

socket_

protected java.net.Socket socket_

socket_reader_

protected java.io.BufferedReader socket_reader_

socket_writer_

protected java.io.Writer socket_writer_
Constructor Detail

HttpRequester

public HttpRequester(java.lang.String hostname)
Constructor connection to the given hostname and the default port for http (80).


HttpRequester

public HttpRequester(java.lang.String hostname,
                     int port)
Constructor

Method Detail

initProxy

protected void initProxy()
Reads the proxy settings from the system's properties.


openConnection

protected void openConnection()
                       throws java.net.UnknownHostException,
                              java.io.IOException
Opens the connection to the host or to the proxy.


requestUrl

public java.util.Map requestUrl(java.net.URL url,
                                java.util.Map http_headers)
                         throws java.io.IOException
Requests the given url from the host or the proxy and uses the given headers (and no other headers!).


writeToSocket

protected void writeToSocket(java.lang.String string)
                      throws java.io.IOException

printMap

protected void printMap(java.util.Map map)