net.noderunner.http
Interface HttpClient

All Known Implementing Classes:
BasicHttpClient, RetryHttpClient

public interface HttpClient

Specifies methods for an HTTP client. Methods must be called in specific order for a successful HTTP exchange to take place. The order of calls that must be made:

If the HTTP server and client are HTTP/1.1, then of course the same output and input stream can be re-used.


Method Summary
 void close()
          Closes any underlying sockets or streams.
 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.
 void writeRequest(ClientRequest request)
          Sends the first part of a Request message, consisting of a request line and headers.
 

Method Detail

writeRequest

void writeRequest(ClientRequest request)
                  throws IOException
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 getOutputStream().

Throws:
IllegalHttpStateException - if the request was already sent and the response was not yet read
IOException

getOutputStream

OutputStream getOutputStream()
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.

Throws:
IllegalHttpStateException - if the request was not yet sent or the response was already read, data was sent with a DataPoster, or this method was already called

readResponse

ClientResponse readResponse()
                            throws IOException
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.

Throws:
IllegalHttpStateException - if the request was not yet sent
HttpException - if the server returned an invalid HTTP response
IOException

close

void close()
           throws IOException
Closes any underlying sockets or streams. May optionally release other sorts of allocated resources.

Throws:
IOException


Copyright © 2011. All Rights Reserved.