List of usage examples for org.apache.http.impl.nio.reactor IOReactorConfig DEFAULT
IOReactorConfig DEFAULT
To view the source code for org.apache.http.impl.nio.reactor IOReactorConfig DEFAULT.
Click Source Link
From source file:com.ok2c.lightmtp.examples.SendMailExample.java
public static void main(final String[] args) throws Exception { if (args.length < 3) { System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file"); System.exit(0);/*from w w w . j a v a2 s .c om*/ } String sender = args[0]; List<String> recipients = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(args[1], ";"); while (tokenizer.hasMoreTokens()) { String s = tokenizer.nextToken(); s = s.trim(); if (s.length() > 0) { recipients.add(s); } } File src = new File(args[2]); if (!src.exists()) { System.out.println("File '" + src + "' does not exist"); System.exit(0); } DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src)); MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT); mua.start(); try { InetSocketAddress address = new InetSocketAddress("localhost", 2525); Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null); DeliveryResult result = future.get(); System.out.println("Delivery result: " + result); } finally { mua.shutdown(); } }
From source file:com.ok2c.lightmtp.examples.MailUserAgentExample.java
public static void main(final String[] args) throws Exception { String text1 = "From: root\r\n" + "To: testuser1\r\n" + "Subject: test message 1\r\n" + "\r\n" + "This is a short test message 1\r\n"; String text2 = "From: root\r\n" + "To: testuser1, testuser2\r\n" + "Subject: test message 2\r\n" + "\r\n" + "This is a short test message 2\r\n"; String text3 = "From: root\r\n" + "To: testuser1, testuser2, testuser3\r\n" + "Subject: test message 3\r\n" + "\r\n" + "This is a short test message 3\r\n"; List<DeliveryRequest> requests = new ArrayList<DeliveryRequest>(); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1"), new ByteArraySource(text1.getBytes("US-ASCII")))); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2"), new ByteArraySource(text2.getBytes("US-ASCII")))); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2", "testuser3"), new ByteArraySource(text3.getBytes("US-ASCII")))); MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT); mua.start();/*from ww w . java 2 s . c o m*/ try { InetSocketAddress address = new InetSocketAddress("localhost", 2525); Queue<Future<DeliveryResult>> queue = new LinkedList<Future<DeliveryResult>>(); for (DeliveryRequest request : requests) { queue.add(mua.deliver(new SessionEndpoint(address), 0, request, null)); } while (!queue.isEmpty()) { Future<DeliveryResult> future = queue.remove(); DeliveryResult result = future.get(); System.out.println("Delivery result: " + result); } } finally { mua.shutdown(); } }
From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpAsyncClientItem.java
private static PoolingNHttpClientConnectionManager buildAsyncConnectionManager(HttpClientConfig config, SSLContext sslContext) {/* w w w . j a v a 2 s . c o m*/ // scheme configuration SchemeIOSessionStrategy sslSocketFactory = new SSLIOSessionStrategy(sslContext); Registry<SchemeIOSessionStrategy> asyncSchemeRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create() .register("http", NoopIOSessionStrategy.INSTANCE).register("https", sslSocketFactory).build(); // pooling settings ConnectingIOReactor ioreactor; try { ioreactor = new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT); } catch (IOReactorException ex) { throw new RuntimeException("Unable to initialize IO reactor.", ex); } PoolingNHttpClientConnectionManager conmgr = new PoolingNHttpClientConnectionManager(ioreactor, asyncSchemeRegistry); conmgr.setMaxTotal(config.getMaxTotalConnections()); conmgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerHost()); return conmgr; }
From source file:com.orange.ngsi.client.HttpConfiguration.java
@Bean PoolingNHttpClientConnectionManager poolingNHttpClientConnectionManager() throws IOReactorException { PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager( new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT)); connectionManager.setMaxTotal(maxTotalConnections); connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute); return connectionManager; }
From source file:org.apache.metron.elasticsearch.client.ElasticsearchClientFactory.java
/** * Creates config with setting for num connection threads. Default is ES client default, * which is 1 to num processors per the documentation. * https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_number_of_threads.html *///w ww . j a v a 2 s .co m private static IOReactorConfig getIOReactorConfig(ElasticsearchClientConfig esClientConfig) { if (esClientConfig.getNumClientConnectionThreads().isPresent()) { Integer numThreads = esClientConfig.getNumClientConnectionThreads().get(); LOG.info("Setting number of client connection threads: {}", numThreads); return IOReactorConfig.custom().setIoThreadCount(numThreads).build(); } else { return IOReactorConfig.DEFAULT; } }
From source file:net.tirasa.wink.client.asynchttpclient.ApacheHttpAsyncClientConnectionHandler.java
private synchronized CloseableHttpAsyncClient openConnection(ClientRequest request) throws NoSuchAlgorithmException, KeyManagementException, IOException { if (this.httpclient != null) { return this.httpclient; }//from www . java 2 s. c o m HttpAsyncClientBuilder clientBuilder = HttpAsyncClientBuilder.create(); // cast is safe because we're on the client ApacheHttpAsyncClientConfig config = (ApacheHttpAsyncClientConfig) request .getAttribute(WinkConfiguration.class); RequestConfig.Builder requestConfigBuilder = RequestConfig.custom() .setConnectTimeout(config.getConnectTimeout()).setSocketTimeout(config.getReadTimeout()); if (config.isFollowRedirects()) { requestConfigBuilder.setRedirectsEnabled(true).setCircularRedirectsAllowed(true); } // setup proxy if (config.getProxyHost() != null) { requestConfigBuilder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort())); } clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); Registry<SchemeIOSessionFactory> connManagerRegistry; if (config.getBypassHostnameVerification()) { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, null, null); connManagerRegistry = RegistryBuilder.<SchemeIOSessionFactory>create() .register("http", PlainIOSessionFactory.INSTANCE) .register("https", new SSLIOSessionFactory(sslcontext, new X509HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } @Override public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } @Override public void verify(String host, X509Certificate cert) throws SSLException { } @Override public void verify(String host, SSLSocket ssl) throws IOException { } })).build(); } else { connManagerRegistry = RegistryBuilder.<SchemeIOSessionFactory>create() .register("http", PlainIOSessionFactory.INSTANCE) .register("https", SSLIOSessionFactory.getDefaultStrategy()).build(); } PoolingNHttpClientConnectionManager httpConnectionManager = new PoolingNHttpClientConnectionManager( new DefaultConnectingIOReactor(IOReactorConfig.DEFAULT), connManagerRegistry); if (config.getMaxPooledConnections() > 0) { httpConnectionManager.setMaxTotal(config.getMaxPooledConnections()); httpConnectionManager.setDefaultMaxPerRoute(config.getMaxPooledConnections()); } clientBuilder.setConnectionManager(httpConnectionManager); this.httpclient = clientBuilder.build(); this.httpclient.start(); return this.httpclient; }