]> iEval git - fonbot.git/commitdiff
Handle HTTP 401 and beautify HTTP messages
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Jul 2013 07:18:26 +0000 (10:18 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 27 Jul 2013 07:18:26 +0000 (10:18 +0300)
src/ro/ieval/fonbot/HttpCallExecutableRunnable.java
src/ro/ieval/fonbot/PollResultCallback.java

index e66a7f8090030360e08dcafcad62c4b659a44404..43e8b3fabb6f479a170a825c3323ea524a027b3b 100644 (file)
@@ -160,12 +160,16 @@ public final class HttpCallExecutableRunnable extends ExecutableRunnable{
                                stream.close();
                        }
                        Log.d(getClass().getName(),"HTTP Response: "+conn.getResponseCode()+" "+conn.getResponseMessage());
-                       final String message=conn.getResponseMessage();
+                       String message=conn.getResponseMessage();
                        if(message==null && callback != null)
                                callback.onError(toNonNull(context.getString(no_response_returned_from_server)));
-                       else if(message != null && callback != null)
-                               callback.onResult(conn.getResponseCode(), message,
-                                               toNonNull(conn.getInputStream()));
+                       else if(message != null && callback != null){
+                               if(message.charAt(message.length()-1) == ')')//message is (something)
+                                       message=message.substring(1, message.length()-1);
+                               else
+                                       message=message.substring(message.indexOf(')')+2);
+                               callback.onResult(conn.getResponseCode(), message, conn.getResponseCode() == 200 ? conn.getInputStream() : null);
+                       }
                        conn.disconnect();
                } catch (Exception e) {
                        e.printStackTrace();
index 6be7479a0031a0441886dc35fdd8a0a1d15be156..d3c84cebc1a2dde5eaacbbabba9b7801bfe0a6ed 100644 (file)
@@ -3,6 +3,7 @@ package ro.ieval.fonbot;
 import static ro.ieval.fonbot.Utils.toNonNull;
 
 import java.io.InputStream;
+import org.eclipse.jdt.annotation.Nullable;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -53,8 +54,8 @@ final class PollResultCallback implements ResultCallback {
        }
 
        @Override
-       public void onResult(final int responseCode, final String responseMessage, final InputStream inputStream) {
-               if(responseCode!=200)
+       public void onResult(final int responseCode, final String responseMessage, final @Nullable InputStream inputStream) {
+               if(responseCode!=200 || inputStream==null)
                        return;
 
                final Handler handler=new Handler(Looper.getMainLooper());
This page took 0.029519 seconds and 4 git commands to generate.