Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.SystemDefaultHttpClient


    private static HttpClient ensureClient(HttpClient client, HttpAuthenticator auth) {
        if ( client != null )
            return client ;
        if ( defaultHttpClient != null && auth == null )
            return defaultHttpClient ;
        return new SystemDefaultHttpClient() ;
    }
View Full Code Here


            if (defaultHttpClient == null) {
                // Uses Apache SystemDefaultHttpClient rather than
                // DefaultHttpClient, thus the normal proxy settings for the
                // JVM will be used

                final DefaultHttpClient client = new SystemDefaultHttpClient();
                // Support compressed data
                // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
                client.addRequestInterceptor(new RequestAcceptEncoding());
                client.addResponseInterceptor(new ResponseContentEncoding());
                final CacheConfig cacheConfig = new CacheConfig();
                cacheConfig.setMaxObjectSize(1024 * 128); // 128 kB
                cacheConfig.setMaxCacheEntries(1000);
                // and allow caching
                final CachingHttpClient cachingClient = new CachingHttpClient(client, cacheConfig);
View Full Code Here

public class JarCacheTest {

    @Test
    public void cacheHit() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/ld+json", resp.getEntity().getContentType().getValue());
View Full Code Here

    }

    @Test(expected = IOException.class)
    public void cacheMiss() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/notfound");
        // Should throw an IOException as the DNS name
        // nonexisting.example.com does not exist
        final HttpResponse resp = httpClient.execute(get);
View Full Code Here

    }

    @Test
    public void doubleLoad() throws Exception {
        final JarCacheStorage storage = new JarCacheStorage();
        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        HttpResponse resp = httpClient.execute(get);
        resp = httpClient.execute(get);
        // Ensure second load through the cached jarcache list works
View Full Code Here

    public void customClassPath() throws Exception {
        final URL nestedJar = getClass().getResource("/nested.jar");
        final ClassLoader cl = new URLClassLoader(new URL[] { nestedJar });
        final JarCacheStorage storage = new JarCacheStorage(cl);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/nested/hello");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/json", resp.getEntity().getContentType().getValue());
View Full Code Here

        final ClassLoader cl = new URLClassLoader(new URL[] { nestedJar });

        final JarCacheStorage storage = new JarCacheStorage();
        Thread.currentThread().setContextClassLoader(cl);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/nested/hello");
        final HttpResponse resp = httpClient.execute(get);

        assertEquals("application/json", resp.getEntity().getContentType().getValue());
View Full Code Here

    public void systemClassLoader() throws Exception {
        final URL nestedJar = getClass().getResource("/nested.jar");
        assertNotNull(nestedJar);
        final JarCacheStorage storage = new JarCacheStorage(null);

        final HttpClient httpClient = new CachingHttpClient(new SystemDefaultHttpClient(), storage,
                storage.getCacheConfig());
        final HttpGet get = new HttpGet("http://nonexisting.example.com/context");
        final HttpResponse resp = httpClient.execute(get);
        assertEquals("application/ld+json", resp.getEntity().getContentType().getValue());
    }
View Full Code Here

    }

    @Test
    public void differentHttpClient() throws Exception {
        // Custom http client
        documentLoader.setHttpClient(new SystemDefaultHttpClient());
        assertNotSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient());

        // Use default again
        documentLoader.setHttpClient(null);
        assertSame(documentLoader.getHttpClient(), new DocumentLoader().getHttpClient());
View Full Code Here

                    // Uses Apache SystemDefaultHttpClient rather than
                    // DefaultHttpClient, thus the normal proxy settings for the
                    // JVM
                    // will be used

                    final DefaultHttpClient client = new SystemDefaultHttpClient();
                    // Support compressed data
                    // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html#d5e1238
                    client.addRequestInterceptor(new RequestAcceptEncoding());
                    client.addResponseInterceptor(new ResponseContentEncoding());
                    final CacheConfig cacheConfig = new CacheConfig();
                    cacheConfig.setMaxObjectSize(1024 * 128); // 128 kB
                    cacheConfig.setMaxCacheEntries(1000);
                    // and allow caching
                    httpClient = new CachingHttpClient(client, cacheConfig);
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.SystemDefaultHttpClient

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.