Example usage for org.apache.http.impl.client.cache FileResourceFactory FileResourceFactory

List of usage examples for org.apache.http.impl.client.cache FileResourceFactory FileResourceFactory

Introduction

In this page you can find the example usage for org.apache.http.impl.client.cache FileResourceFactory FileResourceFactory.

Prototype

public FileResourceFactory(final File cacheDir) 

Source Link

Usage

From source file:org.eclipse.thym.core.engine.internal.cordova.DefaultEngineRepoProvider.java

private InputStream getRemoteJSonStream() {
    BundleContext context = HybridCore.getContext();
    DefaultHttpClient defHttpClient = new DefaultHttpClient();
    HttpUtil.setupProxy(defHttpClient);//w w w. ja va 2 s  .  c o  m

    HttpClient client = new CachingHttpClient(defHttpClient,
            new FileResourceFactory(context.getDataFile(BundleHttpCacheStorage.SUBDIR_HTTP_CACHE)),
            new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), cacheConfig());
    HttpGet get = new HttpGet(REPO_JSON_URL);
    HttpResponse response;
    try {
        response = client.execute(get);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        return stream;
    } catch (IOException e) {
        HybridCore.log(IStatus.WARNING,
                NLS.bind("Could not retrieve the json from remote URL ({0})", REPO_JSON_URL), e);
    }
    return null;
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java

public CordovaRegistryPlugin getCordovaPluginInfo(String name) throws CoreException {

    CordovaRegistryPlugin plugin = detailedPluginInfoCache.get(name);
    if (plugin != null)
        return plugin;
    BundleContext context = HybridCore.getContext();
    HttpClient client = new CachingHttpClient(new DefaultHttpClient(),
            new FileResourceFactory(context.getDataFile(BundleHttpCacheStorage.SUBDIR_HTTP_CACHE)),
            new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), getCacheConfig());
    String url = registry.endsWith("/") ? registry + name : registry + "/" + name;
    HttpGet get = new HttpGet(url);
    HttpResponse response;/*from w w  w. j  a  v a2s .c o m*/
    try {
        response = client.execute(get);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        JsonReader reader = new JsonReader(new InputStreamReader(stream));
        plugin = new CordovaRegistryPlugin();
        readPluginInfo(reader, plugin);
        this.detailedPluginInfoCache.put(name, plugin);
        return plugin;
    } catch (ClientProtocolException e) {
        throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID,
                "Can not retrieve plugin information for " + name, e));
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, HybridCore.PLUGIN_ID,
                "Can not retrieve plugin information for " + name, e));
    }

}

From source file:org.callimachusproject.client.HttpClientFactory.java

private HttpClientFactory(File cacheDir) throws IOException {
    cacheDir.mkdirs();/*from  w w  w. ja  v a  2s . c  o m*/
    entryFactory = new FileResourceFactory(cacheDir);
    decorator = new ProxyClientExecDecorator();
    LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory();
    connManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslSocketFactory).build());
    connManager.setDefaultSocketConfig(getDefaultSocketConfig());
    connManager.setDefaultConnectionConfig(getDefaultConnectionConfig());
    int max = Integer.parseInt(System.getProperty("http.maxConnections", "20"));
    connManager.setDefaultMaxPerRoute(max);
    connManager.setMaxTotal(2 * max);
    reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
    keepAliveStrategy = new ConnectionKeepAliveStrategy() {
        private final long KEEPALIVE = SystemProperties.getClientKeepAliveTimeout();
        private ConnectionKeepAliveStrategy delegate = DefaultConnectionKeepAliveStrategy.INSTANCE;

        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            long ret = delegate.getKeepAliveDuration(response, context);
            if (ret > 0)
                return ret;
            return KEEPALIVE;
        }
    };
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java

public List<CordovaRegistryPluginInfo> retrievePluginInfos(IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();

    BundleContext context = HybridCore.getContext();
    HttpClient client = new CachingHttpClient(new DefaultHttpClient(),
            new FileResourceFactory(context.getDataFile(BundleHttpCacheStorage.SUBDIR_HTTP_CACHE)),
            new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), getCacheConfig());
    String url = registry.endsWith("/") ? registry + "-/all" : registry + "/-/all";
    HttpGet get = new HttpGet(url);
    HttpResponse response;//from   w  ww  .j  a  v a  2s .c  o  m

    try {
        if (monitor.isCanceled()) {
            return null;
        }
        response = client.execute(get);
        HttpEntity entity = response.getEntity();
        InputStream stream = entity.getContent();
        monitor.worked(9);
        JsonReader reader = new JsonReader(new InputStreamReader(stream));
        reader.beginObject();//start the Registry
        plugins = new ArrayList<CordovaRegistryPluginInfo>();
        while (reader.hasNext()) {
            JsonToken token = reader.peek();
            switch (token) {
            case BEGIN_OBJECT:
                CordovaRegistryPluginInfo info = new CordovaRegistryPluginInfo();
                readPluginInfo(reader, info);
                plugins.add(info);
                break;
            case NAME:
                String name = reader.nextName();
                if (name.equals("_updated")) {
                    long newUpdate = reader.nextLong();
                    if (newUpdate == this.updated) {//No changes 
                        return plugins;
                    }

                }
                break;
            default:
                Assert.isTrue(false, "Unexpected token: " + token);
                break;
            }

        }
        reader.endObject();
        return plugins;

    } catch (ClientProtocolException e) {
        throw new CoreException(
                new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e));
    } catch (IOException e) {
        throw new CoreException(
                new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e));
    } finally {
        monitor.done();
    }

}

From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java

private HttpClient enableCaching(HttpClient httpClient) {
    CacheConfig config = new CacheConfig();
    config.setSharedCache(false);/*  w  w w.  j a  v a2  s. co  m*/
    config.setMaxObjectSizeBytes(MAX_OBJECT_SIZE_BYTES);
    cacheFolder = Files.createTempDir();
    return new CachingHttpClient(httpClient, new FileResourceFactory(cacheFolder),
            cacheStorage = new ManagedHttpCacheStorage(config), config);
}