Package org.apache.http.conn

Examples of org.apache.http.conn.DnsResolver


            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", new SSLConnectionSocketFactory(sslcontext))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here


            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here

            .register("http", PlainSocketFactory.INSTANCE)
            .register("https", new SSLSocketFactory(sslcontext, hostnameVerifier))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here

            .register("http", NoopIOSessionStrategy.INSTANCE)
            .register("https", new SSLIOSessionStrategy(sslcontext, hostnameVerifier))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here

public class TestDefaultClientConnectOperator {

    @Test
    public void testCustomDnsResolver() throws Exception {
        DnsResolver dnsResolver = mock(DnsResolver.class);
        InetAddress[] firstAddress = translateIp("192.168.1.1");
        when(dnsResolver.resolve("somehost.example.com")).thenReturn(firstAddress);

        InetAddress[] secondAddress = translateIp("192.168.12.16");
        when(dnsResolver.resolve("otherhost.example.com")).thenReturn(secondAddress);

        DefaultClientConnectionOperator operator = new DefaultClientConnectionOperator(
                SchemeRegistryFactory.createDefault(), dnsResolver);

        Assert.assertArrayEquals(firstAddress, operator.resolveHostname("somehost.example.com"));
View Full Code Here

        Assert.assertArrayEquals(secondAddress, operator.resolveHostname("otherhost.example.com"));
    }

    @Test(expected=UnknownHostException.class)
    public void testDnsResolverUnknownHost() throws Exception {
        DnsResolver dnsResolver = mock(DnsResolver.class);
        when(dnsResolver.resolve("unknown.example.com")).thenThrow(new UnknownHostException());

        DefaultClientConnectionOperator operator = new DefaultClientConnectionOperator(
                SchemeRegistryFactory.createDefault(), dnsResolver);
        operator.resolveHostname("unknown.example.com");
    }
View Full Code Here

        assertThat(spyHttpClientBuilderField("userAgent", apacheBuilder)).isEqualTo("qwerty");
    }

    @Test
    public void canUseACustomDnsResolver() throws Exception {
        final DnsResolver resolver = mock(DnsResolver.class);
        final InstrumentedHttpClientConnectionManager manager =
                builder.using(resolver).createConnectionManager(registry, "test");

        // Yes, this is gross. Thanks, Apache!
        final Field connectionOperatorField =
View Full Code Here

            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here

            .register("http", PlainSocketFactory.INSTANCE)
            .register("https", new SSLSocketFactory(sslcontext, hostnameVerifier))
            .build();

        // Use custom DNS resolver to override the system DNS resolution.
        DnsResolver dnsResolver = new SystemDefaultDnsResolver() {

            @Override
            public InetAddress[] resolve(final String host) throws UnknownHostException {
                if (host.equalsIgnoreCase("myhost")) {
                    return new InetAddress[] { InetAddress.getByAddress(new byte[] {127, 0, 0, 1}) };
View Full Code Here

        if (httpClient == null){ // One-time init for this client

            HttpParams clientParams = new DefaultedHttpParams(new BasicHttpParams(), DEFAULT_HTTP_PARAMS);

            DnsResolver resolver = this.testElement.getDNSResolver();
            if (resolver == null) {
                resolver = new SystemDefaultDnsResolver();
            }
            PoolingClientConnectionManager poolingClientConnectionManager = new PoolingClientConnectionManager(
                    SchemeRegistryFactory.createDefault(), resolver);
View Full Code Here

TOP

Related Classes of org.apache.http.conn.DnsResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.