List of usage examples for org.apache.http.nio.client.methods HttpAsyncMethods createGet
public static HttpAsyncRequestProducer createGet(final String requestURI)
From source file:com.boonya.http.async.examples.nio.client.AsyncClientHttpExchangeStreaming.java
public static void main(final String[] args) throws Exception { CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); try {/*w w w. jav a2s. c o m*/ httpclient.start(); Future<Boolean> future = httpclient.execute(HttpAsyncMethods.createGet("http://localhost:8080/"), new MyResponseConsumer(), null); Boolean result = future.get(); if (result != null && result.booleanValue()) { System.out.println("Request successfully executed"); } else { System.out.println("Request failed"); } System.out.println("Shutting down"); } finally { httpclient.close(); } System.out.println("Done"); }
From source file:rx.apache.http.examples.ExampleObservableHttp.java
public static void main(String args[]) { CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); // final RequestConfig requestConfig = RequestConfig.custom() // .setSocketTimeout(3000) // .setConnectTimeout(3000).build(); // final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom() // .setDefaultRequestConfig(requestConfig) // .setMaxConnPerRoute(20) // .setMaxConnTotal(50) // .build(); try {/*from w w w . ja v a 2 s . c o m*/ httpclient.start(); executeViaObservableHttpWithForEach(httpclient); executeStreamingViaObservableHttpWithForEach(httpclient); } catch (Exception e) { e.printStackTrace(); } finally { try { httpclient.close(); } catch (IOException e1) { e1.printStackTrace(); } } CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault(); ObservableHttp.createGet("http://www.wikipedia.com", httpClient).toObservable(); ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), httpClient) .toObservable(); }
From source file:org.opendaylight.fpc.utils.eventStream.EventClient.java
/** * Send HttpRequest to Client/*from w w w. j av a 2s . c o m*/ * @param uri - FPC Client Uri */ public void connectToClient(String uri) { this.clientUri = uri; try { client.start(); HttpAsyncRequestProducer get = HttpAsyncMethods.createGet(this.clientUri); client.execute(get, new MyResponseConsumer(this.clientUri), null); } catch (Exception e) { ErrorLog.logError(e.getStackTrace()); } }
From source file:rx.apache.http.examples.ExampleObservableHttp.java
protected static void executeViaObservableHttpWithForEach(final HttpAsyncClient client) throws URISyntaxException, IOException, InterruptedException { System.out.println("---- executeViaObservableHttpWithForEach"); ObservableHttp.createRequest(HttpAsyncMethods.createGet("http://www.wikipedia.com"), client).toObservable() .flatMap(new Func1<ObservableHttpResponse, Observable<String>>() { @Override//from ww w . ja va2 s . co m public Observable<String> call(ObservableHttpResponse response) { return response.getContent().map(new Func1<byte[], String>() { @Override public String call(byte[] bb) { return new String(bb); } }); } }).toBlockingObservable().forEach(new Action1<String>() { @Override public void call(String resp) { System.out.println(resp); } }); }
From source file:rx.apache.http.ObservableHttp.java
public static ObservableHttp<ObservableHttpResponse> createGet(String uri, final HttpAsyncClient client) { return createRequest(HttpAsyncMethods.createGet(uri), client); }
From source file:rx.apache.http.examples.ExampleObservableHttp.java
protected static void executeStreamingViaObservableHttpWithForEach(final HttpAsyncClient client) throws URISyntaxException, IOException, InterruptedException { System.out.println("---- executeStreamingViaObservableHttpWithForEach"); // URL against https://github.com/Netflix/Hystrix/tree/master/hystrix-examples-webapp // More information at https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-metrics-event-stream ObservableHttp.createRequest(//from www .jav a 2 s . c o m HttpAsyncMethods.createGet("http://localhost:8989/hystrix-examples-webapp/hystrix.stream"), client) .toObservable().flatMap(new Func1<ObservableHttpResponse, Observable<String>>() { @Override public Observable<String> call(ObservableHttpResponse response) { return response.getContent().map(new Func1<byte[], String>() { @Override public String call(byte[] bb) { return new String(bb); } }); } }).filter(new Func1<String, Boolean>() { @Override public Boolean call(String t1) { return !t1.startsWith(": ping"); } }).take(3).toBlockingObservable().forEach(new Action1<String>() { @Override public void call(String resp) { System.out.println(resp); } }); }