23
23
import org .json .JSONException ;
24
24
import org .json .JSONObject ;
25
25
import org .json .JSONTokener ;
26
-
26
+ import org . apache . http . Header ;
27
27
import android .os .Message ;
28
28
29
29
/**
@@ -62,6 +62,18 @@ public void onSuccess(JSONObject response) {}
62
62
*/
63
63
public void onSuccess (JSONArray response ) {}
64
64
65
+ /**
66
+ * Fired when a request returns successfully and contains a json object
67
+ * at the base of the response string. Override to handle in your
68
+ * own code.
69
+ * @param statusCode the status code of the response
70
+ * @param headers the headers of the HTTP response
71
+ * @param response the parsed json object found in the server response (if any)
72
+ */
73
+ public void onSuccess (int statusCode , Header [] headers , JSONObject response ) {
74
+ onSuccess (statusCode , response );
75
+ }
76
+
65
77
/**
66
78
* Fired when a request returns successfully and contains a json object
67
79
* at the base of the response string. Override to handle in your
@@ -73,6 +85,17 @@ public void onSuccess(int statusCode, JSONObject response) {
73
85
onSuccess (response );
74
86
}
75
87
88
+ /**
89
+ * Fired when a request returns successfully and contains a json array
90
+ * at the base of the response string. Override to handle in your
91
+ * own code.
92
+ * @param statusCode the status code of the response
93
+ * @param headers the headers of the HTTP response
94
+ * @param response the parsed json array found in the server response (if any)
95
+ */
96
+ public void onSuccess (int statusCode , Header [] headers , JSONArray response ) {
97
+ onSuccess (statusCode , response );
98
+ }
76
99
77
100
/**
78
101
* Fired when a request returns successfully and contains a json array
@@ -81,7 +104,7 @@ public void onSuccess(int statusCode, JSONObject response) {
81
104
* @param statusCode the status code of the response
82
105
* @param response the parsed json array found in the server response (if any)
83
106
*/
84
- public void onSuccess (int statusCode , JSONArray response ) {
107
+ public void onSuccess (int statusCode , JSONArray response ) {
85
108
onSuccess (response );
86
109
}
87
110
@@ -94,16 +117,16 @@ public void onFailure(Throwable e, JSONArray errorResponse) {}
94
117
//
95
118
96
119
@ Override
97
- protected void sendSuccessMessage (int statusCode , String responseBody ) {
98
- if (statusCode != HttpStatus .SC_NO_CONTENT ){
99
- try {
100
- Object jsonResponse = parseResponse (responseBody );
101
- sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , new Object []{statusCode , jsonResponse }));
102
- } catch (JSONException e ) {
103
- sendFailureMessage (e , responseBody );
104
- }
105
- } else {
106
- sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , new Object []{statusCode , new JSONObject ()}));
120
+ protected void sendSuccessMessage (int statusCode , Header [] headers , String responseBody ) {
121
+ if (statusCode != HttpStatus .SC_NO_CONTENT ){
122
+ try {
123
+ Object jsonResponse = parseResponse (responseBody );
124
+ sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , new Object []{statusCode , headers , jsonResponse }));
125
+ } catch (JSONException e ) {
126
+ sendFailureMessage (e , responseBody );
127
+ }
128
+ } else {
129
+ sendMessage (obtainMessage (SUCCESS_JSON_MESSAGE , new Object []{statusCode , new JSONObject ()}));
107
130
}
108
131
}
109
132
@@ -117,18 +140,18 @@ protected void handleMessage(Message msg) {
117
140
switch (msg .what ){
118
141
case SUCCESS_JSON_MESSAGE :
119
142
Object [] response = (Object []) msg .obj ;
120
- handleSuccessJsonMessage (((Integer ) response [0 ]).intValue (), response [1 ]);
143
+ handleSuccessJsonMessage (((Integer ) response [0 ]).intValue (),( Header []) response [1 ] , response [ 2 ]);
121
144
break ;
122
145
default :
123
146
super .handleMessage (msg );
124
147
}
125
148
}
126
149
127
- protected void handleSuccessJsonMessage (int statusCode , Object jsonResponse ) {
150
+ protected void handleSuccessJsonMessage (int statusCode ,Header [] headers , Object jsonResponse ) {
128
151
if (jsonResponse instanceof JSONObject ) {
129
- onSuccess (statusCode , (JSONObject )jsonResponse );
152
+ onSuccess (statusCode , headers , (JSONObject )jsonResponse );
130
153
} else if (jsonResponse instanceof JSONArray ) {
131
- onSuccess (statusCode , (JSONArray )jsonResponse );
154
+ onSuccess (statusCode , headers , (JSONArray )jsonResponse );
132
155
} else {
133
156
onFailure (new JSONException ("Unexpected type " + jsonResponse .getClass ().getName ()), (JSONObject )null );
134
157
}
0 commit comments