Revision 25881fb3 src/com/rackspace/cloud/files/api/client/CustomHttpClient.java
b/src/com/rackspace/cloud/files/api/client/CustomHttpClient.java | ||
---|---|---|
1 | 1 |
package com.rackspace.cloud.files.api.client; |
2 | 2 |
|
3 | 3 |
import android.content.Context; |
4 |
import android.util.Log; |
|
5 |
|
|
4 | 6 |
import org.apache.http.conn.ClientConnectionManager; |
5 | 7 |
import org.apache.http.conn.scheme.PlainSocketFactory; |
6 | 8 |
import org.apache.http.conn.scheme.Scheme; |
... | ... | |
14 | 16 |
import java.io.InputStream; |
15 | 17 |
import java.security.KeyStore; |
16 | 18 |
|
19 |
|
|
17 | 20 |
/** |
18 | 21 |
* |
19 | 22 |
* @author Chmouel Boudjnah <chmouel.boudjnah@rackspace.co.uk> |
... | ... | |
24 | 27 |
* other version than 2.3.1. |
25 | 28 |
*/ |
26 | 29 |
public class CustomHttpClient extends DefaultHttpClient { |
27 |
|
|
28 |
final Context context; |
|
29 |
|
|
30 |
|
|
31 |
private static KeyStore trusted; |
|
32 |
final Context context; |
|
33 |
|
|
30 | 34 |
public CustomHttpClient(Context context) { |
35 |
super(); |
|
31 | 36 |
this.context = context; |
32 | 37 |
} |
33 |
|
|
38 |
|
|
34 | 39 |
@Override |
35 | 40 |
protected ClientConnectionManager createClientConnectionManager() { |
36 | 41 |
SchemeRegistry registry = new SchemeRegistry(); |
37 |
registry.register(new Scheme("http", PlainSocketFactory |
|
38 |
.getSocketFactory(), 80)); |
|
42 |
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); |
|
39 | 43 |
registry.register(new Scheme("https", newSslSocketFactory(), 443)); |
40 |
return new SingleClientConnManager(getParams(), registry); |
|
44 |
ClientConnectionManager m = new SingleClientConnManager(getParams(), registry); |
|
45 |
return m; |
|
41 | 46 |
} |
42 | 47 |
|
43 | 48 |
private SSLSocketFactory newSslSocketFactory() { |
44 | 49 |
try { |
45 |
KeyStore trusted = KeyStore.getInstance("BKS"); |
|
46 |
InputStream in = context.getResources().openRawResource( |
|
47 |
R.raw.android231); |
|
48 |
try { |
|
49 |
trusted.load(in, "changeit".toCharArray()); |
|
50 |
} finally { |
|
51 |
in.close(); |
|
50 |
if (trusted == null) { |
|
51 |
trusted = KeyStore.getInstance("BKS"); |
|
52 |
InputStream in = context.getResources().openRawResource(R.raw.android231); |
|
53 |
try { |
|
54 |
trusted.load(in, "changeit".toCharArray()); |
|
55 |
} finally { |
|
56 |
in.close(); |
|
57 |
} |
|
52 | 58 |
} |
53 | 59 |
return new SSLSocketFactory(trusted); |
54 | 60 |
} catch (Exception e) { |
55 | 61 |
throw new AssertionError(e); |
56 | 62 |
} |
57 | 63 |
} |
58 |
} |
|
64 |
} |
Also available in: Unified diff