net.noderunner.http
Class BasicHttpClient

java.lang.Object
  extended by net.noderunner.http.BasicHttpClient
All Implemented Interfaces:
HttpClient

public class BasicHttpClient
extends java.lang.Object
implements HttpClient

A very basic HTTP client implementation.


Constructor Summary
BasicHttpClient(java.io.OutputStream os, java.io.InputStream is)
          Constructs a BasicHttpClient that communicates over input and output streams.
BasicHttpClient(java.net.Socket socket)
          Constructs a BasicHttpClient that communicates over a socket.
 
Method Summary
 void close()
          Closes the underlying input and output streams.
 java.io.OutputStream getOutputStream()
          Returns a stream for writing data to, if data is to be sent to the server.
 ClientResponse readResponse()
          Reads the response data from the HTTP server.
 java.lang.String toString()
          Returns debug information.
 void writeRequest(ClientRequest request)
          Sends the first part of a Request message, consisting of a request line and headers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicHttpClient

public BasicHttpClient(java.net.Socket socket)
                throws java.io.IOException
Constructs a BasicHttpClient that communicates over a socket. By default, wraps the input stream created in a BufferedInputStream. The output stream is unbuffered.

Throws:
java.io.IOException

BasicHttpClient

public BasicHttpClient(java.io.OutputStream os,
                       java.io.InputStream is)
Constructs a BasicHttpClient that communicates over input and output streams.

Method Detail

writeRequest

public void writeRequest(ClientRequest request)
                  throws java.io.IOException
Description copied from interface: HttpClient
Sends the first part of a Request message, consisting of a request line and headers. The message body may be sent in one of two ways:
  1. By returning a DataPoster in the client request object.
  2. Or, by using the stream returned by HttpClient.getOutputStream().

Specified by:
writeRequest in interface HttpClient
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
Description copied from interface: HttpClient
Returns a stream for writing data to, if data is to be sent to the server. For some HTTP methods, like GET, calling this method of course makes little sense. Data must be sent if content-length or transfer encoding headers were sent. This stream should be wrapped to control output based on the headers specified in the request.

Specified by:
getOutputStream in interface HttpClient

readResponse

public ClientResponse readResponse()
                            throws java.io.IOException
Description copied from interface: HttpClient
Reads the response data from the HTTP server. This commits the output stream and reads the response from the input stream. If data is being sent by the HTTP server, it must be read fully before another request can be accepted.

Specified by:
readResponse in interface HttpClient
Throws:
HttpException - if the server returned an invalid HTTP response
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the underlying input and output streams.

Specified by:
close in interface HttpClient
Throws:
java.io.IOException

toString

public java.lang.String toString()
Returns debug information.

Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.