Revision 666c8e11 src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java | ||
---|---|---|
17 | 17 |
import javax.xml.parsers.SAXParser; |
18 | 18 |
import javax.xml.parsers.SAXParserFactory; |
19 | 19 |
|
20 |
import org.apache.http.Header; |
|
20 | 21 |
import org.apache.http.HttpResponse; |
21 | 22 |
import org.apache.http.client.ClientProtocolException; |
22 | 23 |
import org.apache.http.client.methods.HttpDelete; |
23 | 24 |
import org.apache.http.client.methods.HttpGet; |
25 |
import org.apache.http.client.methods.HttpHead; |
|
24 | 26 |
import org.apache.http.client.methods.HttpPost; |
25 | 27 |
import org.apache.http.client.methods.HttpPut; |
26 | 28 |
import org.apache.http.client.methods.HttpRequestBase; |
... | ... | |
61 | 63 |
this.context = context; |
62 | 64 |
} |
63 | 65 |
|
66 |
public ContainerObjects executeHead(String containerName, String cname) throws CloudServersException{ |
|
67 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
|
68 |
String url = Account.getAccount().getStorageUrl()+"/"+ containerName |
|
69 |
+ "/" + cname+"?format=xml"; |
|
70 |
Log.i(LOG,url); |
|
71 |
HttpHead get = new HttpHead(url); |
|
72 |
get.addHeader("Content-Type", "application/xml"); |
|
73 |
get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken); |
|
74 |
|
|
75 |
try { |
|
76 |
HttpResponse resp = httpclient.execute(get); |
|
77 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
78 |
String body = responseHandler.handleResponse(resp); |
|
79 |
|
|
80 |
if (resp.getStatusLine().getStatusCode() == 200 |
|
81 |
|| resp.getStatusLine().getStatusCode() == 203) { |
|
82 |
|
|
83 |
ContainerObjects objects = new ContainerObjects(); |
|
84 |
for(Header h : resp.getAllHeaders()){ |
|
85 |
if(h.getName().equals("Content-Type")) |
|
86 |
objects.setContentType(h.getValue()); |
|
87 |
else if(h.getName().equals("X-Object-Public")) |
|
88 |
objects.setIsPublic(h.getValue()); |
|
89 |
else if(h.getName().equals("Content-Length")) |
|
90 |
objects.setBytes(Integer.parseInt(h.getValue())); |
|
91 |
else if(h.getName().equals("X-Object-Public")) |
|
92 |
objects.setIsPublic(h.getValue()); |
|
93 |
else if(h.getName().equals("X-Object-Modified-By")) |
|
94 |
objects.setModifiedBy(h.getValue()); |
|
95 |
else if(h.getName().equals("X-Object-UUID")) |
|
96 |
objects.setObjectUUID(h.getValue()); |
|
97 |
else if(h.getName().equals("X-Object-Hash")) |
|
98 |
objects.setObjectHash(h.getValue()); |
|
99 |
else if(h.getName().equals("X-Object-Version")) |
|
100 |
objects.setVersion(h.getValue()); |
|
101 |
else if(h.getName().equals("X-Object-Version-Timestamp")) |
|
102 |
objects.setVersionTimestamp(h.getValue()); |
|
103 |
else if(h.getName().equals("X-Object-Sharing")) |
|
104 |
objects.setObjectSharing(h.getValue()); |
|
105 |
else if(h.getName().equals("Last-Modified")) |
|
106 |
objects.setLastMod(h.getValue()); |
|
107 |
else if(h.getName().startsWith("X-Object-Meta")){ |
|
108 |
if(objects.getMetadata()==null) |
|
109 |
objects.setMetadata(new HashMap<String, String>()); |
|
110 |
objects.getMetadata().put(h.getName().replaceAll("X-Object-Meta-", ""),h.getValue()); |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 |
objects.setContainerName(containerName); |
|
115 |
objects.setCName(cname); |
|
116 |
return objects; |
|
117 |
|
|
118 |
} else { |
|
119 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser(); |
|
120 |
SAXParser saxParser = SAXParserFactory.newInstance() |
|
121 |
.newSAXParser(); |
|
122 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
123 |
xmlReader.setContentHandler(parser); |
|
124 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
125 |
CloudServersException cse = parser.getException(); |
|
126 |
throw cse; |
|
127 |
} |
|
128 |
} catch (ClientProtocolException e) { |
|
129 |
CloudServersException cse = new CloudServersException(); |
|
130 |
cse.setMessage(e.getLocalizedMessage()); |
|
131 |
throw cse; |
|
132 |
} catch (IOException e) { |
|
133 |
CloudServersException cse = new CloudServersException(); |
|
134 |
cse.setMessage(e.getLocalizedMessage()); |
|
135 |
throw cse; |
|
136 |
} catch (ParserConfigurationException e) { |
|
137 |
CloudServersException cse = new CloudServersException(); |
|
138 |
cse.setMessage(e.getLocalizedMessage()); |
|
139 |
throw cse; |
|
140 |
} catch (SAXException e) { |
|
141 |
CloudServersException cse = new CloudServersException(); |
|
142 |
cse.setMessage(e.getLocalizedMessage()); |
|
143 |
throw cse; |
|
144 |
} catch (FactoryConfigurationError e) { |
|
145 |
CloudServersException cse = new CloudServersException(); |
|
146 |
cse.setMessage(e.getLocalizedMessage()); |
|
147 |
throw cse; |
|
148 |
} |
|
149 |
|
|
150 |
} |
|
64 | 151 |
|
65 | 152 |
private List<ContainerObjects> executeGet(String containerName, String url) throws CloudServersException{ |
66 | 153 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
... | ... | |
344 | 431 |
} |
345 | 432 |
|
346 | 433 |
|
434 |
public HttpBundle getObject(String Container, String Object, String version) |
|
435 |
throws CloudServersException { |
|
436 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container |
|
437 |
+ "/" + Object+"?version="+version); |
|
438 |
return executeMethod(GET, url); |
|
439 |
} |
|
440 |
|
|
441 |
|
|
347 | 442 |
|
348 | 443 |
public HttpBundle addObject(String Container, String Path, String Object, |
349 | 444 |
String type) throws CloudServersException { |
Also available in: Unified diff