root / src / com / rackspace / cloud / files / api / client / ContainerObjectManager.java @ d37efce5
History | View | Annotate | Download (19.2 kB)
1 |
package com.rackspace.cloud.files.api.client; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.io.StringReader; |
5 |
import java.io.UnsupportedEncodingException; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URI; |
8 |
import java.net.URISyntaxException; |
9 |
import java.util.ArrayList; |
10 |
import java.util.List; |
11 |
import java.util.Map; |
12 |
import java.util.Map.Entry; |
13 |
|
14 |
import javax.xml.parsers.FactoryConfigurationError; |
15 |
import javax.xml.parsers.ParserConfigurationException; |
16 |
import javax.xml.parsers.SAXParser; |
17 |
import javax.xml.parsers.SAXParserFactory; |
18 |
|
19 |
import org.apache.http.HttpResponse; |
20 |
import org.apache.http.client.ClientProtocolException; |
21 |
import org.apache.http.client.methods.HttpDelete; |
22 |
import org.apache.http.client.methods.HttpGet; |
23 |
import org.apache.http.client.methods.HttpPost; |
24 |
import org.apache.http.client.methods.HttpPut; |
25 |
import org.apache.http.entity.StringEntity; |
26 |
import org.apache.http.impl.client.BasicResponseHandler; |
27 |
import org.apache.http.protocol.RequestExpectContinue; |
28 |
import org.xml.sax.InputSource; |
29 |
import org.xml.sax.SAXException; |
30 |
import org.xml.sax.XMLReader; |
31 |
|
32 |
import android.content.Context; |
33 |
import android.util.Log; |
34 |
|
35 |
import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser; |
36 |
import com.rackspace.cloud.files.api.client.parsers.ObjectVersionXMLParser; |
37 |
import com.rackspace.cloud.servers.api.client.Account; |
38 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
39 |
import com.rackspace.cloud.servers.api.client.EntityManager; |
40 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
41 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
42 |
|
43 |
/**
|
44 |
*
|
45 |
* @author Phillip Toohill
|
46 |
*
|
47 |
*/
|
48 |
public class ContainerObjectManager extends EntityManager { |
49 |
|
50 |
public String LOG = "ContainerObjectManager"; |
51 |
private Context context; |
52 |
public static final String storageToken = Account.getAccount() |
53 |
.getStorageToken(); |
54 |
|
55 |
public ContainerObjectManager(Context context) { |
56 |
this.context = context;
|
57 |
} |
58 |
|
59 |
public ArrayList<ContainerObjects> createList(boolean detail, |
60 |
String passName) throws CloudServersException { |
61 |
Log.i(LOG,"Create List:"+passName);
|
62 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
63 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), passName)
|
64 |
+ "?format=xml";
|
65 |
HttpGet get = new HttpGet(url);
|
66 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
67 |
|
68 |
get.addHeader("Content-Type", "application/xml"); |
69 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
70 |
|
71 |
try {
|
72 |
HttpResponse resp = httpclient.execute(get); |
73 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
74 |
String body = responseHandler.handleResponse(resp);
|
75 |
|
76 |
if (resp.getStatusLine().getStatusCode() == 200 |
77 |
|| resp.getStatusLine().getStatusCode() == 203) {
|
78 |
ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
|
79 |
SAXParser saxParser = SAXParserFactory.newInstance() |
80 |
.newSAXParser(); |
81 |
XMLReader xmlReader = saxParser.getXMLReader(); |
82 |
xmlReader.setContentHandler(filesXMLParser); |
83 |
|
84 |
xmlReader.parse(new InputSource(new StringReader(body))); |
85 |
files = filesXMLParser.getViewFiles(); |
86 |
for(ContainerObjects o :files)
|
87 |
o.setContainerName(passName); |
88 |
|
89 |
} else {
|
90 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
91 |
SAXParser saxParser = SAXParserFactory.newInstance() |
92 |
.newSAXParser(); |
93 |
XMLReader xmlReader = saxParser.getXMLReader(); |
94 |
xmlReader.setContentHandler(parser); |
95 |
xmlReader.parse(new InputSource(new StringReader(body))); |
96 |
CloudServersException cse = parser.getException(); |
97 |
throw cse;
|
98 |
} |
99 |
} catch (ClientProtocolException e) {
|
100 |
CloudServersException cse = new CloudServersException();
|
101 |
cse.setMessage(e.getLocalizedMessage()); |
102 |
throw cse;
|
103 |
} catch (IOException e) { |
104 |
CloudServersException cse = new CloudServersException();
|
105 |
cse.setMessage(e.getLocalizedMessage()); |
106 |
throw cse;
|
107 |
} catch (ParserConfigurationException e) { |
108 |
CloudServersException cse = new CloudServersException();
|
109 |
cse.setMessage(e.getLocalizedMessage()); |
110 |
throw cse;
|
111 |
} catch (SAXException e) {
|
112 |
CloudServersException cse = new CloudServersException();
|
113 |
cse.setMessage(e.getLocalizedMessage()); |
114 |
throw cse;
|
115 |
} catch (FactoryConfigurationError e) { |
116 |
CloudServersException cse = new CloudServersException();
|
117 |
cse.setMessage(e.getLocalizedMessage()); |
118 |
throw cse;
|
119 |
} |
120 |
return files;
|
121 |
|
122 |
} |
123 |
|
124 |
public ArrayList<ContainerObjects> createOtherList(boolean detail, |
125 |
String passName, String user) throws CloudServersException { |
126 |
Log.i(LOG,"Create List:"+passName);
|
127 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
128 |
String url = getSafeURL(Account.getAccount().getStorageUrl().replaceAll(Account.getAccount().getUsername(), user), passName)
|
129 |
+ "?format=xml";
|
130 |
HttpGet get = new HttpGet(url);
|
131 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
132 |
|
133 |
get.addHeader("Content-Type", "application/xml"); |
134 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
135 |
|
136 |
try {
|
137 |
HttpResponse resp = httpclient.execute(get); |
138 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
139 |
String body = responseHandler.handleResponse(resp);
|
140 |
|
141 |
if (resp.getStatusLine().getStatusCode() == 200 |
142 |
|| resp.getStatusLine().getStatusCode() == 203) {
|
143 |
ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
|
144 |
SAXParser saxParser = SAXParserFactory.newInstance() |
145 |
.newSAXParser(); |
146 |
XMLReader xmlReader = saxParser.getXMLReader(); |
147 |
xmlReader.setContentHandler(filesXMLParser); |
148 |
|
149 |
xmlReader.parse(new InputSource(new StringReader(body))); |
150 |
files = filesXMLParser.getViewFiles(); |
151 |
for(ContainerObjects o :files)
|
152 |
o.setContainerName(passName); |
153 |
|
154 |
} else {
|
155 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
156 |
SAXParser saxParser = SAXParserFactory.newInstance() |
157 |
.newSAXParser(); |
158 |
XMLReader xmlReader = saxParser.getXMLReader(); |
159 |
xmlReader.setContentHandler(parser); |
160 |
xmlReader.parse(new InputSource(new StringReader(body))); |
161 |
CloudServersException cse = parser.getException(); |
162 |
throw cse;
|
163 |
} |
164 |
} catch (ClientProtocolException e) {
|
165 |
CloudServersException cse = new CloudServersException();
|
166 |
cse.setMessage(e.getLocalizedMessage()); |
167 |
throw cse;
|
168 |
} catch (IOException e) { |
169 |
CloudServersException cse = new CloudServersException();
|
170 |
cse.setMessage(e.getLocalizedMessage()); |
171 |
throw cse;
|
172 |
} catch (ParserConfigurationException e) { |
173 |
CloudServersException cse = new CloudServersException();
|
174 |
cse.setMessage(e.getLocalizedMessage()); |
175 |
throw cse;
|
176 |
} catch (SAXException e) {
|
177 |
CloudServersException cse = new CloudServersException();
|
178 |
cse.setMessage(e.getLocalizedMessage()); |
179 |
throw cse;
|
180 |
} catch (FactoryConfigurationError e) { |
181 |
CloudServersException cse = new CloudServersException();
|
182 |
cse.setMessage(e.getLocalizedMessage()); |
183 |
throw cse;
|
184 |
} |
185 |
return files;
|
186 |
|
187 |
} |
188 |
|
189 |
public ArrayList<ContainerObjects> createList(boolean detail, |
190 |
String passName, String prefix) throws CloudServersException { |
191 |
|
192 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
193 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), passName)
|
194 |
+ "?format=xml&prefix="+prefix;
|
195 |
HttpGet get = new HttpGet(url);
|
196 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
197 |
|
198 |
get.addHeader("Content-Type", "application/xml"); |
199 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
200 |
|
201 |
try {
|
202 |
HttpResponse resp = httpclient.execute(get); |
203 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
204 |
String body = responseHandler.handleResponse(resp);
|
205 |
|
206 |
if (resp.getStatusLine().getStatusCode() == 200 |
207 |
|| resp.getStatusLine().getStatusCode() == 203) {
|
208 |
ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
|
209 |
SAXParser saxParser = SAXParserFactory.newInstance() |
210 |
.newSAXParser(); |
211 |
XMLReader xmlReader = saxParser.getXMLReader(); |
212 |
xmlReader.setContentHandler(filesXMLParser); |
213 |
|
214 |
xmlReader.parse(new InputSource(new StringReader(body))); |
215 |
files = filesXMLParser.getViewFiles(); |
216 |
for(ContainerObjects o :files)
|
217 |
o.setContainerName(passName); |
218 |
|
219 |
} else {
|
220 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
221 |
SAXParser saxParser = SAXParserFactory.newInstance() |
222 |
.newSAXParser(); |
223 |
XMLReader xmlReader = saxParser.getXMLReader(); |
224 |
xmlReader.setContentHandler(parser); |
225 |
xmlReader.parse(new InputSource(new StringReader(body))); |
226 |
CloudServersException cse = parser.getException(); |
227 |
throw cse;
|
228 |
} |
229 |
} catch (ClientProtocolException e) {
|
230 |
CloudServersException cse = new CloudServersException();
|
231 |
cse.setMessage(e.getLocalizedMessage()); |
232 |
throw cse;
|
233 |
} catch (IOException e) { |
234 |
CloudServersException cse = new CloudServersException();
|
235 |
cse.setMessage(e.getLocalizedMessage()); |
236 |
throw cse;
|
237 |
} catch (ParserConfigurationException e) { |
238 |
CloudServersException cse = new CloudServersException();
|
239 |
cse.setMessage(e.getLocalizedMessage()); |
240 |
throw cse;
|
241 |
} catch (SAXException e) {
|
242 |
CloudServersException cse = new CloudServersException();
|
243 |
cse.setMessage(e.getLocalizedMessage()); |
244 |
throw cse;
|
245 |
} catch (FactoryConfigurationError e) { |
246 |
CloudServersException cse = new CloudServersException();
|
247 |
cse.setMessage(e.getLocalizedMessage()); |
248 |
throw cse;
|
249 |
} |
250 |
return files;
|
251 |
|
252 |
} |
253 |
|
254 |
public List<ObjectVersion> getObjectVersions(String Container, String Object) |
255 |
throws CloudServersException {
|
256 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
257 |
String url = Account.getAccount().getStorageUrl()+"/"+ Container |
258 |
+ "/" + Object+"?format=xml&version=list"; |
259 |
Log.i("papala",url);
|
260 |
HttpGet get = new HttpGet(url);
|
261 |
List<ObjectVersion> versions =null; |
262 |
get.addHeader("Content-Type", "application/xml"); |
263 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
264 |
|
265 |
try {
|
266 |
HttpResponse resp = httpclient.execute(get); |
267 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
268 |
String body = responseHandler.handleResponse(resp);
|
269 |
|
270 |
if (resp.getStatusLine().getStatusCode() == 200 |
271 |
|| resp.getStatusLine().getStatusCode() == 203) {
|
272 |
ObjectVersionXMLParser filesXMLParser = new ObjectVersionXMLParser();
|
273 |
SAXParser saxParser = SAXParserFactory.newInstance() |
274 |
.newSAXParser(); |
275 |
XMLReader xmlReader = saxParser.getXMLReader(); |
276 |
xmlReader.setContentHandler(filesXMLParser); |
277 |
|
278 |
xmlReader.parse(new InputSource(new StringReader(body))); |
279 |
versions = filesXMLParser.getContainers(); |
280 |
|
281 |
|
282 |
} else {
|
283 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
284 |
SAXParser saxParser = SAXParserFactory.newInstance() |
285 |
.newSAXParser(); |
286 |
XMLReader xmlReader = saxParser.getXMLReader(); |
287 |
xmlReader.setContentHandler(parser); |
288 |
xmlReader.parse(new InputSource(new StringReader(body))); |
289 |
CloudServersException cse = parser.getException(); |
290 |
throw cse;
|
291 |
} |
292 |
} catch (ClientProtocolException e) {
|
293 |
CloudServersException cse = new CloudServersException();
|
294 |
cse.setMessage(e.getLocalizedMessage()); |
295 |
throw cse;
|
296 |
} catch (IOException e) { |
297 |
CloudServersException cse = new CloudServersException();
|
298 |
cse.setMessage(e.getLocalizedMessage()); |
299 |
throw cse;
|
300 |
} catch (ParserConfigurationException e) { |
301 |
CloudServersException cse = new CloudServersException();
|
302 |
cse.setMessage(e.getLocalizedMessage()); |
303 |
throw cse;
|
304 |
} catch (SAXException e) {
|
305 |
CloudServersException cse = new CloudServersException();
|
306 |
cse.setMessage(e.getLocalizedMessage()); |
307 |
throw cse;
|
308 |
} catch (FactoryConfigurationError e) { |
309 |
CloudServersException cse = new CloudServersException();
|
310 |
cse.setMessage(e.getLocalizedMessage()); |
311 |
throw cse;
|
312 |
} |
313 |
return versions;
|
314 |
} |
315 |
|
316 |
public ArrayList<ContainerObjects> createListMyShared(boolean detail, |
317 |
String passName, List<Container> containers) throws CloudServersException { |
318 |
|
319 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
320 |
for(Container con :containers ){ |
321 |
Log.i(LOG,"GEETING FILES OF COntainer:"+con.getName());
|
322 |
if(con.getName().equalsIgnoreCase("trash")||con.getName().equals(Container.MYSHARED)||con.getName().equals(Container.OTHERS)){} |
323 |
else
|
324 |
try{
|
325 |
ArrayList<ContainerObjects> temp = createList(detail, con.getName());
|
326 |
for(ContainerObjects o : temp){
|
327 |
Log.i(LOG,o.getCName()+" "+o.isShared());
|
328 |
if(o.isShared()){
|
329 |
o.setContainerName(Container.MYSHARED);
|
330 |
files.add(o); |
331 |
} |
332 |
} |
333 |
} |
334 |
catch(CloudServersException e){
|
335 |
|
336 |
} |
337 |
} |
338 |
return files;
|
339 |
|
340 |
} |
341 |
|
342 |
public HttpBundle deleteObject(String Container, String Object) |
343 |
throws CloudServersException {
|
344 |
HttpResponse resp = null;
|
345 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
346 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container |
347 |
+ "/" + Object); |
348 |
HttpDelete deleteObject = new HttpDelete(url);
|
349 |
|
350 |
deleteObject.addHeader("X-Auth-Token", Account.getAccount()
|
351 |
.getAuthToken()); |
352 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
353 |
|
354 |
HttpBundle bundle = new HttpBundle();
|
355 |
bundle.setCurlRequest(deleteObject); |
356 |
|
357 |
try {
|
358 |
resp = httpclient.execute(deleteObject); |
359 |
bundle.setHttpResponse(resp); |
360 |
} catch (ClientProtocolException e) {
|
361 |
CloudServersException cse = new CloudServersException();
|
362 |
cse.setMessage(e.getLocalizedMessage()); |
363 |
throw cse;
|
364 |
} catch (IOException e) { |
365 |
CloudServersException cse = new CloudServersException();
|
366 |
cse.setMessage(e.getLocalizedMessage()); |
367 |
throw cse;
|
368 |
} catch (FactoryConfigurationError e) { |
369 |
CloudServersException cse = new CloudServersException();
|
370 |
cse.setMessage(e.getLocalizedMessage()); |
371 |
throw cse;
|
372 |
} |
373 |
return bundle;
|
374 |
} |
375 |
|
376 |
public HttpBundle getObject(String Container, String Object) |
377 |
throws CloudServersException {
|
378 |
HttpResponse resp = null;
|
379 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
380 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container |
381 |
+ "/" + Object); |
382 |
HttpGet getObject = new HttpGet(url);
|
383 |
getObject |
384 |
.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
385 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
386 |
|
387 |
HttpBundle bundle = new HttpBundle();
|
388 |
bundle.setCurlRequest(getObject); |
389 |
|
390 |
try {
|
391 |
resp = httpclient.execute(getObject); |
392 |
bundle.setHttpResponse(resp); |
393 |
} catch (ClientProtocolException e) {
|
394 |
CloudServersException cse = new CloudServersException();
|
395 |
cse.setMessage(e.getLocalizedMessage()); |
396 |
throw cse;
|
397 |
} catch (IOException e) { |
398 |
CloudServersException cse = new CloudServersException();
|
399 |
cse.setMessage(e.getLocalizedMessage()); |
400 |
throw cse;
|
401 |
} catch (FactoryConfigurationError e) { |
402 |
CloudServersException cse = new CloudServersException();
|
403 |
cse.setMessage(e.getLocalizedMessage()); |
404 |
throw cse;
|
405 |
} |
406 |
return bundle;
|
407 |
} |
408 |
|
409 |
|
410 |
|
411 |
public HttpBundle addObject(String Container, String Path, String Object, |
412 |
String type) throws CloudServersException { |
413 |
HttpResponse resp = null;
|
414 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
415 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container |
416 |
+ "/" + Path + Object); |
417 |
HttpPut addObject = new HttpPut(url);
|
418 |
|
419 |
addObject |
420 |
.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
421 |
addObject.addHeader("Content-Type", type);
|
422 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
423 |
|
424 |
HttpBundle bundle = new HttpBundle();
|
425 |
bundle.setCurlRequest(addObject); |
426 |
|
427 |
try {
|
428 |
resp = httpclient.execute(addObject); |
429 |
bundle.setHttpResponse(resp); |
430 |
} catch (ClientProtocolException e) {
|
431 |
CloudServersException cse = new CloudServersException();
|
432 |
cse.setMessage(e.getLocalizedMessage()); |
433 |
throw cse;
|
434 |
} catch (IOException e) { |
435 |
CloudServersException cse = new CloudServersException();
|
436 |
cse.setMessage(e.getLocalizedMessage()); |
437 |
throw cse;
|
438 |
} catch (FactoryConfigurationError e) { |
439 |
CloudServersException cse = new CloudServersException();
|
440 |
cse.setMessage(e.getLocalizedMessage()); |
441 |
throw cse;
|
442 |
} |
443 |
return bundle;
|
444 |
} |
445 |
|
446 |
public HttpBundle updateObject(String Container, String Path, String Object, |
447 |
String type, Map<String,String> headers) throws CloudServersException { |
448 |
HttpResponse resp = null;
|
449 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
450 |
String url;
|
451 |
if(Container !=null) |
452 |
url = getSafeURL(Account.getAccount().getStorageUrl(), Container
|
453 |
+ "/" + Path + Object); |
454 |
else{
|
455 |
url = getSafeURL(Account.getAccount().getStorageUrl(),"");
|
456 |
if(url.endsWith("/")) |
457 |
url = url.substring(0, url.length()-1); |
458 |
} |
459 |
url =url+"?update=";
|
460 |
Log.d("papala", url);
|
461 |
HttpPost addObject = new HttpPost(url);
|
462 |
|
463 |
addObject |
464 |
.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
465 |
addObject.addHeader("Content-Type", " text/plain; charset=UTF-8"); |
466 |
for(Entry<String,String> entry : headers.entrySet()){ |
467 |
addObject.addHeader(entry.getKey(),entry.getValue()); |
468 |
} |
469 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
470 |
|
471 |
HttpBundle bundle = new HttpBundle();
|
472 |
bundle.setCurlRequest(addObject); |
473 |
|
474 |
try {
|
475 |
resp = httpclient.execute(addObject); |
476 |
bundle.setHttpResponse(resp); |
477 |
} catch (ClientProtocolException e) {
|
478 |
CloudServersException cse = new CloudServersException();
|
479 |
cse.setMessage(e.getLocalizedMessage()); |
480 |
throw cse;
|
481 |
} catch (IOException e) { |
482 |
CloudServersException cse = new CloudServersException();
|
483 |
cse.setMessage(e.getLocalizedMessage()); |
484 |
throw cse;
|
485 |
} catch (FactoryConfigurationError e) { |
486 |
CloudServersException cse = new CloudServersException();
|
487 |
cse.setMessage(e.getLocalizedMessage()); |
488 |
throw cse;
|
489 |
} |
490 |
return bundle;
|
491 |
} |
492 |
|
493 |
/*
|
494 |
* used for adding text files, requires an extra parameter to store the data
|
495 |
* for the file
|
496 |
*/
|
497 |
public HttpBundle addObject(String Container, String Path, String Object, |
498 |
String type, String data) throws CloudServersException { |
499 |
HttpResponse resp = null;
|
500 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
501 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container |
502 |
+ "/" + Path + Object); |
503 |
HttpPut addObject = new HttpPut(url);
|
504 |
|
505 |
addObject |
506 |
.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
507 |
addObject.addHeader("Content-Type", type);
|
508 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
509 |
|
510 |
StringEntity tmp = null;
|
511 |
try {
|
512 |
tmp = new StringEntity(data);
|
513 |
} catch (UnsupportedEncodingException e) { |
514 |
CloudServersException cse = new CloudServersException();
|
515 |
cse.setMessage(e.getLocalizedMessage()); |
516 |
throw cse;
|
517 |
} |
518 |
addObject.setEntity(tmp); |
519 |
|
520 |
HttpBundle bundle = new HttpBundle();
|
521 |
bundle.setCurlRequest(addObject); |
522 |
|
523 |
try {
|
524 |
resp = httpclient.execute(addObject); |
525 |
bundle.setHttpResponse(resp); |
526 |
} catch (ClientProtocolException e) {
|
527 |
CloudServersException cse = new CloudServersException();
|
528 |
cse.setMessage(e.getLocalizedMessage()); |
529 |
throw cse;
|
530 |
} catch (IOException e) { |
531 |
CloudServersException cse = new CloudServersException();
|
532 |
cse.setMessage(e.getLocalizedMessage()); |
533 |
throw cse;
|
534 |
} catch (FactoryConfigurationError e) { |
535 |
CloudServersException cse = new CloudServersException();
|
536 |
cse.setMessage(e.getLocalizedMessage()); |
537 |
throw cse;
|
538 |
} |
539 |
return bundle;
|
540 |
} |
541 |
|
542 |
private String getSafeURL(String badURL, String name) { |
543 |
URI uri = null; |
544 |
try {
|
545 |
uri = new URI("https", badURL.substring(8), "/" + name + "/", ""); |
546 |
} catch (URISyntaxException e1) { |
547 |
// TODO Auto-generated catch block
|
548 |
e1.printStackTrace(); |
549 |
} |
550 |
String url = null; |
551 |
try {
|
552 |
url = uri.toURL().toString(); |
553 |
} catch (MalformedURLException e1) { |
554 |
// TODO Auto-generated catch block
|
555 |
e1.printStackTrace(); |
556 |
} |
557 |
return url.substring(0, url.length() - 2); |
558 |
} |
559 |
|
560 |
} |