Revision 006434d8 src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 | 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; |
|
5 | 9 |
import java.util.ArrayList; |
6 | 10 |
|
7 | 11 |
import javax.xml.parsers.FactoryConfigurationError; |
... | ... | |
14 | 18 |
import org.apache.http.client.methods.HttpDelete; |
15 | 19 |
import org.apache.http.client.methods.HttpGet; |
16 | 20 |
import org.apache.http.client.methods.HttpPut; |
21 |
import org.apache.http.entity.StringEntity; |
|
17 | 22 |
import org.apache.http.impl.client.BasicResponseHandler; |
18 | 23 |
import org.apache.http.protocol.RequestExpectContinue; |
19 | 24 |
import org.xml.sax.InputSource; |
... | ... | |
21 | 26 |
import org.xml.sax.XMLReader; |
22 | 27 |
|
23 | 28 |
import android.content.Context; |
29 |
import android.util.Log; |
|
24 | 30 |
|
25 | 31 |
import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser; |
26 | 32 |
import com.rackspace.cloud.servers.api.client.Account; |
... | ... | |
47 | 53 |
public ArrayList<ContainerObjects> createList(boolean detail, String passName) throws CloudServersException { |
48 | 54 |
|
49 | 55 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
50 |
HttpGet get = new HttpGet(Account.getAccount().getStorageUrl()+"/"+passName + "?format=xml"); |
|
56 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), passName) + "?format=xml"; |
|
57 |
Log.d("info", "captin the url creatlist: " + url); |
|
58 |
HttpGet get = new HttpGet(url); |
|
51 | 59 |
ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>(); |
52 | 60 |
|
53 | 61 |
|
... | ... | |
107 | 115 |
public HttpBundle deleteObject(String Container, String Object) throws CloudServersException { |
108 | 116 |
HttpResponse resp = null; |
109 | 117 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
110 |
HttpDelete deleteObject = new HttpDelete(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Object); |
|
118 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object); |
|
119 |
HttpDelete deleteObject = new HttpDelete(url); |
|
120 |
Log.d("info", "captin the url deleteobject: " + url); |
|
111 | 121 |
|
112 | 122 |
deleteObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
113 | 123 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
... | ... | |
137 | 147 |
public HttpBundle getObject(String Container, String Object) throws CloudServersException { |
138 | 148 |
HttpResponse resp = null; |
139 | 149 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
140 |
HttpGet getObject = new HttpGet(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Object); |
|
141 |
|
|
150 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object); |
|
151 |
HttpGet getObject = new HttpGet(url); |
|
152 |
Log.d("info", "captin the url getobject: " + url); |
|
142 | 153 |
getObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
143 | 154 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
144 | 155 |
|
... | ... | |
167 | 178 |
public HttpBundle addObject(String Container, String Path, String Object, String type) throws CloudServersException { |
168 | 179 |
HttpResponse resp = null; |
169 | 180 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
170 |
HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object); |
|
171 |
|
|
181 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object); |
|
182 |
HttpPut addObject = new HttpPut(url); |
|
183 |
Log.d("info", "captin the url addobject: " + url); |
|
184 |
|
|
172 | 185 |
addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
173 | 186 |
addObject.addHeader("Content-Type", type); |
174 | 187 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
... | ... | |
202 | 215 |
public HttpBundle addObject(String Container, String Path, String Object, String type, String data) throws CloudServersException { |
203 | 216 |
HttpResponse resp = null; |
204 | 217 |
CustomHttpClient httpclient = new CustomHttpClient(context); |
205 |
HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object); |
|
218 |
String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object); |
|
219 |
HttpPut addObject = new HttpPut(url); |
|
220 |
Log.d("info", "captin the url addobject2: " + url); |
|
206 | 221 |
|
207 | 222 |
addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken()); |
208 | 223 |
addObject.addHeader("Content-Type", type); |
209 | 224 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
210 | 225 |
|
226 |
StringEntity tmp = null; |
|
227 |
try { |
|
228 |
tmp = new StringEntity(data); |
|
229 |
} catch (UnsupportedEncodingException e) { |
|
230 |
CloudServersException cse = new CloudServersException(); |
|
231 |
cse.setMessage(e.getLocalizedMessage()); |
|
232 |
throw cse; |
|
233 |
} |
|
234 |
addObject.setEntity(tmp); |
|
235 |
|
|
211 | 236 |
HttpBundle bundle = new HttpBundle(); |
212 | 237 |
bundle.setCurlRequest(addObject); |
213 | 238 |
|
... | ... | |
229 | 254 |
} |
230 | 255 |
return bundle; |
231 | 256 |
} |
257 |
|
|
258 |
private String getSafeURL(String badURL, String name){ |
|
259 |
URI uri = null; |
|
260 |
try { |
|
261 |
uri = new URI("https", badURL.substring(8), "/" + name + "/", ""); |
|
262 |
} catch (URISyntaxException e1) { |
|
263 |
// TODO Auto-generated catch block |
|
264 |
e1.printStackTrace(); |
|
265 |
} |
|
266 |
String url = null; |
|
267 |
try { |
|
268 |
url = uri.toURL().toString(); |
|
269 |
} catch (MalformedURLException e1) { |
|
270 |
// TODO Auto-generated catch block |
|
271 |
e1.printStackTrace(); |
|
272 |
} |
|
273 |
return url.substring(0, url.length()-2); |
|
274 |
} |
|
232 | 275 |
|
233 | 276 |
} |
Also available in: Unified diff