0

i have a problem with a part of my application, in one case i use http request on a json stream to get some data, and it work really good. but in another case, i have to use the location of the user to get the data. and after using the location provider, http request didn't work correctly. this problem appear only on one of the two device i have to test my application. on the first one, a smart phone with android 2.3.6, i have no problem. but that is on the seconde device, where the problem appear: a galaxy tab with android 4.0.4 (i have do a recent update of it, it was 3.0.1 before, problem was the same). and my application is compiled with the sdk 10 (android 2.3.3)

i try to catch the exception that is throw when the bug appear, but the message of the exception is null and i cant see what is the problem. does anibody have yet encounter this sort of bug ?

here is the source code from the activity, the runnable doRechercheGeoloc is launched from a click on a button :

private Runnable doRechercheGeoloc = new Runnable(){

    public void run() {
        // TODO Auto-generated method stub
        getProvider = true;

        LocationListener locationListener = new LocationListener(){
            public void onLocationChanged(Location newLocation) {
                // TODO Auto-generated method stub
                Log.i("*", "GPS : location changed");
                location = newLocation;
            }

            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub
                Log.i("*", "GPS : provider disabled");
            }

            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub
                Log.i("*", "GPS : provider enable");
            }

            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
                // TODO Auto-generated method stub
                Log.i("*", "GPS : status changed");
            }
        };

        lm = (LocationManager) getSystemService( AnnuaireActivity.LOCATION_SERVICE );
        Log.i("*", "le GPS est activé");
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
        location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        lm.removeUpdates(locationListener);
        lm = null;
        getProvider = true;
        lm = null;

        handler.postAtFrontOfQueue(doRecherchePourGeoloc);

    }

};

and the code of my json parser where i do the http connection :

public class JsonParser {

...

private String getJson(String url) throws Exception{

    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet( url );

    try{

                    //this is this instruction that provoque the error
        HttpResponse response = client.execute( get );
        StatusLine statusline = response.getStatusLine();
        int statuscode = statusline.getStatusCode();

        if (statuscode == 200){
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader( new InputStreamReader(content) );
            String line;
            while((line = reader.readLine()) != null){
                builder.append(line);
            }
        }else{
            Log.e("*", JsonParser.class.toString() + " : Failed to download file");
            throw new Exception(JsonParser.class.toString() + " : Failed to download file");
        }

    }catch( ClientProtocolException e ){
        Log.e("*", "JsonParser.getJson() : ClientProtocolException : " + e.getMessage());
        throw e;//
    }catch( IOException ioe ){
        Log.e("*", "JsonParser.getJson() : IOException : " + ioe.getMessage());
        throw ioe;//
    }catch( Exception e ){
        Log.e("*", "JsonParser.getJson() : Exception : " + e.getMessage());//the erreur is throwing from here and the message is null
        throw e;
    }

    return builder.toString();
}

...

}

thx.

seb
  • 9
  • 2

1 Answers1

-1

logging

What http package/jar are you using? Figure out how to turn on logging for WIRE and for HEADERS .

The package i use, i have to recompile/ use a separate http jar to get the logging at run time.

With the full logging turned on, you should have enough data to find your issue

see sample WIRE and HEADERS from adb logcat:

D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(18636): Attempt 1 to execute request
D/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(18636): Sending request: POST /1/files/audio HTTP/1.1
D/ch.boye.httpclientandroidlib.wire(18636): >> "POST /1/files/audio HTTP/1.1[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "X-Parse-Application-Id: 3KxPBTPSTe8f0iexGanSagCztLp6wSPzJkyMLAbR[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "X-Parse-REST-API-Key: kVl5Z0CXmBSCoQRmE8XSLIDFuLGHMCIkLXXjkuI9[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Type: audio/*[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Length: 12074[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Host: api.parse.com[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Connection: Keep-Alive[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]"
D/ch.boye.httpclientandroidlib.headers(18636): >> POST /1/files/audio HTTP/1.1
D/ch.boye.httpclientandroidlib.headers(18636): >> X-Parse-Application-Id: 3KxPBTPSTe8f0iexGanSagCztLp6wSPzJkyMLAbR
D/ch.boye.httpclientandroidlib.headers(18636): >> X-Parse-REST-API-Key: kVl5Z0CXmBSCoQRmE8XSLIDFuLGHMCIkLXXjkuI9
D/ch.boye.httpclientandroidlib.headers(18636): >> Content-Type: audio/*
D/ch.boye.httpclientandroidlib.headers(18636): >> Content-Length: 12074
D/ch.boye.httpclientandroidlib.headers(18636): >> Host: api.parse.com
D/ch.boye.httpclientandroidlib.headers(18636): >> Connection: Keep-Alive
D/ch.boye.httpclientandroidlib.wire(18636): >> "--"
D/ch.boye.httpclientandroidlib.wire(18636): >> "cVxX6b-jxQnxFCczaKHLNZ_Hq8HI9AEW219GW3w"
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Disposition"
D/ch.boye.httpclientandroidlib.wire(18636): >> ": "
D/ch.boye.httpclientandroidlib.wire(18636): >> "form-data; name="bin"; filename="myfile.3gp""
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "Content-Type"
D/ch.boye.httpclientandroidlib.wire(18636): >> ": "
D/ch.boye.httpclientandroidlib.wire(18636): >> "application/octet-stream"
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]"
D/ch.boye.httpclientandroidlib.wire(18636): >> "[\r][\n]"
D/dalvikvm(18636): GC_CONCURRENT freed 387K, 5% free 11211K/11719K, paused 12ms+3ms, total 38ms
D/dalvikvm(18636): WAIT_FOR_CONCURRENT_GC blocked 12ms
D/ch.boye.httpclientandroidlib.wire(18636): >> "[0x0][0x0][0x0][0x18]ftyp3gp4[0x0][0x0][0x0][0x0]isom3gp4[0x0][0x0][0x2][0xe7]moov[0
Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • i am using "org.apache.http" – seb Nov 07 '12 at 15:47
  • where did i put this line in my code : java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.FINEST); – seb Nov 07 '12 at 16:03
  • did i use the adb shell before launching the application – seb Nov 07 '12 at 16:04
  • that's ok, the logging system is working, i can see th "hola" test like in the subject you link. but no other log appear during the exception throws... – seb Nov 07 '12 at 16:14
  • revised answer. If you have a full trace from logcat of what the bi-directional headers and WIRE contents are, that should help you find your bug. Without the .wire and the .headers entries from a full trace on HTTP activity, its much harder to locate errors. You have to know as a developer , how to turn ON/OFF this debug feature when developing for android. – Robert Rowntree Nov 07 '12 at 19:11
  • i think the "hola" test is always working even if the debug feature is not enable... so i tried many thing to enable it, and i didn't succed yet. may be i need to recompile the package in externale lib like you have to do, but i dont have any source of the sdk i use (sdk 10)... do you know anything that could help me to do that ? – seb Nov 08 '12 at 10:06
  • i have found the source code of the android sdk 10, i do the third party lib of the org.apache.http package. it apears that the headers and wire are correctly logged now, but they didn't appear anymore in the case of the bug, i think no http request is done before the bug so no header, no wire to log. and when i do a test on a request that work, i can see only headers and wire even if i have enable log on the entire package org.apache.http – seb Nov 09 '12 at 10:16