List of usage examples for org.apache.http.impl.nio.client DefaultHttpAsyncClient DefaultHttpAsyncClient
public DefaultHttpAsyncClient() throws IOReactorException
From source file:com.example.AsyncClientHttpExchangeFutureCallback.java
public static void main(String[] args) throws Exception { HttpAsyncClient httpclient = new DefaultHttpAsyncClient(); httpclient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 3000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); httpclient.start();// w w w. j a v a 2s.c om try { HttpGet[] requests = new HttpGet[] { new HttpGet("http://www.apache.org/"), new HttpGet("https://www.verisign.com/"), new HttpGet("http://www.google.com/") }; final CountDownLatch latch = new CountDownLatch(requests.length); for (final HttpGet request : requests) { httpclient.execute(request, new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); System.out.println(request.getRequestLine() + "->" + response.getStatusLine()); } public void failed(final Exception ex) { latch.countDown(); System.out.println(request.getRequestLine() + "->" + ex); } public void cancelled() { latch.countDown(); System.out.println(request.getRequestLine() + " cancelled"); } }); } latch.await(); System.out.println("Shutting down"); } finally { httpclient.shutdown(); } System.out.println("Done"); }
From source file:com.example.AsyncClientHttpExchange.java
public static void main(String[] args) throws Exception { HttpAsyncClient httpclient = new DefaultHttpAsyncClient(); httpclient.start();/*from w w w . j a va2 s .c o m*/ try { ArrayList<Future<HttpResponse>> response = new ArrayList<Future<HttpResponse>>(); ArrayList<String> sites = new ArrayList<String>(); sites.add("MLA"); sites.add("MLB"); sites.add("MLU"); sites.add("MLV"); for (String site : sites) { HttpGet request = new HttpGet("https://api.mercadolibre.com/sites/" + site); Future<HttpResponse> r = httpclient.execute(request, null); response.add(r); } System.out.println("lalala........"); System.out.println("lalala........"); System.out.println("lalala........"); for (Future<HttpResponse> future : response) { HttpResponse r = future.get(); System.out.println("Response: " + r.getStatusLine()); System.out.println("Body : " + convertStreamToString(r.getEntity().getContent())); } } finally { httpclient.shutdown(); } System.out.println("Done"); }
From source file:org.openstack.burrow.backend.http.AsyncHttp.java
/** * Constructor for AsyncHttp that takes a host name and a port number as * arguments/* ww w .j a v a 2 s . c om*/ * * @param host A host name as a String * @param port A port number as an int * @throws IOReactorException Thrown if a issue in starting the * DefaultHttpAsyncClient */ public AsyncHttp(String host, int port) throws IOReactorException { super(host, port); this.client = new DefaultHttpAsyncClient(); // TODO: Move this into a Backend.start() method this.client.start(); }
From source file:org.apache.servicemix.wsn.jms.JmsSubscription.java
public JmsSubscription(String name) { super(name);// w w w. j av a 2 s . c om // factory = new JaxWsProxyFactoryBean(); topicConverter = new JmsTopicExpressionConverter(); if (asyClient == null) { try { asyClient = new DefaultHttpAsyncClient(); } catch (IOReactorException e) { // TODO Auto-generated catch block e.printStackTrace(); } asyClient.start(); } for (int i = asyClientList.size(); i < 5; i++) { try { HttpAsyncClient asyCli = new DefaultHttpAsyncClient(); asyCli.start(); asyClientList.add(asyCli); } catch (IOReactorException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // notifyObserver = new NotifyObserver(); // notifyObserver.addObserver(RtMgr.getInstance()); // pool1 = Executors.newFixedThreadPool(5); //? // pool2 = Executors.newFixedThreadPool(5); //? // pool1 = new ThreadPool(2); // pool2 = new ThreadPool(30); // r = new PushClient(); }
From source file:iqq.im.service.ApacheHttpService.java
@Override public void init(QQContext context) throws QQException { super.init(context); try {/*from w w w . java 2 s . c o m*/ SSLContext sslContext = new QQSSLSocketFactory().getSSLContext(); SSLContext.setDefault(sslContext); asyncHttpClient = new DefaultHttpAsyncClient(); HttpParams httpParams = asyncHttpClient.getParams(); HttpConnectionParams.setSoTimeout(httpParams, QQConstants.HTTP_TIME_OUT); HttpConnectionParams.setConnectionTimeout(httpParams, QQConstants.HTTP_TIME_OUT); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, 4096); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); asyncHttpClient.getConnectionManager().getSchemeRegistry() .register(new AsyncScheme("https", 443, new SSLLayeringStrategy(sslContext))); asyncHttpClient.setRedirectStrategy(new QQDefaultRedirectStrategy()); asyncHttpClient.start(); cookieJar = new QQHttpCookieJar(); } catch (IOReactorException e) { throw new QQException(QQErrorCode.INIT_ERROR, e); } }
From source file:com.minws.frame.sdk.webqq.service.ApacheHttpService.java
/** {@inheritDoc} */ @Override//from w w w .j a va2 s. com public void init(QQContext context) throws QQException { super.init(context); try { SSLContext sslContext = new QQSSLSocketFactory().getSSLContext(); SSLContext.setDefault(sslContext); asyncHttpClient = new DefaultHttpAsyncClient(); HttpParams httpParams = asyncHttpClient.getParams(); HttpConnectionParams.setSoTimeout(httpParams, QQConstants.HTTP_TIME_OUT); HttpConnectionParams.setConnectionTimeout(httpParams, QQConstants.HTTP_TIME_OUT); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, 4096); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); asyncHttpClient.getConnectionManager().getSchemeRegistry() .register(new AsyncScheme("https", 443, new SSLLayeringStrategy(sslContext))); asyncHttpClient.setRedirectStrategy(new QQDefaultRedirectStrategy()); asyncHttpClient.start(); cookieJar = new QQHttpCookieJar(); } catch (IOReactorException e) { throw new QQException(QQErrorCode.INIT_ERROR, e); } }