2323import  org .json .JSONException ;
2424import  org .json .JSONObject ;
2525import  org .json .JSONTokener ;
26- 
26+ import   org . apache . http . Header ; 
2727import  android .os .Message ;
2828
2929/** 
@@ -62,6 +62,18 @@ public void onSuccess(JSONObject response) {}
6262     */ 
6363    public  void  onSuccess (JSONArray  response ) {}
6464
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+ 
6577    /** 
6678     * Fired when a request returns successfully and contains a json object 
6779     * at the base of the response string. Override to handle in your 
@@ -73,6 +85,17 @@ public void onSuccess(int statusCode, JSONObject response) {
7385        onSuccess (response );
7486    }
7587
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+     }
7699
77100    /** 
78101     * Fired when a request returns successfully and contains a json array 
@@ -81,7 +104,7 @@ public void onSuccess(int statusCode, JSONObject response) {
81104     * @param statusCode the status code of the response 
82105     * @param response the parsed json array found in the server response (if any) 
83106     */ 
84-     public  void  onSuccess (int  statusCode , JSONArray  response ) {
107+     public  void  onSuccess (int  statusCode ,   JSONArray  response ) {
85108        onSuccess (response );
86109    }
87110
@@ -94,16 +117,16 @@ public void onFailure(Throwable e, JSONArray errorResponse) {}
94117    // 
95118
96119    @ 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 ()}));
107130    	}
108131    }
109132
@@ -117,18 +140,18 @@ protected void handleMessage(Message msg) {
117140        switch (msg .what ){
118141            case  SUCCESS_JSON_MESSAGE :
119142                Object [] response  = (Object []) msg .obj ;
120-                 handleSuccessJsonMessage (((Integer ) response [0 ]).intValue (), response [1 ]);
143+                 handleSuccessJsonMessage (((Integer ) response [0 ]).intValue (),( Header [])  response [1 ] , response [ 2 ]);
121144                break ;
122145            default :
123146                super .handleMessage (msg );
124147        }
125148    }
126149
127-     protected  void  handleSuccessJsonMessage (int  statusCode , Object  jsonResponse ) {
150+     protected  void  handleSuccessJsonMessage (int  statusCode ,Header []  headers ,  Object  jsonResponse ) {
128151        if (jsonResponse  instanceof  JSONObject ) {
129-             onSuccess (statusCode , (JSONObject )jsonResponse );
152+             onSuccess (statusCode , headers ,  (JSONObject )jsonResponse );
130153        } else  if (jsonResponse  instanceof  JSONArray ) {
131-             onSuccess (statusCode , (JSONArray )jsonResponse );
154+             onSuccess (statusCode , headers ,  (JSONArray )jsonResponse );
132155        } else  {
133156            onFailure (new  JSONException ("Unexpected type "  + jsonResponse .getClass ().getName ()), (JSONObject )null );
134157        }
0 commit comments