List of usage examples for org.apache.http.impl.client.cache CachingHttpClient CachingHttpClient
public CachingHttpClient(HttpClient client, ResourceFactory resourceFactory, HttpCacheStorage storage,
CacheConfig config)
From source file:org.eclipse.thym.core.engine.AbstractEngineRepoProvider.java
protected InputStream getRemoteJSonStream(String url) { DefaultHttpClient defHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(defHttpClient);/*w w w . ja v a 2 s .c o m*/ 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.engine.internal.cordova.DefaultEngineRepoProvider.java
private InputStream getRemoteJSonStream() { BundleContext context = HybridCore.getContext(); DefaultHttpClient defHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(defHttpClient);//ww w . ja v a 2 s . c om 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.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);//w w w .ja v a 2 s. c om 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.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;// w w w. j a v a 2s .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.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);//w ww . j ava 2 s . c o m 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.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;//w w w .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);/*from w w w . j a v a 2 s.com*/ config.setMaxObjectSizeBytes(MAX_OBJECT_SIZE_BYTES); cacheFolder = Files.createTempDir(); return new CachingHttpClient(httpClient, new FileResourceFactory(cacheFolder), cacheStorage = new ManagedHttpCacheStorage(config), config); }