Difference between revisions of "Jetty/Tutorial/HttpClient"

From Eclipsepedia

Jump to: navigation, search
Line 9: Line 9:
 
Instead, the request is sent concurrently to your code, and the response is interpreted also concurrently with your code.
 
Instead, the request is sent concurrently to your code, and the response is interpreted also concurrently with your code.
  
The HttpClient API offers you '''callbacks''' to interact with the request-response lifecycle.  
+
The HttpClient API offers you ''callbacks'' to interact with the request-response lifecycle.  
 
These callbacks will be called by the HttpClient implementation to allow further actions to be performed during each request-response event.
 
These callbacks will be called by the HttpClient implementation to allow further actions to be performed during each request-response event.
  
 +
A request-response unit is called ''exchange'', and represent the exchange of information with the HTTP server.
 +
 +
There are two main classes in the HttpClient API:
 +
* <tt>org.eclipse.jetty.client.HttpClient</tt>, which manages the thread pooling, the proxy setting, the authentication settings, the connector type (blocking or non-blocking), the SSL settings and the timeouts. <tt>HttpClient</tt> manages the configuration that does not depend on a particular exchange.
 +
* <tt>org.eclipse.jetty.client.HttpExchange</tt>, which is the base class that you normally have to subclass that represent the exchange with the HTTP server, and manages HTTP method, the request URI, HTTP headers, request content, HTTP response code, HTTP response headers and response content.
 +
 +
 
}}
 
}}

Revision as of 05:06, 15 September 2009



Introduction

HttpClient is the Jetty component that allows to make requests and interpret responses to HTTP servers.

This tutorial takes you through the steps necessary to use the HttpClient in the most effective way.

Details

The HttpClient is by its nature asynchronous. This means that the code that sends the request does not wait for the response to arrive before continuing. Instead, the request is sent concurrently to your code, and the response is interpreted also concurrently with your code.

The HttpClient API offers you callbacks to interact with the request-response lifecycle. These callbacks will be called by the HttpClient implementation to allow further actions to be performed during each request-response event.

A request-response unit is called exchange, and represent the exchange of information with the HTTP server.

There are two main classes in the HttpClient API:

  • org.eclipse.jetty.client.HttpClient, which manages the thread pooling, the proxy setting, the authentication settings, the connector type (blocking or non-blocking), the SSL settings and the timeouts. HttpClient manages the configuration that does not depend on a particular exchange.
  • org.eclipse.jetty.client.HttpExchange, which is the base class that you normally have to subclass that represent the exchange with the HTTP server, and manages HTTP method, the request URI, HTTP headers, request content, HTTP response code, HTTP response headers and response content.