root / src / com / rackspace / cloud / servers / api / client / ServerManager.java @ 006434d8
History | View | Annotate | Download (20.1 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 |
Log.d("info", "captin the flavor id is " + flavorId); |
269 |
tmp = new StringEntity("<resize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" flavorId=\"" + flavorId + "\"/>"); |
270 |
} catch (UnsupportedEncodingException e) { |
271 |
CloudServersException cse = new CloudServersException();
|
272 |
cse.setMessage(e.getLocalizedMessage()); |
273 |
throw cse;
|
274 |
} |
275 |
post.setEntity(tmp); |
276 |
|
277 |
HttpBundle bundle = new HttpBundle();
|
278 |
bundle.setCurlRequest(post); |
279 |
|
280 |
try {
|
281 |
resp = httpclient.execute(post); |
282 |
bundle.setHttpResponse(resp); |
283 |
} catch (ClientProtocolException e) {
|
284 |
CloudServersException cse = new CloudServersException();
|
285 |
cse.setMessage(e.getLocalizedMessage()); |
286 |
throw cse;
|
287 |
} catch (IOException e) { |
288 |
CloudServersException cse = new CloudServersException();
|
289 |
cse.setMessage(e.getLocalizedMessage()); |
290 |
throw cse;
|
291 |
} catch (FactoryConfigurationError e) { |
292 |
CloudServersException cse = new CloudServersException();
|
293 |
cse.setMessage(e.getLocalizedMessage()); |
294 |
throw cse;
|
295 |
} |
296 |
return bundle;
|
297 |
} |
298 |
|
299 |
public HttpBundle confirmResize(Server server, Context context) throws CloudServersException { |
300 |
HttpResponse resp = null;
|
301 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
302 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
303 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
304 |
post.addHeader("Content-Type", "application/xml"); |
305 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
306 |
|
307 |
StringEntity tmp = null;
|
308 |
try {
|
309 |
tmp = new StringEntity("<confirmResize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\">"); |
310 |
} catch (UnsupportedEncodingException e) { |
311 |
CloudServersException cse = new CloudServersException();
|
312 |
cse.setMessage(e.getLocalizedMessage()); |
313 |
throw cse;
|
314 |
} |
315 |
post.setEntity(tmp); |
316 |
|
317 |
HttpBundle bundle = new HttpBundle();
|
318 |
bundle.setCurlRequest(post); |
319 |
|
320 |
try {
|
321 |
resp = httpclient.execute(post); |
322 |
bundle.setHttpResponse(resp); |
323 |
} catch (ClientProtocolException e) {
|
324 |
CloudServersException cse = new CloudServersException();
|
325 |
cse.setMessage(e.getLocalizedMessage()); |
326 |
throw cse;
|
327 |
} catch (IOException e) { |
328 |
CloudServersException cse = new CloudServersException();
|
329 |
cse.setMessage(e.getLocalizedMessage()); |
330 |
throw cse;
|
331 |
} catch (FactoryConfigurationError e) { |
332 |
CloudServersException cse = new CloudServersException();
|
333 |
cse.setMessage(e.getLocalizedMessage()); |
334 |
throw cse;
|
335 |
} |
336 |
return bundle;
|
337 |
} |
338 |
|
339 |
|
340 |
public HttpBundle delete(Server server, Context context) throws CloudServersException { |
341 |
HttpResponse resp = null;
|
342 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
343 |
HttpDelete delete = new HttpDelete(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
344 |
delete.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
345 |
delete.addHeader("Content-Type", "application/xml"); |
346 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
347 |
|
348 |
HttpBundle bundle = new HttpBundle();
|
349 |
bundle.setCurlRequest(delete); |
350 |
|
351 |
try {
|
352 |
resp = httpclient.execute(delete); |
353 |
bundle.setHttpResponse(resp); |
354 |
} catch (ClientProtocolException e) {
|
355 |
CloudServersException cse = new CloudServersException();
|
356 |
cse.setMessage(e.getLocalizedMessage()); |
357 |
throw cse;
|
358 |
} catch (IOException e) { |
359 |
CloudServersException cse = new CloudServersException();
|
360 |
cse.setMessage(e.getLocalizedMessage()); |
361 |
throw cse;
|
362 |
} catch (FactoryConfigurationError e) { |
363 |
CloudServersException cse = new CloudServersException();
|
364 |
cse.setMessage(e.getLocalizedMessage()); |
365 |
throw cse;
|
366 |
} |
367 |
return bundle;
|
368 |
} |
369 |
|
370 |
public HttpBundle rename(Server server, String name, Context context) throws CloudServersException{ |
371 |
HttpResponse resp = null;
|
372 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
373 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
374 |
|
375 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
376 |
put.addHeader("Content-Type", "application/xml"); |
377 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
378 |
|
379 |
StringEntity tmp = null;
|
380 |
try {
|
381 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" name=\"" + name + "\"/>"); |
382 |
} catch (UnsupportedEncodingException e) { |
383 |
CloudServersException cse = new CloudServersException();
|
384 |
cse.setMessage(e.getLocalizedMessage()); |
385 |
throw cse;
|
386 |
} |
387 |
put.setEntity(tmp); |
388 |
|
389 |
HttpBundle bundle = new HttpBundle();
|
390 |
bundle.setCurlRequest(put); |
391 |
|
392 |
try {
|
393 |
resp = httpclient.execute(put); |
394 |
bundle.setHttpResponse(resp); |
395 |
} catch (ClientProtocolException e) {
|
396 |
CloudServersException cse = new CloudServersException();
|
397 |
cse.setMessage(e.getLocalizedMessage()); |
398 |
throw cse;
|
399 |
} catch (IOException e) { |
400 |
CloudServersException cse = new CloudServersException();
|
401 |
cse.setMessage(e.getLocalizedMessage()); |
402 |
throw cse;
|
403 |
} catch (FactoryConfigurationError e) { |
404 |
CloudServersException cse = new CloudServersException();
|
405 |
cse.setMessage(e.getLocalizedMessage()); |
406 |
throw cse;
|
407 |
} |
408 |
return bundle;
|
409 |
} |
410 |
|
411 |
public HttpBundle rebuild(Server server, int imageId, Context context) throws CloudServersException { |
412 |
HttpResponse resp = null;
|
413 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
414 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
415 |
|
416 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
417 |
post.addHeader("Content-Type", "application/xml"); |
418 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
419 |
|
420 |
StringEntity tmp = null;
|
421 |
try {
|
422 |
tmp = new StringEntity("<rebuild xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" imageId=\"" + imageId + "\"/>"); |
423 |
} catch (UnsupportedEncodingException e) { |
424 |
CloudServersException cse = new CloudServersException();
|
425 |
cse.setMessage(e.getLocalizedMessage()); |
426 |
throw cse;
|
427 |
} |
428 |
post.setEntity(tmp); |
429 |
|
430 |
HttpBundle bundle = new HttpBundle();
|
431 |
bundle.setCurlRequest(post); |
432 |
|
433 |
try {
|
434 |
resp = httpclient.execute(post); |
435 |
bundle.setHttpResponse(resp); |
436 |
} catch (ClientProtocolException e) {
|
437 |
CloudServersException cse = new CloudServersException();
|
438 |
cse.setMessage(e.getLocalizedMessage()); |
439 |
throw cse;
|
440 |
} catch (IOException e) { |
441 |
CloudServersException cse = new CloudServersException();
|
442 |
cse.setMessage(e.getLocalizedMessage()); |
443 |
throw cse;
|
444 |
} catch (FactoryConfigurationError e) { |
445 |
CloudServersException cse = new CloudServersException();
|
446 |
cse.setMessage(e.getLocalizedMessage()); |
447 |
throw cse;
|
448 |
} |
449 |
return bundle;
|
450 |
} |
451 |
|
452 |
public HttpBundle backup(Server server, String weeklyValue, String dailyValue, boolean enabled, Context context) throws CloudServersException { |
453 |
HttpResponse resp = null;
|
454 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
455 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/backup_schedule.xml"); |
456 |
|
457 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
458 |
post.addHeader("Content-Type", "application/xml"); |
459 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
460 |
|
461 |
StringEntity tmp = null;
|
462 |
try {
|
463 |
tmp = new StringEntity("<backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
464 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
465 |
|
466 |
} catch (UnsupportedEncodingException e) { |
467 |
CloudServersException cse = new CloudServersException();
|
468 |
cse.setMessage(e.getLocalizedMessage()); |
469 |
throw cse;
|
470 |
} |
471 |
post.setEntity(tmp); |
472 |
|
473 |
HttpBundle bundle = new HttpBundle();
|
474 |
bundle.setCurlRequest(post); |
475 |
|
476 |
try {
|
477 |
resp = httpclient.execute(post); |
478 |
bundle.setHttpResponse(resp); |
479 |
} catch (ClientProtocolException e) {
|
480 |
CloudServersException cse = new CloudServersException();
|
481 |
cse.setMessage(e.getLocalizedMessage()); |
482 |
throw cse;
|
483 |
} catch (IOException e) { |
484 |
CloudServersException cse = new CloudServersException();
|
485 |
cse.setMessage(e.getLocalizedMessage()); |
486 |
throw cse;
|
487 |
} catch (FactoryConfigurationError e) { |
488 |
CloudServersException cse = new CloudServersException();
|
489 |
cse.setMessage(e.getLocalizedMessage()); |
490 |
throw cse;
|
491 |
} |
492 |
return bundle;
|
493 |
} |
494 |
|
495 |
public HttpBundle changePassword(Server server, String password, Context context) throws CloudServersException{ |
496 |
HttpResponse resp = null;
|
497 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
498 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
499 |
|
500 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
501 |
put.addHeader("Content-Type", "application/xml"); |
502 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
503 |
|
504 |
StringEntity tmp = null;
|
505 |
try {
|
506 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" adminPass=\"" + password + "\"/>"); |
507 |
} catch (UnsupportedEncodingException e) { |
508 |
CloudServersException cse = new CloudServersException();
|
509 |
cse.setMessage(e.getLocalizedMessage()); |
510 |
throw cse;
|
511 |
} |
512 |
put.setEntity(tmp); |
513 |
|
514 |
HttpBundle bundle = new HttpBundle();
|
515 |
bundle.setCurlRequest(put); |
516 |
|
517 |
try {
|
518 |
resp = httpclient.execute(put); |
519 |
bundle.setHttpResponse(resp); |
520 |
} catch (ClientProtocolException e) {
|
521 |
CloudServersException cse = new CloudServersException();
|
522 |
cse.setMessage(e.getLocalizedMessage()); |
523 |
throw cse;
|
524 |
} catch (IOException e) { |
525 |
CloudServersException cse = new CloudServersException();
|
526 |
cse.setMessage(e.getLocalizedMessage()); |
527 |
throw cse;
|
528 |
} catch (FactoryConfigurationError e) { |
529 |
CloudServersException cse = new CloudServersException();
|
530 |
cse.setMessage(e.getLocalizedMessage()); |
531 |
throw cse;
|
532 |
} |
533 |
return bundle;
|
534 |
} |
535 |
|
536 |
|
537 |
} |