Revision b347d5e3
b/src/com/rackspace/cloud/files/api/client/ContainerManager.java | ||
---|---|---|
16 | 16 |
import org.apache.http.client.methods.HttpPost; |
17 | 17 |
import org.apache.http.client.methods.HttpPut; |
18 | 18 |
import org.apache.http.impl.client.BasicResponseHandler; |
19 |
import org.apache.http.impl.client.DefaultHttpClient; |
|
20 | 19 |
import org.apache.http.protocol.RequestExpectContinue; |
21 | 20 |
import org.xml.sax.InputSource; |
22 | 21 |
import org.xml.sax.SAXException; |
23 | 22 |
import org.xml.sax.XMLReader; |
24 | 23 |
|
24 |
import android.content.Context; |
|
25 | 25 |
import android.text.Editable; |
26 | 26 |
import android.util.Log; |
27 | 27 |
|
... | ... | |
36 | 36 |
* |
37 | 37 |
*/ |
38 | 38 |
public class ContainerManager extends EntityManager { |
39 |
private Context context; |
|
40 |
|
|
41 |
public ContainerManager(Context context) { |
|
42 |
this.context = context; |
|
43 |
} |
|
39 | 44 |
|
40 | 45 |
public HttpResponse create(Editable editable) throws CloudServersException { |
41 | 46 |
HttpResponse resp = null; |
42 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
47 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
43 | 48 |
HttpPut put = new HttpPut(Account.getStorageUrl() + "/" + editable); |
44 | 49 |
|
45 | 50 |
put.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
65 | 70 |
|
66 | 71 |
public ArrayList<Container> createCDNList(boolean detail) throws CloudServersException { |
67 | 72 |
|
68 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
73 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
69 | 74 |
HttpGet get = new HttpGet(Account.getCdnManagementUrl()+"?format=xml"); |
70 | 75 |
ArrayList<Container> cdnContainers = new ArrayList<Container>(); |
71 | 76 |
|
... | ... | |
123 | 128 |
public HttpResponse enable(String container, String ttl, String logRet) |
124 | 129 |
throws CloudServersException { |
125 | 130 |
HttpResponse resp = null; |
126 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
131 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
127 | 132 |
HttpPut put = new HttpPut(Account.getCdnManagementUrl() + "/" |
128 | 133 |
+ container); |
129 | 134 |
|
... | ... | |
153 | 158 |
public HttpResponse disable(String container, String cdn, String ttl, String logRet) |
154 | 159 |
throws CloudServersException { |
155 | 160 |
HttpResponse resp = null; |
156 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
161 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
157 | 162 |
HttpPost post = new HttpPost(Account.getCdnManagementUrl() + "/" |
158 | 163 |
+ container); |
159 | 164 |
|
... | ... | |
183 | 188 |
|
184 | 189 |
public HttpResponse delete(String string) throws CloudServersException { |
185 | 190 |
HttpResponse resp = null; |
186 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
191 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
187 | 192 |
HttpDelete put = new HttpDelete(Account.getStorageUrl() + "/" + string); |
188 | 193 |
|
189 | 194 |
put.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
210 | 215 |
public ArrayList<Container> createList(boolean detail) |
211 | 216 |
throws CloudServersException { |
212 | 217 |
|
213 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
218 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
214 | 219 |
HttpGet get = new HttpGet(Account.getStorageUrl() + "?format=xml"); |
215 | 220 |
ArrayList<Container> containers = new ArrayList<Container>(); |
216 | 221 |
|
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java | ||
---|---|---|
14 | 14 |
import org.apache.http.client.methods.HttpDelete; |
15 | 15 |
import org.apache.http.client.methods.HttpGet; |
16 | 16 |
import org.apache.http.impl.client.BasicResponseHandler; |
17 |
import org.apache.http.impl.client.DefaultHttpClient; |
|
18 | 17 |
import org.apache.http.protocol.RequestExpectContinue; |
19 | 18 |
import org.xml.sax.InputSource; |
20 | 19 |
import org.xml.sax.SAXException; |
21 | 20 |
import org.xml.sax.XMLReader; |
22 | 21 |
|
22 |
import android.content.Context; |
|
23 | 23 |
import android.util.Log; |
24 | 24 |
|
25 | 25 |
import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser; |
... | ... | |
36 | 36 |
public class ContainerObjectManager extends EntityManager { |
37 | 37 |
|
38 | 38 |
public String LOG = "ContainerObjectManager"; |
39 |
private Context context; |
|
39 | 40 |
public static final String storageToken = Account.getStorageToken(); |
40 | 41 |
|
41 |
|
|
42 |
public ContainerObjectManager(Context context) { |
|
43 |
this.context = context; |
|
44 |
} |
|
42 | 45 |
|
43 | 46 |
public ArrayList<ContainerObjects> createList(boolean detail, String passName) throws CloudServersException { |
44 | 47 |
|
45 |
|
|
46 |
DefaultHttpClient httpclient = new DefaultHttpClient(); |
|
48 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
47 | 49 |
HttpGet get = new HttpGet(Account.getStorageUrl()+"/"+passName+"?format=xml"); |
48 | 50 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
49 | 51 |
|
... | ... | |
103 | 105 |
|
104 | 106 |
public HttpResponse deleteObject(String Container, String Object) throws CloudServersException { |
105 | 107 |
HttpResponse resp = null; |
106 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
108 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
107 | 109 |
HttpDelete deleteObject = new HttpDelete(Account.getStorageUrl() + "/" + Container + "/" + Object); |
108 | 110 |
Log.v(LOG, "the container (deleteObject) vairble "+Container+" "+Object); |
109 | 111 |
|
b/src/com/rackspace/cloud/files/api/client/CustomHttpClient.java | ||
---|---|---|
1 |
package com.rackspace.cloud.files.api.client; |
|
2 |
|
|
3 |
import android.content.Context; |
|
4 |
import org.apache.http.conn.ClientConnectionManager; |
|
5 |
import org.apache.http.conn.scheme.PlainSocketFactory; |
|
6 |
import org.apache.http.conn.scheme.Scheme; |
|
7 |
import org.apache.http.conn.scheme.SchemeRegistry; |
|
8 |
import org.apache.http.conn.ssl.SSLSocketFactory; |
|
9 |
import org.apache.http.impl.client.DefaultHttpClient; |
|
10 |
import org.apache.http.impl.conn.SingleClientConnManager; |
|
11 |
|
|
12 |
import com.rackspacecloud.android.R; |
|
13 |
|
|
14 |
import java.io.InputStream; |
|
15 |
import java.security.KeyStore; |
|
16 |
|
|
17 |
/** |
|
18 |
* |
|
19 |
* @author Chmouel Boudjnah <chmouel.boudjnah@rackspace.co.uk> |
|
20 |
* |
|
21 |
* Custom implementation of HTTPClient using the keystore (in bks |
|
22 |
* format) from android 2.3.1 which allow us to connect to London |
|
23 |
* CloudFiles SSL host which doesn't work with the default keystore in |
|
24 |
* other version than 2.3.1. |
|
25 |
*/ |
|
26 |
public class CustomHttpClient extends DefaultHttpClient { |
|
27 |
|
|
28 |
final Context context; |
|
29 |
|
|
30 |
public CustomHttpClient(Context context) { |
|
31 |
this.context = context; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
protected ClientConnectionManager createClientConnectionManager() { |
|
36 |
SchemeRegistry registry = new SchemeRegistry(); |
|
37 |
registry.register(new Scheme("http", PlainSocketFactory |
|
38 |
.getSocketFactory(), 80)); |
|
39 |
registry.register(new Scheme("https", newSslSocketFactory(), 443)); |
|
40 |
return new SingleClientConnManager(getParams(), registry); |
|
41 |
} |
|
42 |
|
|
43 |
private SSLSocketFactory newSslSocketFactory() { |
|
44 |
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(); |
|
52 |
} |
|
53 |
return new SSLSocketFactory(trusted); |
|
54 |
} catch (Exception e) { |
|
55 |
throw new AssertionError(e); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
b/src/com/rackspacecloud/android/AddContainerActivity.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import android.app.Activity; |
19 | 19 |
import android.app.AlertDialog; |
20 |
import android.content.Context; |
|
20 | 21 |
import android.content.DialogInterface; |
21 | 22 |
import android.os.AsyncTask; |
22 | 23 |
import android.os.Bundle; |
... | ... | |
38 | 39 |
public class AddContainerActivity extends Activity implements OnClickListener { |
39 | 40 |
|
40 | 41 |
|
41 |
private EditText fileName; |
|
42 |
private EditText fileName; |
|
43 |
private Context context; |
|
42 | 44 |
|
43 | 45 |
/** Called when the activity is first created. */ |
44 | 46 |
@Override |
45 | 47 |
public void onCreate(Bundle savedInstanceState) { |
46 | 48 |
super.onCreate(savedInstanceState); |
49 |
context = getApplicationContext(); |
|
47 | 50 |
setContentView(R.layout.createcontainer); |
48 | 51 |
fileName = (EditText) findViewById(R.id.container_name); |
49 | 52 |
((Button) findViewById(R.id.save_button)).setOnClickListener(this); |
50 |
|
|
51 | 53 |
} |
52 | 54 |
|
53 | 55 |
|
... | ... | |
125 | 127 |
protected HttpResponse doInBackground(Void... arg0) { |
126 | 128 |
HttpResponse resp = null; |
127 | 129 |
try { |
128 |
resp = (new ContainerManager()).create(fileName.getText()); |
|
130 |
resp = (new ContainerManager(context)).create(fileName.getText());
|
|
129 | 131 |
} catch (CloudServersException e) { |
130 | 132 |
exception = e; |
131 | 133 |
} |
b/src/com/rackspacecloud/android/ContainerObjectDetails.java | ||
---|---|---|
21 | 21 |
import android.app.Activity; |
22 | 22 |
import android.app.AlertDialog; |
23 | 23 |
import android.app.Dialog; |
24 |
import android.content.Context; |
|
24 | 25 |
import android.content.DialogInterface; |
25 | 26 |
import android.content.Intent; |
26 | 27 |
import android.net.Uri; |
... | ... | |
59 | 60 |
private double megaBytes; |
60 | 61 |
private double kiloBytes; |
61 | 62 |
public Button previewButton; |
63 |
public Context context; |
|
62 | 64 |
|
63 | 65 |
/** Called when the activity is first created. */ |
64 | 66 |
@Override |
65 | 67 |
public void onCreate(Bundle savedInstanceState) { |
66 | 68 |
super.onCreate(savedInstanceState); |
67 | 69 |
|
70 |
context = getApplicationContext(); |
|
71 |
|
|
68 | 72 |
objects = (ContainerObjects) this.getIntent().getExtras().get("container"); |
69 | 73 |
containerNames = (String) this.getIntent().getExtras().get("containerNames"); |
70 | 74 |
cdnURL = (String) this.getIntent().getExtras().get("cdnUrl"); |
... | ... | |
262 | 266 |
|
263 | 267 |
@Override |
264 | 268 |
protected HttpResponse doInBackground(Void... arg0) { |
265 |
HttpResponse resp = null; |
|
269 |
HttpResponse resp = null;
|
|
266 | 270 |
try { |
267 |
resp = (new ContainerObjectManager()).deleteObject(containerNames, objects.getCName() ); |
|
271 |
resp = (new ContainerObjectManager(context)).deleteObject(containerNames, objects.getCName() );
|
|
268 | 272 |
Log.v(LOG, "container name " + objects.getCName() + " " + containerNames); |
269 | 273 |
} catch (CloudServersException e) { |
270 | 274 |
exception = e; |
b/src/com/rackspacecloud/android/ContainerObjectsActivity.java | ||
---|---|---|
20 | 20 |
import android.app.AlertDialog; |
21 | 21 |
import android.app.Dialog; |
22 | 22 |
import android.app.ListActivity; |
23 |
import android.content.Context; |
|
23 | 24 |
import android.content.DialogInterface; |
24 | 25 |
import android.content.Intent; |
25 | 26 |
import android.os.AsyncTask; |
... | ... | |
58 | 59 |
public Object kiloBytes; |
59 | 60 |
public int bConver = 1048576; |
60 | 61 |
public int kbConver = 1024; |
62 |
private Context context; |
|
61 | 63 |
|
62 | 64 |
@Override |
63 | 65 |
public void onCreate(Bundle savedInstanceState) { |
64 | 66 |
super.onCreate(savedInstanceState); |
65 | 67 |
container = (Container) this.getIntent().getExtras().get("container"); |
66 | 68 |
Log.v(LOG, "CDNEnabled:" + container.isCdnEnabled()); |
69 |
context = getApplicationContext(); |
|
67 | 70 |
if (container.isCdnEnabled() == true) { |
68 | 71 |
cdnEnabledIs = "true"; |
69 | 72 |
} else { |
... | ... | |
185 | 188 |
protected ArrayList<ContainerObjects> doInBackground(Void... arg0) { |
186 | 189 |
ArrayList<ContainerObjects> files = null; |
187 | 190 |
try { |
188 |
files = (new ContainerObjectManager()).createList(true, |
|
191 |
files = (new ContainerObjectManager(context)).createList(true,
|
|
189 | 192 |
container.getName()); |
190 | 193 |
} catch (CloudServersException e) { |
191 | 194 |
exception = e; |
... | ... | |
350 | 353 |
protected HttpResponse doInBackground(Void... arg0) { |
351 | 354 |
HttpResponse resp = null; |
352 | 355 |
try { |
353 |
resp = (new ContainerManager()).delete(container.getName()); |
|
356 |
resp = (new ContainerManager(context)).delete(container.getName());
|
|
354 | 357 |
Log.v(LOG, "container's name " + container.getName()); |
355 | 358 |
} catch (CloudServersException e) { |
356 | 359 |
exception = e; |
b/src/com/rackspacecloud/android/EnableCDNActivity.java | ||
---|---|---|
18 | 18 |
import android.app.Activity; |
19 | 19 |
import android.app.AlertDialog; |
20 | 20 |
import android.app.Dialog; |
21 |
import android.content.Context; |
|
21 | 22 |
import android.content.DialogInterface; |
22 | 23 |
import android.os.AsyncTask; |
23 | 24 |
import android.os.Bundle; |
... | ... | |
45 | 46 |
private Spinner ttlSpinner; |
46 | 47 |
private Spinner logRetSpinner; |
47 | 48 |
private Spinner cdnSpinner; |
48 |
|
|
49 |
private Context context; |
|
50 |
|
|
49 | 51 |
/** Called when the activity is first created. */ |
50 | 52 |
@Override |
51 | 53 |
public void onCreate(Bundle savedInstanceState) { |
52 | 54 |
super.onCreate(savedInstanceState); |
53 | 55 |
setContentView(R.layout.enable_cdn_container); |
56 |
context = getApplicationContext(); |
|
54 | 57 |
containerName = (String) this.getIntent().getExtras().get("Cname"); |
55 | 58 |
setupButtons(); |
56 | 59 |
loadTtlSpinner(); |
... | ... | |
241 | 244 |
protected HttpResponse doInBackground(Void... arg0) { |
242 | 245 |
HttpResponse resp = null; |
243 | 246 |
try { |
244 |
resp = (new ContainerManager()).enable(containerName, |
|
247 |
resp = (new ContainerManager(context)).enable(containerName,
|
|
245 | 248 |
selectedTtlId, selectedLogRetId); |
246 | 249 |
} catch (CloudServersException e) { |
247 | 250 |
exception = e; |
... | ... | |
287 | 290 |
protected HttpResponse doInBackground(Void... arg0) { |
288 | 291 |
HttpResponse resp = null; |
289 | 292 |
try { |
290 |
resp = (new ContainerManager()).disable(containerName, |
|
293 |
resp = (new ContainerManager(context)).disable(containerName,
|
|
291 | 294 |
selectedCdnId, selectedTtlId, selectedLogRetId); |
292 | 295 |
} catch (CloudServersException e) { |
293 | 296 |
exception = e; |
b/src/com/rackspacecloud/android/ListContainerActivity.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import android.app.AlertDialog; |
6 | 6 |
import android.app.ListActivity; |
7 |
import android.content.Context; |
|
7 | 8 |
import android.content.DialogInterface; |
8 | 9 |
import android.content.Intent; |
9 | 10 |
import android.os.AsyncTask; |
... | ... | |
39 | 40 |
public int bConver = 1048576; |
40 | 41 |
public int kbConver = 1024; |
41 | 42 |
protected static final int DELETE_ID = 0; |
42 |
|
|
43 |
private Context context; |
|
44 |
|
|
43 | 45 |
@Override |
44 | 46 |
public void onCreate(Bundle savedInstanceState) { |
45 | 47 |
super.onCreate(savedInstanceState); |
48 |
context = getApplicationContext(); |
|
46 | 49 |
restoreState(savedInstanceState); |
47 | 50 |
} |
48 | 51 |
|
... | ... | |
143 | 146 |
ArrayList<Container> containers = null; |
144 | 147 |
|
145 | 148 |
try { |
146 |
containers = (new ContainerManager()).createList(true); |
|
149 |
containers = (new ContainerManager(context)).createList(true);
|
|
147 | 150 |
} catch (CloudServersException e) { |
148 | 151 |
exception = e; |
149 | 152 |
} |
... | ... | |
180 | 183 |
ArrayList<Container> cdnContainers = null; |
181 | 184 |
|
182 | 185 |
try { |
183 |
cdnContainers = (new ContainerManager()).createCDNList(true); |
|
186 |
cdnContainers = (new ContainerManager(context)).createCDNList(true);
|
|
184 | 187 |
} catch (CloudServersException e) { |
185 | 188 |
exception = e; |
186 | 189 |
} |
b/src/com/rackspacecloud/android/RackspaceCloudActivity.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
import android.app.Activity; |
7 | 7 |
import android.app.AlertDialog; |
8 |
import android.app.Dialog; |
|
9 | 8 |
import android.content.Context; |
10 | 9 |
import android.content.DialogInterface; |
11 | 10 |
import android.content.Intent; |
... | ... | |
15 | 14 |
import android.os.Bundle; |
16 | 15 |
import android.text.method.PasswordTransformationMethod; |
17 | 16 |
import android.text.method.SingleLineTransformationMethod; |
18 |
import android.text.method.TextKeyListener; |
|
19 | 17 |
import android.util.Log; |
20 | 18 |
import android.view.KeyEvent; |
21 | 19 |
import android.view.Menu; |
Also available in: Unified diff