Package org.apache.http.conn

Examples of org.apache.http.conn.DnsResolver


        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.INSTANCE)
                .register("https", new SSLConnectionSocketFactory(fetcher.sslContext(), new AllowAllHostnameVerifier()))
                .build();

        DnsResolver dnsResolver = new ServerCacheResolver(fetcher.getServerCache());

        ManagedHttpClientConnectionFactory connFactory = new ManagedHttpClientConnectionFactory(){
            private static final int DEFAULT_BUFSIZE = 8 * 1024;

            @Override
View Full Code Here


            .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

@Deprecated
public class TestDefaultClientConnectOperator {

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

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

        final 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 {
        final DnsResolver dnsResolver = mock(DnsResolver.class);
        when(dnsResolver.resolve("unknown.example.com")).thenThrow(new UnknownHostException());

        final DefaultClientConnectionOperator operator = new DefaultClientConnectionOperator(
                SchemeRegistryFactory.createDefault(), dnsResolver);
        operator.resolveHostname("unknown.example.com");
    }
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.