root / src / com / rackspace / cloud / files / api / client / CustomHttpClient.java @ 96a8e632
History | View | Annotate | Download (1.8 kB)
1 |
package com.rackspace.cloud.files.api.client; |
---|---|
2 |
|
3 |
import android.content.Context; |
4 |
import android.util.Log; |
5 |
|
6 |
import org.apache.http.conn.ClientConnectionManager; |
7 |
import org.apache.http.conn.scheme.PlainSocketFactory; |
8 |
import org.apache.http.conn.scheme.Scheme; |
9 |
import org.apache.http.conn.scheme.SchemeRegistry; |
10 |
import org.apache.http.conn.ssl.SSLSocketFactory; |
11 |
import org.apache.http.impl.client.DefaultHttpClient; |
12 |
import org.apache.http.impl.conn.SingleClientConnManager; |
13 |
|
14 |
import com.rackspacecloud.android.R; |
15 |
|
16 |
import java.io.InputStream; |
17 |
import java.security.KeyStore; |
18 |
|
19 |
|
20 |
/**
|
21 |
*
|
22 |
* @author Chmouel Boudjnah <chmouel.boudjnah@rackspace.co.uk>
|
23 |
*
|
24 |
* Custom implementation of HTTPClient using the keystore (in bks
|
25 |
* format) from android 2.3.1 which allow us to connect to London
|
26 |
* CloudFiles SSL host which doesn't work with the default keystore in
|
27 |
* other version than 2.3.1.
|
28 |
*/
|
29 |
public class CustomHttpClient extends DefaultHttpClient { |
30 |
|
31 |
final Context context; |
32 |
|
33 |
public CustomHttpClient(Context context) { |
34 |
super();
|
35 |
this.context = context;
|
36 |
} |
37 |
|
38 |
@Override
|
39 |
protected ClientConnectionManager createClientConnectionManager() {
|
40 |
SchemeRegistry registry = new SchemeRegistry();
|
41 |
registry.register(new Scheme("http", PlainSocketFactory |
42 |
.getSocketFactory(), 80));
|
43 |
registry.register(new Scheme("https", newSslSocketFactory(), 443)); |
44 |
return new SingleClientConnManager(getParams(), registry); |
45 |
} |
46 |
|
47 |
private SSLSocketFactory newSslSocketFactory() { |
48 |
try {
|
49 |
KeyStore trusted = KeyStore.getInstance("BKS"); |
50 |
InputStream in = context.getResources().openRawResource(
|
51 |
R.raw.android231); |
52 |
try {
|
53 |
trusted.load(in, "changeit".toCharArray());
|
54 |
} finally {
|
55 |
in.close(); |
56 |
} |
57 |
return new SSLSocketFactory(trusted); |
58 |
} catch (Exception e) { |
59 |
throw new AssertionError(e); |
60 |
} |
61 |
} |
62 |
} |