rx.apache.http
Class ObservableHttp<T>

java.lang.Object
  extended by rx.apache.http.ObservableHttp<T>
Type Parameters:
T -

public class ObservableHttp<T>
extends java.lang.Object

An Observable interface to Apache HttpAsyncClient.

The initial HttpResponse is returned via Observer.onNext(T) wrapped in a ObservableHttpResponse.

The content stream is retrieved from ObservableHttpResponse.getContent().

It is aware of Content-Type text/event-stream and will stream each event via Observer.onNext(T).

Other Content-Types will be returned as a single call to Observer.onNext(T).

Examples:

 ObservableHttp.createGet("http://www.wikipedia.com", httpClient).toObservable();
  

 ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), httpClient).toObservable();
  
An HttpClient can be created like this:
 CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
 httpClient.start(); // start it
 httpClient.stop(); // stop it
  

A client with custom configurations can be created like this:

 final RequestConfig requestConfig = RequestConfig.custom()
     .setSocketTimeout(1000)
     .setConnectTimeout(200).build();
 final CloseableHttpAsyncClient httpClient = HttpAsyncClients.custom()
     .setDefaultRequestConfig(requestConfig)
     .setMaxConnPerRoute(20)
     .setMaxConnTotal(50)
     .build();
 httpClient.start();
 


Method Summary
static ObservableHttp<ObservableHttpResponse> createGet(java.lang.String uri, org.apache.http.nio.client.HttpAsyncClient client)
           
static ObservableHttp<ObservableHttpResponse> createRequest(org.apache.http.nio.protocol.HttpAsyncRequestProducer requestProducer, org.apache.http.nio.client.HttpAsyncClient client)
          Execute request using HttpAsyncRequestProducer to define HTTP Method, URI and payload (if applicable).
static ObservableHttp<ObservableHttpResponse> createRequest(org.apache.http.nio.protocol.HttpAsyncRequestProducer requestProducer, org.apache.http.nio.client.HttpAsyncClient client, org.apache.http.protocol.HttpContext context)
          Execute request using HttpAsyncRequestProducer to define HTTP Method, URI and payload (if applicable).
 rx.Observable<T> toObservable()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toObservable

public rx.Observable<T> toObservable()

createGet

public static ObservableHttp<ObservableHttpResponse> createGet(java.lang.String uri,
                                                               org.apache.http.nio.client.HttpAsyncClient client)

createRequest

public static ObservableHttp<ObservableHttpResponse> createRequest(org.apache.http.nio.protocol.HttpAsyncRequestProducer requestProducer,
                                                                   org.apache.http.nio.client.HttpAsyncClient client)
Execute request using HttpAsyncRequestProducer to define HTTP Method, URI and payload (if applicable).

If the response is chunked (or flushed progressively such as with text/event-stream Server-Sent Events) this will call Observer.onNext(T) multiple times.

Use HttpAsyncMethods.create* factory methods to create HttpAsyncRequestProducer instances.

A client can be retrieved like this:

 CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();  

A client with custom configurations can be created like this:

 final RequestConfig requestConfig = RequestConfig.custom()
     .setSocketTimeout(3000)
     .setConnectTimeout(3000).build();
 final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
     .setDefaultRequestConfig(requestConfig)
     .setMaxConnPerRoute(20)
     .setMaxConnTotal(50)
     .build();
 httpclient.start();
 

Parameters:
requestProducer -
client -
Returns:

createRequest

public static ObservableHttp<ObservableHttpResponse> createRequest(org.apache.http.nio.protocol.HttpAsyncRequestProducer requestProducer,
                                                                   org.apache.http.nio.client.HttpAsyncClient client,
                                                                   org.apache.http.protocol.HttpContext context)
Execute request using HttpAsyncRequestProducer to define HTTP Method, URI and payload (if applicable).

If the response is chunked (or flushed progressively such as with text/event-stream Server-Sent Events) this will call Observer.onNext(T) multiple times.

Use HttpAsyncMethods.create* factory methods to create HttpAsyncRequestProducer instances.

A client can be retrieved like this:

 CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();  

A client with custom configurations can be created like this:

 final RequestConfig requestConfig = RequestConfig.custom()
     .setSocketTimeout(3000)
     .setConnectTimeout(3000).build();
 final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
     .setDefaultRequestConfig(requestConfig)
     .setMaxConnPerRoute(20)
     .setMaxConnTotal(50)
     .build();
 httpclient.start();
 

Parameters:
requestProducer -
client -
context - The HttpContext
Returns: