/** * Creates a new client connection operator for the given scheme registry * and the given custom DNS lookup mechanism. * * @param schemes * the scheme registry * @param dnsResolver * the custom DNS lookup mechanism */ public DefaultClientConnectionOperator(final SchemeRegistry schemes,final DnsResolver dnsResolver) { if (schemes == null) { throw new IllegalArgumentException( "Scheme registry may not be null"); } if(dnsResolver == null){ throw new IllegalArgumentException("DNS resolver may not be null"); } this.schemeRegistry = schemes; this.dnsResolver = dnsResolver; }
public PoolingClientConnectionManager(final SchemeRegistry schemeRegistry, final long timeToLive, final TimeUnit tunit, final DnsResolver dnsResolver) { super(); if (schemeRegistry == null) { throw new IllegalArgumentException("Scheme registry may not be null"); } if (dnsResolver == null) { throw new IllegalArgumentException("DNS resolver may not be null"); } this.schemeRegistry = schemeRegistry; this.dnsResolver = dnsResolver; this.operator = createConnectionOperator(schemeRegistry); this.pool = new HttpConnPool(this.log, 2, 20, timeToLive, tunit); }
@Before public void setUp() throws Exception { reactor = new NioReactor(); crusher = TcpCrusherBuilder.builder() .withReactor(reactor) .withBindAddress("127.0.0.1", CRUSHER_PORT) .withConnectAddress(REMOTE_HOST, REMOTE_PORT) .buildAndOpen(); DnsResolver dnsResolver = new SystemDefaultDnsResolver() { @Override public InetAddress[] resolve(final String host) throws UnknownHostException { if (host.equalsIgnoreCase(REMOTE_HOST)) { return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) }; } else { return super.resolve(host); } } }; HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> httpConnectionFactory = new ManagedHttpClientConnectionFactory(); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .build(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry, httpConnectionFactory, dnsResolver); http = HttpClients.createMinimal(connectionManager); }
HttpClientConnectionOperator( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); Args.notNull(socketFactoryRegistry, "Socket factory registry"); this.socketFactoryRegistry = socketFactoryRegistry; this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE; this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE; }
public BasicHttpClientConnectionManager( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); this.connectionOperator = new HttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; this.expiry = Long.MAX_VALUE; this.socketConfig = SocketConfig.DEFAULT; this.connConfig = ConnectionConfig.DEFAULT; this.isShutdown = new AtomicBoolean(false); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit tunit) { super(); this.configData = new ConfigData(); this.pool = new CPool( new InternalConnectionFactory(this.configData, connFactory), 2, 20, timeToLive, tunit); this.connectionOperator = new HttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.isShutDown = new AtomicBoolean(false); }
PoolingHttpClientConnectionManager( final CPool pool, final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); this.configData = new ConfigData(); this.pool = pool; this.connectionOperator = new HttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.isShutDown = new AtomicBoolean(false); }
@BeforeClass public static void setupProxying() { DnsResolver dnsResolver = prepareProxiedDnsResolver(); DefaultSchemePortResolver schemePortResolver = prepareSchemePortResolver(); BasicHttpClientConnectionManager connManager = prepareConnectionManager(dnsResolver, schemePortResolver); HttpClient httpClient = prepareHttpClient(connManager); originalHttpClient = (HttpClient) Options.getOption(Option.HTTPCLIENT); Unirest.setHttpClient(httpClient); }
private static BasicHttpClientConnectionManager prepareConnectionManager(DnsResolver dnsResolver, DefaultSchemePortResolver schemePortResolver) { return new BasicHttpClientConnectionManager( RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSocketFactory()) .build(), null, schemePortResolver, dnsResolver ); }
private static DnsResolver prepareProxiedDnsResolver() { return new SystemDefaultDnsResolver() { @Override public InetAddress[] resolve(String host) throws UnknownHostException { if (host.equalsIgnoreCase("sushi-shop.test")) { return new InetAddress[]{InetAddress.getByName("127.0.0.1")}; } else { return super.resolve(host); } } }; }
public JMeterPoolingClientConnectionManager(final SchemeRegistry schemeRegistry, final long timeToLive, final TimeUnit tunit, final DnsResolver dnsResolver, int validateAfterInactivity) { super(); Args.notNull(schemeRegistry, "Scheme registry"); Args.notNull(dnsResolver, "DNS resolver"); this.schemeRegistry = schemeRegistry; this.dnsResolver = dnsResolver; this.operator = createConnectionOperator(schemeRegistry); this.pool = new HttpConnPool(this.log, this.operator, 2, 20, timeToLive, tunit); pool.setValidateAfterInactivity(validateAfterInactivity); }
public PoolingClientConnectionManager(final SchemeRegistry schemeRegistry, final long timeToLive, final TimeUnit tunit, final DnsResolver dnsResolver) { super(); Args.notNull(schemeRegistry, "Scheme registry"); Args.notNull(dnsResolver, "DNS resolver"); this.schemeRegistry = schemeRegistry; this.dnsResolver = dnsResolver; this.operator = createConnectionOperator(schemeRegistry); this.pool = new HttpConnPool(this.log, this.operator, 2, 20, timeToLive, tunit); }
public BasicHttpClientConnectionManager( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { this( new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), connFactory ); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver, final long timeToLive, final TimeUnit tunit) { this( new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), connFactory, timeToLive, tunit ); }
/** * Visible for test. */ PoolingHttpClientConnectionManager( final CPool pool, final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); this.configData = new ConfigData(); this.pool = pool; this.connectionOperator = new DefaultHttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); this.isShutDown = new AtomicBoolean(false); }
public DefaultHttpClientConnectionOperator( final Lookup<ConnectionSocketFactory> socketFactoryRegistry, final SchemePortResolver schemePortResolver, final DnsResolver dnsResolver) { super(); Args.notNull(socketFactoryRegistry, "Socket factory registry"); this.socketFactoryRegistry = socketFactoryRegistry; this.schemePortResolver = schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE; this.dnsResolver = dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE; }
@SuppressWarnings("unchecked") @Before public void setup() throws Exception { conn = Mockito.mock(ManagedHttpClientConnection.class); socket = Mockito.mock(Socket.class); plainSocketFactory = Mockito.mock(ConnectionSocketFactory.class); sslSocketFactory = Mockito.mock(LayeredConnectionSocketFactory.class); socketFactoryRegistry = Mockito.mock(Lookup.class); schemePortResolver = Mockito.mock(SchemePortResolver.class); dnsResolver = Mockito.mock(DnsResolver.class); connectionOperator = new DefaultHttpClientConnectionOperator( socketFactoryRegistry, schemePortResolver, dnsResolver); }
public GalaxyFDSClient(GalaxyFDSCredential credential, FDSClientConfiguration fdsConfig, DnsResolver dnsResolver) { this.credential = credential; this.fdsConfig = fdsConfig; this.dnsResolver = dnsResolver; init(); }
public TestHttpClientDNSBlackList() { super(new BasicFDSCredential("AUTH_AK", "AUTH_SK"), defaultFdsConfig, new DnsResolver() { @Override public InetAddress[] resolve(String host) throws UnknownHostException { ++dnsResolvedCnt; return localIpAddress; } }); }
public PoolingClientConnectionManager(final SchemeRegistry schreg,final DnsResolver dnsResolver) { this(schreg, -1, TimeUnit.MILLISECONDS,dnsResolver); }
private CloseableHttpClient createHttpClient() throws NSPException { try { initSocketFactory(); DnsResolver dnsResolver = new SystemDefaultDnsResolver() { public InetAddress[] resolve(String host) throws UnknownHostException { if (host.equalsIgnoreCase("localhost")) { return new InetAddress[] { InetAddress .getByAddress(new byte[] { 127, 0, 0, 1 }) }; } return super.resolve(host); } }; PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( this.socketFactoryRegistry, dnsResolver); SocketConfig socketConfig = SocketConfig.custom() .setTcpNoDelay(true).setSoKeepAlive(true).setSoLinger(0) .setSoReuseAddress(true).build(); connManager.setDefaultSocketConfig(socketConfig); ConnectionConfig connectionConfig = ConnectionConfig.custom() .setCharset(Consts.UTF_8).build(); connManager.setDefaultConnectionConfig(connectionConfig); connManager.setConnectionConfig(new HttpHost("localhost", 80), ConnectionConfig.DEFAULT); connManager.setMaxTotal(this.mMaxConnections); if ((this.mMaxConnections <= this.mConnectionsPerRoute) && (this.mMaxConnections > 0)) { this.mConnectionsPerRoute = this.mMaxConnections; } connManager.setDefaultMaxPerRoute(this.mConnectionsPerRoute); connManager.setMaxPerRoute(new HttpRoute(new HttpHost("localhost", 80)), 100); CloseableHttpClient httpclient = HttpClients .custom() .setConnectionManager(connManager) .setDefaultRequestConfig( RequestConfig.copy(defaultRequestConfig).build()) .build(); return ((CloseableHttpClient) new WeakReference(httpclient).get()); } catch (Exception e) { throw new NSPException(2, "Service unavailable.", e); } }
public DelegatingDnsResolver(com.amazonaws.DnsResolver delegate) { this.delegate = delegate; }
public BasicHttpClientConnectionManagerWithAlternateDNS(final DnsResolver dnsResolver) { super(getDefaultRegistry(), null, null, dnsResolver); }
public DnsResolver getDnsResover() { return dnsResover; }
public void setDnsResover(DnsResolver dnsResover) { this.dnsResover = dnsResover; }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final DnsResolver dnsResolver) { this(socketFactoryRegistry, null, dnsResolver); }
public PoolingHttpClientConnectionManager( final Registry<ConnectionSocketFactory> socketFactoryRegistry, final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final DnsResolver dnsResolver) { this(socketFactoryRegistry, connFactory, null, dnsResolver, -1, TimeUnit.MILLISECONDS); }
public JMeterPoolingClientConnectionManager(final SchemeRegistry schreg,final DnsResolver dnsResolver) { this(schreg, -1, TimeUnit.MILLISECONDS,dnsResolver); }
public JMeterPoolingClientConnectionManager( final SchemeRegistry schemeRegistry, final long timeToLive, final TimeUnit tunit, final DnsResolver dnsResolver) { this(schemeRegistry, timeToLive, tunit, dnsResolver, VALIDATE_AFTER_INACTIVITY_DEFAULT); }
public MeasuringConnectionManager(SchemeRegistry schemeRegistry, DnsResolver resolver, int timeToLiveMs, int validateAfterInactivityMs) { super(schemeRegistry, timeToLiveMs, TimeUnit.MILLISECONDS, resolver, validateAfterInactivityMs); }