root / src / com / rackspace / cloud / servers / api / client / ServerManager.java @ 697895bc
History | View | Annotate | Download (20 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.servers.api.client; |
5 |
|
6 |
import java.io.IOException; |
7 |
import java.io.StringReader; |
8 |
import java.io.UnsupportedEncodingException; |
9 |
import java.util.ArrayList; |
10 |
|
11 |
import javax.xml.parsers.FactoryConfigurationError; |
12 |
import javax.xml.parsers.ParserConfigurationException; |
13 |
import javax.xml.parsers.SAXParser; |
14 |
import javax.xml.parsers.SAXParserFactory; |
15 |
|
16 |
import org.apache.http.HttpResponse; |
17 |
import org.apache.http.client.ClientProtocolException; |
18 |
import org.apache.http.client.methods.HttpDelete; |
19 |
import org.apache.http.client.methods.HttpGet; |
20 |
import org.apache.http.client.methods.HttpPost; |
21 |
import org.apache.http.client.methods.HttpPut; |
22 |
import org.apache.http.entity.StringEntity; |
23 |
import org.apache.http.impl.client.BasicResponseHandler; |
24 |
import org.apache.http.protocol.RequestExpectContinue; |
25 |
import org.xml.sax.InputSource; |
26 |
import org.xml.sax.SAXException; |
27 |
import org.xml.sax.XMLReader; |
28 |
|
29 |
import android.content.Context; |
30 |
import android.util.Log; |
31 |
|
32 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
33 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
34 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
35 |
import com.rackspace.cloud.servers.api.client.parsers.ServersXMLParser; |
36 |
|
37 |
/**
|
38 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
|
39 |
*
|
40 |
*/
|
41 |
public class ServerManager extends EntityManager { |
42 |
|
43 |
public static final String SOFT_REBOOT = "SOFT"; |
44 |
public static final String HARD_REBOOT = "HARD"; |
45 |
|
46 |
public void create(Server entity, Context context) throws CloudServersException { |
47 |
|
48 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
49 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers.xml"); |
50 |
|
51 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
52 |
post.addHeader("Content-Type", "application/xml"); |
53 |
|
54 |
StringEntity tmp = null;
|
55 |
try {
|
56 |
tmp = new StringEntity(entity.toXML());
|
57 |
} catch (UnsupportedEncodingException e) { |
58 |
CloudServersException cse = new CloudServersException();
|
59 |
cse.setMessage(e.getLocalizedMessage()); |
60 |
throw cse;
|
61 |
} |
62 |
post.setEntity(tmp); |
63 |
|
64 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
65 |
|
66 |
try {
|
67 |
HttpResponse resp = httpclient.execute(post); |
68 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
69 |
String body = responseHandler.handleResponse(resp);
|
70 |
|
71 |
if (resp.getStatusLine().getStatusCode() == 202) { |
72 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
73 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
74 |
XMLReader xmlReader = saxParser.getXMLReader(); |
75 |
xmlReader.setContentHandler(serversXMLParser); |
76 |
xmlReader.parse(new InputSource(new StringReader(body))); |
77 |
entity = serversXMLParser.getServer(); |
78 |
} else {
|
79 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
80 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
81 |
XMLReader xmlReader = saxParser.getXMLReader(); |
82 |
xmlReader.setContentHandler(parser); |
83 |
xmlReader.parse(new InputSource(new StringReader(body))); |
84 |
CloudServersException cse = parser.getException(); |
85 |
throw cse;
|
86 |
} |
87 |
} catch (ClientProtocolException e) {
|
88 |
CloudServersException cse = new CloudServersException();
|
89 |
cse.setMessage(e.getLocalizedMessage()); |
90 |
throw cse;
|
91 |
} catch (IOException e) { |
92 |
CloudServersException cse = new CloudServersException();
|
93 |
cse.setMessage(e.getLocalizedMessage()); |
94 |
throw cse;
|
95 |
} catch (FactoryConfigurationError e) { |
96 |
CloudServersException cse = new CloudServersException();
|
97 |
cse.setMessage(e.getLocalizedMessage()); |
98 |
throw cse;
|
99 |
} catch (ParserConfigurationException e) { |
100 |
CloudServersException cse = new CloudServersException();
|
101 |
cse.setMessage(e.getLocalizedMessage()); |
102 |
throw cse;
|
103 |
} catch (SAXException e) {
|
104 |
CloudServersException cse = new CloudServersException();
|
105 |
cse.setMessage(e.getLocalizedMessage()); |
106 |
throw cse;
|
107 |
} |
108 |
} |
109 |
|
110 |
public ArrayList<Server> createList(boolean detail, Context context) throws CloudServersException { |
111 |
|
112 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
113 |
HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/servers/detail.xml" + cacheBuster()); |
114 |
ArrayList<Server> servers = new ArrayList<Server>(); |
115 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
116 |
|
117 |
try {
|
118 |
HttpResponse resp = httpclient.execute(get); |
119 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
120 |
String body = responseHandler.handleResponse(resp);
|
121 |
|
122 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) { |
123 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
124 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
125 |
XMLReader xmlReader = saxParser.getXMLReader(); |
126 |
xmlReader.setContentHandler(serversXMLParser); |
127 |
xmlReader.parse(new InputSource(new StringReader(body))); |
128 |
servers = serversXMLParser.getServers(); |
129 |
} else {
|
130 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
131 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
132 |
XMLReader xmlReader = saxParser.getXMLReader(); |
133 |
xmlReader.setContentHandler(parser); |
134 |
xmlReader.parse(new InputSource(new StringReader(body))); |
135 |
CloudServersException cse = parser.getException(); |
136 |
throw cse;
|
137 |
} |
138 |
} catch (ClientProtocolException e) {
|
139 |
CloudServersException cse = new CloudServersException();
|
140 |
cse.setMessage(e.getLocalizedMessage()); |
141 |
throw cse;
|
142 |
} catch (IOException e) { |
143 |
CloudServersException cse = new CloudServersException();
|
144 |
cse.setMessage(e.getLocalizedMessage()); |
145 |
throw cse;
|
146 |
} catch (ParserConfigurationException e) { |
147 |
CloudServersException cse = new CloudServersException();
|
148 |
cse.setMessage(e.getLocalizedMessage()); |
149 |
throw cse;
|
150 |
} catch (SAXException e) {
|
151 |
CloudServersException cse = new CloudServersException();
|
152 |
cse.setMessage(e.getLocalizedMessage()); |
153 |
throw cse;
|
154 |
} catch (FactoryConfigurationError e) { |
155 |
CloudServersException cse = new CloudServersException();
|
156 |
cse.setMessage(e.getLocalizedMessage()); |
157 |
throw cse;
|
158 |
} |
159 |
|
160 |
|
161 |
return servers;
|
162 |
} |
163 |
|
164 |
public Server find(long id, Context context) throws CloudServersException { |
165 |
|
166 |
Server server = null;
|
167 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
168 |
HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/servers/" + id + ".xml" + cacheBuster()); |
169 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
170 |
|
171 |
try {
|
172 |
HttpResponse resp = httpclient.execute(get); |
173 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
174 |
String body = responseHandler.handleResponse(resp);
|
175 |
|
176 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) { |
177 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
178 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
179 |
XMLReader xmlReader = saxParser.getXMLReader(); |
180 |
xmlReader.setContentHandler(serversXMLParser); |
181 |
xmlReader.parse(new InputSource(new StringReader(body))); |
182 |
server = serversXMLParser.getServer(); |
183 |
} else {
|
184 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
185 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
186 |
XMLReader xmlReader = saxParser.getXMLReader(); |
187 |
xmlReader.setContentHandler(parser); |
188 |
xmlReader.parse(new InputSource(new StringReader(body))); |
189 |
CloudServersException cse = parser.getException(); |
190 |
throw cse;
|
191 |
} |
192 |
} catch (ClientProtocolException e) {
|
193 |
CloudServersException cse = new CloudServersException();
|
194 |
cse.setMessage(e.getLocalizedMessage()); |
195 |
throw cse;
|
196 |
} catch (IOException e) { |
197 |
CloudServersException cse = new CloudServersException();
|
198 |
cse.setMessage(e.getLocalizedMessage()); |
199 |
throw cse;
|
200 |
} catch (ParserConfigurationException e) { |
201 |
CloudServersException cse = new CloudServersException();
|
202 |
cse.setMessage(e.getLocalizedMessage()); |
203 |
throw cse;
|
204 |
} catch (SAXException e) {
|
205 |
CloudServersException cse = new CloudServersException();
|
206 |
cse.setMessage(e.getLocalizedMessage()); |
207 |
throw cse;
|
208 |
} catch (FactoryConfigurationError e) { |
209 |
CloudServersException cse = new CloudServersException();
|
210 |
cse.setMessage(e.getLocalizedMessage()); |
211 |
throw cse;
|
212 |
} |
213 |
|
214 |
return server;
|
215 |
} |
216 |
|
217 |
public HttpBundle reboot(Server server, String rebootType, Context context) throws CloudServersException { |
218 |
HttpResponse resp = null;
|
219 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
220 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
221 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
222 |
post.addHeader("Content-Type", "application/xml"); |
223 |
|
224 |
StringEntity tmp = null;
|
225 |
try {
|
226 |
tmp = new StringEntity("<reboot xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" type=\"" + rebootType + "\"/>"); |
227 |
} catch (UnsupportedEncodingException e) { |
228 |
CloudServersException cse = new CloudServersException();
|
229 |
cse.setMessage(e.getLocalizedMessage()); |
230 |
throw cse;
|
231 |
} |
232 |
post.setEntity(tmp); |
233 |
|
234 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
235 |
|
236 |
HttpBundle bundle = new HttpBundle();
|
237 |
bundle.setCurlRequest(post); |
238 |
|
239 |
try {
|
240 |
resp = httpclient.execute(post); |
241 |
bundle.setHttpResponse(resp); |
242 |
} catch (ClientProtocolException e) {
|
243 |
CloudServersException cse = new CloudServersException();
|
244 |
cse.setMessage(e.getLocalizedMessage()); |
245 |
throw cse;
|
246 |
} catch (IOException e) { |
247 |
CloudServersException cse = new CloudServersException();
|
248 |
cse.setMessage(e.getLocalizedMessage()); |
249 |
throw cse;
|
250 |
} catch (FactoryConfigurationError e) { |
251 |
CloudServersException cse = new CloudServersException();
|
252 |
cse.setMessage(e.getLocalizedMessage()); |
253 |
throw cse;
|
254 |
} |
255 |
return bundle;
|
256 |
} |
257 |
|
258 |
public HttpBundle resize(Server server, int flavorId, Context context) throws CloudServersException { |
259 |
HttpResponse resp = null;
|
260 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
261 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
262 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
263 |
post.addHeader("Content-Type", "application/xml"); |
264 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
265 |
|
266 |
StringEntity tmp = null;
|
267 |
try {
|
268 |
tmp = new StringEntity("<resize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" flavorId=\"" + flavorId + "\"/>"); |
269 |
} catch (UnsupportedEncodingException e) { |
270 |
CloudServersException cse = new CloudServersException();
|
271 |
cse.setMessage(e.getLocalizedMessage()); |
272 |
throw cse;
|
273 |
} |
274 |
post.setEntity(tmp); |
275 |
|
276 |
HttpBundle bundle = new HttpBundle();
|
277 |
bundle.setCurlRequest(post); |
278 |
|
279 |
try {
|
280 |
resp = httpclient.execute(post); |
281 |
bundle.setHttpResponse(resp); |
282 |
} catch (ClientProtocolException e) {
|
283 |
CloudServersException cse = new CloudServersException();
|
284 |
cse.setMessage(e.getLocalizedMessage()); |
285 |
throw cse;
|
286 |
} catch (IOException e) { |
287 |
CloudServersException cse = new CloudServersException();
|
288 |
cse.setMessage(e.getLocalizedMessage()); |
289 |
throw cse;
|
290 |
} catch (FactoryConfigurationError e) { |
291 |
CloudServersException cse = new CloudServersException();
|
292 |
cse.setMessage(e.getLocalizedMessage()); |
293 |
throw cse;
|
294 |
} |
295 |
return bundle;
|
296 |
} |
297 |
|
298 |
public HttpBundle confirmResize(Server server, Context context) throws CloudServersException { |
299 |
HttpResponse resp = null;
|
300 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
301 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
302 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
303 |
post.addHeader("Content-Type", "application/xml"); |
304 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
305 |
|
306 |
StringEntity tmp = null;
|
307 |
try {
|
308 |
tmp = new StringEntity("<confirmResize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\">"); |
309 |
} catch (UnsupportedEncodingException e) { |
310 |
CloudServersException cse = new CloudServersException();
|
311 |
cse.setMessage(e.getLocalizedMessage()); |
312 |
throw cse;
|
313 |
} |
314 |
post.setEntity(tmp); |
315 |
|
316 |
HttpBundle bundle = new HttpBundle();
|
317 |
bundle.setCurlRequest(post); |
318 |
|
319 |
try {
|
320 |
resp = httpclient.execute(post); |
321 |
bundle.setHttpResponse(resp); |
322 |
} catch (ClientProtocolException e) {
|
323 |
CloudServersException cse = new CloudServersException();
|
324 |
cse.setMessage(e.getLocalizedMessage()); |
325 |
throw cse;
|
326 |
} catch (IOException e) { |
327 |
CloudServersException cse = new CloudServersException();
|
328 |
cse.setMessage(e.getLocalizedMessage()); |
329 |
throw cse;
|
330 |
} catch (FactoryConfigurationError e) { |
331 |
CloudServersException cse = new CloudServersException();
|
332 |
cse.setMessage(e.getLocalizedMessage()); |
333 |
throw cse;
|
334 |
} |
335 |
return bundle;
|
336 |
} |
337 |
|
338 |
|
339 |
public HttpBundle delete(Server server, Context context) throws CloudServersException { |
340 |
HttpResponse resp = null;
|
341 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
342 |
HttpDelete delete = new HttpDelete(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
343 |
delete.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
344 |
delete.addHeader("Content-Type", "application/xml"); |
345 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
346 |
|
347 |
HttpBundle bundle = new HttpBundle();
|
348 |
bundle.setCurlRequest(delete); |
349 |
|
350 |
try {
|
351 |
resp = httpclient.execute(delete); |
352 |
bundle.setHttpResponse(resp); |
353 |
} catch (ClientProtocolException e) {
|
354 |
CloudServersException cse = new CloudServersException();
|
355 |
cse.setMessage(e.getLocalizedMessage()); |
356 |
throw cse;
|
357 |
} catch (IOException e) { |
358 |
CloudServersException cse = new CloudServersException();
|
359 |
cse.setMessage(e.getLocalizedMessage()); |
360 |
throw cse;
|
361 |
} catch (FactoryConfigurationError e) { |
362 |
CloudServersException cse = new CloudServersException();
|
363 |
cse.setMessage(e.getLocalizedMessage()); |
364 |
throw cse;
|
365 |
} |
366 |
return bundle;
|
367 |
} |
368 |
|
369 |
public HttpBundle rename(Server server, String name, Context context) throws CloudServersException{ |
370 |
HttpResponse resp = null;
|
371 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
372 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
373 |
|
374 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
375 |
put.addHeader("Content-Type", "application/xml"); |
376 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
377 |
|
378 |
StringEntity tmp = null;
|
379 |
try {
|
380 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" name=\"" + name + "\"/>"); |
381 |
} catch (UnsupportedEncodingException e) { |
382 |
CloudServersException cse = new CloudServersException();
|
383 |
cse.setMessage(e.getLocalizedMessage()); |
384 |
throw cse;
|
385 |
} |
386 |
put.setEntity(tmp); |
387 |
|
388 |
HttpBundle bundle = new HttpBundle();
|
389 |
bundle.setCurlRequest(put); |
390 |
|
391 |
try {
|
392 |
resp = httpclient.execute(put); |
393 |
bundle.setHttpResponse(resp); |
394 |
} catch (ClientProtocolException e) {
|
395 |
CloudServersException cse = new CloudServersException();
|
396 |
cse.setMessage(e.getLocalizedMessage()); |
397 |
throw cse;
|
398 |
} catch (IOException e) { |
399 |
CloudServersException cse = new CloudServersException();
|
400 |
cse.setMessage(e.getLocalizedMessage()); |
401 |
throw cse;
|
402 |
} catch (FactoryConfigurationError e) { |
403 |
CloudServersException cse = new CloudServersException();
|
404 |
cse.setMessage(e.getLocalizedMessage()); |
405 |
throw cse;
|
406 |
} |
407 |
return bundle;
|
408 |
} |
409 |
|
410 |
public HttpBundle rebuild(Server server, int imageId, Context context) throws CloudServersException { |
411 |
HttpResponse resp = null;
|
412 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
413 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
414 |
|
415 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
416 |
post.addHeader("Content-Type", "application/xml"); |
417 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
418 |
|
419 |
StringEntity tmp = null;
|
420 |
try {
|
421 |
tmp = new StringEntity("<rebuild xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" imageId=\"" + imageId + "\"/>"); |
422 |
} catch (UnsupportedEncodingException e) { |
423 |
CloudServersException cse = new CloudServersException();
|
424 |
cse.setMessage(e.getLocalizedMessage()); |
425 |
throw cse;
|
426 |
} |
427 |
post.setEntity(tmp); |
428 |
|
429 |
HttpBundle bundle = new HttpBundle();
|
430 |
bundle.setCurlRequest(post); |
431 |
|
432 |
try {
|
433 |
resp = httpclient.execute(post); |
434 |
bundle.setHttpResponse(resp); |
435 |
} catch (ClientProtocolException e) {
|
436 |
CloudServersException cse = new CloudServersException();
|
437 |
cse.setMessage(e.getLocalizedMessage()); |
438 |
throw cse;
|
439 |
} catch (IOException e) { |
440 |
CloudServersException cse = new CloudServersException();
|
441 |
cse.setMessage(e.getLocalizedMessage()); |
442 |
throw cse;
|
443 |
} catch (FactoryConfigurationError e) { |
444 |
CloudServersException cse = new CloudServersException();
|
445 |
cse.setMessage(e.getLocalizedMessage()); |
446 |
throw cse;
|
447 |
} |
448 |
return bundle;
|
449 |
} |
450 |
|
451 |
public HttpBundle backup(Server server, String weeklyValue, String dailyValue, boolean enabled, Context context) throws CloudServersException { |
452 |
HttpResponse resp = null;
|
453 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
454 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/backup_schedule.xml"); |
455 |
|
456 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
457 |
post.addHeader("Content-Type", "application/xml"); |
458 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
459 |
|
460 |
StringEntity tmp = null;
|
461 |
try {
|
462 |
tmp = new StringEntity("<backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
463 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
464 |
|
465 |
} catch (UnsupportedEncodingException e) { |
466 |
CloudServersException cse = new CloudServersException();
|
467 |
cse.setMessage(e.getLocalizedMessage()); |
468 |
throw cse;
|
469 |
} |
470 |
post.setEntity(tmp); |
471 |
|
472 |
HttpBundle bundle = new HttpBundle();
|
473 |
bundle.setCurlRequest(post); |
474 |
|
475 |
try {
|
476 |
resp = httpclient.execute(post); |
477 |
bundle.setHttpResponse(resp); |
478 |
} catch (ClientProtocolException e) {
|
479 |
CloudServersException cse = new CloudServersException();
|
480 |
cse.setMessage(e.getLocalizedMessage()); |
481 |
throw cse;
|
482 |
} catch (IOException e) { |
483 |
CloudServersException cse = new CloudServersException();
|
484 |
cse.setMessage(e.getLocalizedMessage()); |
485 |
throw cse;
|
486 |
} catch (FactoryConfigurationError e) { |
487 |
CloudServersException cse = new CloudServersException();
|
488 |
cse.setMessage(e.getLocalizedMessage()); |
489 |
throw cse;
|
490 |
} |
491 |
return bundle;
|
492 |
} |
493 |
|
494 |
public HttpBundle changePassword(Server server, String password, Context context) throws CloudServersException{ |
495 |
HttpResponse resp = null;
|
496 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
497 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
498 |
|
499 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
500 |
put.addHeader("Content-Type", "application/xml"); |
501 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
502 |
|
503 |
StringEntity tmp = null;
|
504 |
try {
|
505 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" adminPass=\"" + password + "\"/>"); |
506 |
} catch (UnsupportedEncodingException e) { |
507 |
CloudServersException cse = new CloudServersException();
|
508 |
cse.setMessage(e.getLocalizedMessage()); |
509 |
throw cse;
|
510 |
} |
511 |
put.setEntity(tmp); |
512 |
|
513 |
HttpBundle bundle = new HttpBundle();
|
514 |
bundle.setCurlRequest(put); |
515 |
|
516 |
try {
|
517 |
resp = httpclient.execute(put); |
518 |
bundle.setHttpResponse(resp); |
519 |
} catch (ClientProtocolException e) {
|
520 |
CloudServersException cse = new CloudServersException();
|
521 |
cse.setMessage(e.getLocalizedMessage()); |
522 |
throw cse;
|
523 |
} catch (IOException e) { |
524 |
CloudServersException cse = new CloudServersException();
|
525 |
cse.setMessage(e.getLocalizedMessage()); |
526 |
throw cse;
|
527 |
} catch (FactoryConfigurationError e) { |
528 |
CloudServersException cse = new CloudServersException();
|
529 |
cse.setMessage(e.getLocalizedMessage()); |
530 |
throw cse;
|
531 |
} |
532 |
return bundle;
|
533 |
} |
534 |
|
535 |
|
536 |
} |