List of usage examples for org.apache.http.impl.client.cache HeapResourceFactory HeapResourceFactory
HeapResourceFactory
From source file:org.eclipse.thym.core.engine.AbstractEngineRepoProvider.java
protected InputStream getRemoteJSonStream(String url) { DefaultHttpClient defHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(defHttpClient);/*from w ww .ja v a 2 s .c om*/ HttpClient client = new CachingHttpClient(defHttpClient, new HeapResourceFactory(), new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), cacheConfig()); HttpGet get = new HttpGet(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})", url), e); } return null; }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
public CordovaRegistryPlugin getCordovaPluginInfo(String name) throws CoreException { CordovaRegistryPlugin plugin = detailedPluginInfoCache.get(name); if (plugin != null) return plugin; DefaultHttpClient defHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(defHttpClient);/*from w w w. j a v a 2 s. c o m*/ HttpClient client = new CachingHttpClient(defHttpClient, new HeapResourceFactory(), new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), getCacheConfig()); HttpGet get = new HttpGet(REGISTRY_URL + name); HttpResponse response; 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.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
public List<CordovaRegistryPluginInfo> retrievePluginInfos(IProgressMonitor monitor) throws CoreException { if (monitor == null) monitor = new NullProgressMonitor(); monitor.beginTask("Retrieve plug-in registry catalog", 10); DefaultHttpClient theHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(theHttpClient);// ww w .java 2 s . com HttpClient client = new CachingHttpClient(theHttpClient, new HeapResourceFactory(), new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), getCacheConfig()); JsonReader reader = null; try { if (monitor.isCanceled()) { return null; } String url = REGISTRY_URL + "-/_view/byKeyword?startkey=%5B%22ecosystem:cordova%22%5D&endkey=%5B%22ecosystem:cordova1%22%5D&group_level=3"; HttpGet get = new HttpGet(URI.create(url)); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); monitor.worked(7); reader = new JsonReader(new InputStreamReader(stream)); reader.beginObject();//start the Registry final ArrayList<CordovaRegistryPluginInfo> plugins = new ArrayList<CordovaRegistryPluginInfo>(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_ARRAY: reader.beginArray(); break; case BEGIN_OBJECT: plugins.add(parseCordovaRegistryPluginInfo(reader)); break; default: reader.skipValue(); break; } } 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 { if (reader != null) try { reader.close(); } catch (IOException e) { /*ignored*/ } monitor.done(); } }
From source file:org.apache.http.impl.client.cache.BasicHttpCache.java
public BasicHttpCache(CacheConfig config) { this(new HeapResourceFactory(), new BasicHttpCacheStorage(config), config); }
From source file:org.apache.http.impl.client.cache.CachingHttpAsyncClient.java
public CachingHttpAsyncClient(final HttpAsyncClient client, final HttpCacheStorage storage, final CacheConfig config) { this(client, new BasicHttpCache(new HeapResourceFactory(), storage, config), config); }
From source file:org.apache.http.impl.client.cache.CachingHttpClient.java
/** * Constructs a {@code CachingHttpClient} with the given caching options * that stores cache entries in the provided storage backend and uses * the given {@link HttpClient} for backend requests. * @param client used to make origin requests * @param storage where to store cache entries * @param config cache module options/* w w w . j a va 2 s . co m*/ */ public CachingHttpClient(HttpClient client, HttpCacheStorage storage, CacheConfig config) { this(client, new BasicHttpCache(new HeapResourceFactory(), storage, config), config); }