@Test public void closeRemovesReference() throws Exception { HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42); cache.close(); assertThat(HttpResponseCache.getInstalled()).isNull(); } }
@Test public void deleteRemovesReference() throws Exception { HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42); cache.delete(); assertThat(HttpResponseCache.getInstalled()).isNull(); }
@Test public void countsStartAtZero() throws Exception { HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42); assertThat(cache.getHitCount()).isEqualTo(0); assertThat(cache.getNetworkCount()).isEqualTo(0); assertThat(cache.getRequestCount()).isEqualTo(0); }
@Test public void testNewInstanceWithContext() throws Exception { AndroidHttpClient client = AndroidHttpClient.newInstance("foo", RuntimeEnvironment.application); assertThat(client).isNotNull(); }
@Test public void testExecute() throws IOException { AndroidHttpClient client = AndroidHttpClient.newInstance("foo"); FakeHttp.addPendingHttpResponse(200, "foo"); HttpResponse resp = client.execute(new HttpGet("/foo")); assertThat(resp.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(CharStreams.toString(new InputStreamReader(resp.getEntity().getContent(), UTF_8))) .isEqualTo("foo"); } }
@Override public Object invoke(final Object... args) throws InvocationException { final String userAgent = this.buildUserAgent(this.context); final AndroidHttpClient client = AndroidHttpClient.newInstance(userAgent, this.context); try { return this.invoke(client, args); } finally { client.close(); } }
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { Log.e("Error", "Received SSL error"+ error.toString()); handler.proceed(); }
AlertDialog alertDialog = builder.create(); String message = "SSL Certificate error."; switch (error.getPrimaryError()) { case SslError.SSL_UNTRUSTED: message = "The certificate authority is not trusted.";
@Test public void installedCacheIsReturned() throws Exception { assertThat(HttpResponseCache.getInstalled()).isNull(); HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42); HttpResponseCache installed = HttpResponseCache.getInstalled(); assertThat(installed).isSameAs(cache); assertThat(installed.maxSize()).isEqualTo(42); }
public void close() { client.close(); }
SslCertificate sslCert = error.getCertificate(); Field f = sslCert.getClass().getDeclaredField("mX509Certificate"); f.setAccessible(true);
@Test public void testNewInstance() throws Exception { AndroidHttpClient client = AndroidHttpClient.newInstance("foo"); assertThat(client).isNotNull(); }
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { Log.e("Error", "Received SSL error"+ error.toString()); handler.proceed(); }
webview.setWebViewClient(new WebViewClient(){ @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { super.onReceivedHttpAuthRequest(view, handler, host, realm); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { super.onReceivedSslError(view, handler, error); if(error.getPrimaryError()==SslError.SSL_UNTRUSTED){ handler.proceed(); }else{ handler.proceed(); } } });
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link android.content.Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
@Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { Log.e("Error", "Received SSL error"+ error.toString()); handler.proceed(); }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent));
public AndroidApacheClient() { super(AndroidHttpClient.newInstance("Retrofit")); } }
public BaseHttpClient(final String userAgent) { this.userAgent = userAgent; this.client = AndroidHttpClient.newInstance(userAgent); this.auth = new BasicAuthenticator(); }