Android Open Source - android-rackspacecloud Custom Http Client

From Project

Back to project page android-rackspacecloud.


The source code is released under:

MIT License

If you think the Android project android-rackspacecloud listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*ww w  .  j a  va 2  s .c  om*/
import android.content.Context;
import android.util.Log;

import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;



 * @author Chmouel Boudjnah <>
 *         Custom implementation of HTTPClient using the keystore (in bks
 *         format) from android 2.3.1 which allow us to connect to London
 *         CloudFiles SSL host which doesn't work with the default keystore in
 *         other version than 2.3.1.
public class CustomHttpClient extends DefaultHttpClient {
  private static KeyStore trusted;
  final Context context; 
  public CustomHttpClient(Context context) {
    this.context = context;
  protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", newSslSocketFactory(), 443));
    ClientConnectionManager m =  new SingleClientConnManager(getParams(), registry);
    return m;

  private SSLSocketFactory newSslSocketFactory() {
    try {
      if (trusted == null) {
        trusted = KeyStore.getInstance("BKS");
        InputStream in = context.getResources().openRawResource(R.raw.android231); 
        try {
          trusted.load(in, "changeit".toCharArray());
        } finally {
      return new SSLSocketFactory(trusted);
    } catch (Exception e) {
      throw new AssertionError(e);

Java Source Code List