|
8 | 8 | import net.servicestack.client.AsyncServiceClient;
|
9 | 9 | import net.servicestack.client.IReturn;
|
10 | 10 | import net.servicestack.client.JsonServiceClient;
|
| 11 | +import net.servicestack.client.Utils; |
11 | 12 |
|
12 | 13 | import java.lang.reflect.Type;
|
13 | 14 | import java.net.HttpURLConnection;
|
@@ -111,24 +112,24 @@ protected void onPostExecute(T response) {
|
111 | 112 | }, path);
|
112 | 113 | }
|
113 | 114 |
|
114 |
| - public void getAsync(String path, final AsyncResult<HttpURLConnection> asyncResult) { |
| 115 | + public void getAsync(String path, final AsyncResult<byte[]> asyncResult) { |
115 | 116 | final AndroidServiceClient client = this;
|
116 |
| - execTask(new AsyncTask<String, Void, HttpURLConnection>() { |
| 117 | + execTask(new AsyncTask<String, Void, byte[]>() { |
117 | 118 | @Override
|
118 |
| - protected HttpURLConnection doInBackground(String... params) { |
| 119 | + protected byte[] doInBackground(String... params) { |
119 | 120 | try {
|
120 |
| - return client.get(params[0]); |
| 121 | + HttpURLConnection httpRes = client.get(params[0]); |
| 122 | + return Utils.readBytesToEnd(httpRes); |
121 | 123 | } catch (Exception e) {
|
122 | 124 | asyncResult.setError(e);
|
123 | 125 | return null;
|
124 | 126 | }
|
125 | 127 | }
|
126 | 128 |
|
127 | 129 | @Override
|
128 |
| - protected void onPostExecute(HttpURLConnection response) { |
129 |
| - asyncResult.completeResult(response); |
| 130 | + protected void onPostExecute(byte[] bytes) { |
| 131 | + asyncResult.completeResult(bytes); |
130 | 132 | }
|
131 |
| - |
132 | 133 | }, path);
|
133 | 134 | }
|
134 | 135 |
|
@@ -245,22 +246,23 @@ protected void onPostExecute(T response) {
|
245 | 246 | }
|
246 | 247 |
|
247 | 248 | @Override
|
248 |
| - public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult) { |
| 249 | + public void postAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult) { |
249 | 250 | final AndroidServiceClient client = this;
|
250 |
| - execTask(new AsyncTask<String, Void, HttpURLConnection>() { |
| 251 | + execTask(new AsyncTask<String, Void, byte[]>() { |
251 | 252 | @Override
|
252 |
| - protected HttpURLConnection doInBackground(String... params) { |
| 253 | + protected byte[] doInBackground(String... params) { |
253 | 254 | try {
|
254 |
| - return client.post(params[0], requestBody, contentType); |
| 255 | + HttpURLConnection httpRes = client.post(params[0], requestBody, contentType); |
| 256 | + return Utils.readBytesToEnd(httpRes); |
255 | 257 | } catch (Exception e) {
|
256 | 258 | asyncResult.setError(e);
|
257 | 259 | return null;
|
258 | 260 | }
|
259 | 261 | }
|
260 | 262 |
|
261 | 263 | @Override
|
262 |
| - protected void onPostExecute(HttpURLConnection response) { |
263 |
| - asyncResult.completeResult(response); |
| 264 | + protected void onPostExecute(byte[] bytes) { |
| 265 | + asyncResult.completeResult(bytes); |
264 | 266 | }
|
265 | 267 |
|
266 | 268 | }, path);
|
@@ -379,22 +381,23 @@ protected void onPostExecute(T response) {
|
379 | 381 | }
|
380 | 382 |
|
381 | 383 | @Override
|
382 |
| - public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<HttpURLConnection> asyncResult) { |
| 384 | + public void putAsync(String path, final byte[] requestBody, final String contentType, final AsyncResult<byte[]> asyncResult) { |
383 | 385 | final AndroidServiceClient client = this;
|
384 |
| - execTask(new AsyncTask<String, Void, HttpURLConnection>() { |
| 386 | + execTask(new AsyncTask<String, Void, byte[]>() { |
385 | 387 | @Override
|
386 |
| - protected HttpURLConnection doInBackground(String... params) { |
| 388 | + protected byte[] doInBackground(String... params) { |
387 | 389 | try {
|
388 |
| - return client.put(params[0], requestBody, contentType); |
| 390 | + HttpURLConnection httpRes = client.put(params[0], requestBody, contentType); |
| 391 | + return Utils.readBytesToEnd(httpRes); |
389 | 392 | } catch (Exception e) {
|
390 | 393 | asyncResult.setError(e);
|
391 | 394 | return null;
|
392 | 395 | }
|
393 | 396 | }
|
394 | 397 |
|
395 | 398 | @Override
|
396 |
| - protected void onPostExecute(HttpURLConnection response) { |
397 |
| - asyncResult.completeResult(response); |
| 399 | + protected void onPostExecute(byte[] bytes) { |
| 400 | + asyncResult.completeResult(bytes); |
398 | 401 | }
|
399 | 402 |
|
400 | 403 | }, path);
|
@@ -487,22 +490,23 @@ protected void onPostExecute(T response) {
|
487 | 490 | }, path);
|
488 | 491 | }
|
489 | 492 |
|
490 |
| - public void deleteAsync(String path, final AsyncResult<HttpURLConnection> asyncResult) { |
| 493 | + public void deleteAsync(String path, final AsyncResult<byte[]> asyncResult) { |
491 | 494 | final AndroidServiceClient client = this;
|
492 |
| - execTask(new AsyncTask<String, Void, HttpURLConnection>() { |
| 495 | + execTask(new AsyncTask<String, Void, byte[]>() { |
493 | 496 | @Override
|
494 |
| - protected HttpURLConnection doInBackground(String... params) { |
| 497 | + protected byte[] doInBackground(String... params) { |
495 | 498 | try {
|
496 |
| - return client.delete(params[0]); |
| 499 | + HttpURLConnection httpRes = client.delete(params[0]); |
| 500 | + return Utils.readBytesToEnd(httpRes); |
497 | 501 | } catch (Exception e) {
|
498 | 502 | asyncResult.setError(e);
|
499 | 503 | return null;
|
500 | 504 | }
|
501 | 505 | }
|
502 | 506 |
|
503 | 507 | @Override
|
504 |
| - protected void onPostExecute(HttpURLConnection response) { |
505 |
| - asyncResult.completeResult(response); |
| 508 | + protected void onPostExecute(byte[] bytes) { |
| 509 | + asyncResult.completeResult(bytes); |
506 | 510 | }
|
507 | 511 |
|
508 | 512 | }, path);
|
|
0 commit comments