0

I am working on android/php project. What I am trying to do is create a library that uploads crash details to my server.

I have a test app, which purposely throws a NullPointerException. This calls my library which then gets various, such as device details and crash details.

The contents of these values should then be posted to my web server which then stores the data in my database.

There are no errors occurring with the library but there's a strange message in the apache log, even stranger its in the access log not the error log. I don't know if its something in the android project or the PHP pages aren't doing something I'm expecting them to.

Below is how I am posting the data from Android

CrashReporter.severity = severity;
        CrashReporter.exceptionObject = exceptionObject;

        String exceptionType = CrashReporter.exceptionObject.getClass().getName();
        Log.d("Exception Type", exceptionType);
        Log.d("Device Name", android.os.Build.MODEL);
        Log.d("Device Brand", android.os.Build.BRAND);
        Log.d("Android API Level", String.valueOf(android.os.Build.VERSION.SDK_INT));
        Log.d("Android Name", CommonTasks.convertApiLevelToAndroidName(android.os.Build.VERSION.SDK_INT));
        Log.d("Screen Resolution", CritiMon.appContext.getResources().getDisplayMetrics().widthPixels + " x " + CritiMon.appContext.getResources().getDisplayMetrics().heightPixels);
        Log.d("Exception", exceptionObject.toString());
        Log.d("Severity", severity.toString());

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try
                    {
                    String exceptionType = CrashReporter.exceptionObject.getClass().getName();
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost("http://192.168.1.74/API/ReceiveData.php");

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("platform", "Android"));
                    nameValuePairs.add(new BasicNameValuePair("exceptionType", exceptionType));
                    nameValuePairs.add(new BasicNameValuePair("deviceName", android.os.Build.MODEL));
                    nameValuePairs.add(new BasicNameValuePair("devicBrand", android.os.Build.BRAND));
                    nameValuePairs.add(new BasicNameValuePair("apiLevel", String.valueOf(android.os.Build.VERSION.SDK_INT)));
                    nameValuePairs.add(new BasicNameValuePair("androidName", CommonTasks.convertApiLevelToAndroidName(android.os.Build.VERSION.SDK_INT)));
                    nameValuePairs.add(new BasicNameValuePair("screenResolution", CritiMon.appContext.getResources().getDisplayMetrics().widthPixels + " x " + CritiMon.appContext.getResources().getDisplayMetrics().heightPixels));
                    nameValuePairs.add(new BasicNameValuePair("exception", CrashReporter.exceptionObject.toString()));
                    nameValuePairs.add(new BasicNameValuePair("severity", CrashReporter.severity.toString()));

                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    HttpResponse response = httpClient.execute(httpPost);
                    InputStream is = response.getEntity().getContent();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    ByteArrayBuffer baf = new ByteArrayBuffer(20);

                    int current = 0;
                    while ((current = bis.read()) != -1)
                    {
                        baf.append((byte)current);
                    }

                    Log.d("HTTP Response", new String(baf.toByteArray()));
                    }
                    catch (ClientProtocolException ex)
                    {
                        Log.e("ClientProtocolException", ex.toString());
                    }
                    catch (IOException ex)
                    {
                        Log.e("IOException", ex.toString());
                    }
                }
            }).start();

Below is the ReceiveData.php file

<?php

    include ("../config.php");
    include ("CommonTasks.php");

    $commonTasks = new CommonTasks();

    if (empty($_POST))
    {
        $commonTasks->setAlarm("Test", "POST WAS EMPTY", ALARM_WARNING, $_SERVER['REQUEST_URI']);
        exit();
    }
    switch ($_POST['platform'])
    {
        case "Android":
            include ("AndroidCrash.php");
                $androidCrash = new AndroidCrash($_POST);
                echo $androidCrash->submitToDatabase($_POST);
                break;
        default:
            $commonTasks->setAlarm("API Receive Data", "Unknown platform detected", ALARM_WARNING, $_SERVER['REQUEST_URI']);
            echo "Error 500 - Unsupported platform detected";
            break;
    }
?>

Below is the AndrioidCrash.php file

<?php
    include ("../config.php");
    include ("SettingsManager.php");
    include ("CommonWork.php");

    class AndroidCrash
    {
        var $type;
        var $deviceName;
        var $deviceBrand;
        var $apiLevel;
        var $androidName;
        var $screenResolution;
        var $exception;
        var $severity;

        function __construct($post)
        {
            /*$this->type = $type;
            $this->deviceName = $deviceName;
            $this->deviceBrand = $deviceBrand;
            $this->apiLevel = $apiLevel;
            $this->androidName = $androidName;
            $this->screenResolution = $screenResolution;
            $this->exception = $exception;
            $this->severity = $severity;*/

            $fh = fopen('log.txt', 'w');
            fwrite($fh, print_r($post, true));
            fclose($fh);

            $commonWork = new CommonTasks();
            $commonWork->setAlarm("Test", print_r($post, true), ALARM_WARNING, $_SERVER['REQUEST_URI']);
        }

        function submitToDatabase($post)
        {
            $fh = fopen('log.txt', 'w');
            fwrite($fh, print_r($post, true));
            fclose($fh);

            $commonWork = new CommonTasks();
            $commonWork->setAlarm("Test", print_r($post, true), ALARM_WARNING, $_SERVER['REQUEST_URI']);

            return "200 OK";
        }
    }
?>

There message within the apache file that I do not understand is.

192.168.1.76 - - [15/Jun/2013:16:20:37 +0100] "POST /API/ReceiveData.php HTTP/1.1" 200 - "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

So basically I have 2 questions:

  1. What does the Apache-HttpClient/UNAVAILABLE mean
  2. What would cause the above error. The commonTasks->setAlarm method is supposed to add the post data into an array
Boardy
  • 35,417
  • 104
  • 256
  • 447

1 Answers1

1
  1. "Apache-HttpClient/UNAVAILABLE (java 1.4)" is just the user-agent string that was sent by the request. See here (Android HTTP User Agent)

  2. It doesn't look like an error. Looks like you got a 200 OK response from your post to "/API/ReceiveData.php". This is why it's in your access log. This is exactly what a successful request looks like. See here (http://httpd.apache.org/docs/current/logs.html#combined)

What makes you think anything is erroring?

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • I think its not working because after android posts to ReceiveData.php if the selected post variable platform is ``Android`` it then includes AndroidCrash.php within the switch statement and sets an alarm that includes the post data. But there is nothing in the apache log for AndroidCrash.php only ReceiveData.php and there no alarms – Boardy Jun 15 '13 at 15:39
  • Well hopefully I've answered your 2 questions :) – Ken Wolf Jun 15 '13 at 16:05