HttpAppender

Developers
tvolk
2010-05-10
2013-04-26
  • tvolk
    tvolk
    2010-05-10

    Hi all,

    I've noticed some issues in HttpAppender class:

    1.  logOpen property is not updated properly. I suppose it's a bug, because logOpen is set to true in close() and open() is empty. I've changed to:

       public void open() throws IOException {
          logOpen = true;
       }

      public void close() throws IOException {
          IOUtil.closeSilent(connection);
          logOpen = false;
       }

    2. Some HttpConnection properties are missing, without them the my "server" does't work. I've added them to connect() method.

       protected OutputStream connect() throws IOException {
          connection = (HttpConnection) Connector.open(postURL);
          connection.setRequestMethod(HttpConnection.POST);
          connection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
             connection.setRequestProperty("Accept_Language","en-US");
          connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          return connection.openOutputStream();
       }

    3. I don't know if it is only a PHP issue, but I need to name POST parameters. This can be done simply modifying doLog() method writing ** instead of .
        printStream.print(logString);
        printStream.print("log="+logString);

    4. I don't know if any of the provided HTTP servers works. They seemed a little confusing to me, so I've developed my own really simple php script. I post it here in case somebody wants it (or maybe improve it ;-)):

       <?php
          $filepath = 'logs/test.log';
          $fh = fopen($filepath, 'a') or die('cannot open file');
          fwrite($fh,$_POST."\n");
          fclose($fh);
       ?>

    5. I've noticed that http appender cannot be fully configured via properties file. Am I right? Is it possible to configure postURL property with microlog.properties file? If it is not, would it be possible to add it?

    I have tested the proposed solution both in an emulator and in a real mobile phone.

    Best regards,

    Aitor Gómez Goiri**

     
  • Johan Karlsson
    Johan Karlsson
    2010-05-15

    Hi,

    nice that you have tried the HttpAppender class. This is the newest addition to the Appender classes. Therefore not tested so much. Here are my comments:

    1. This is naturally a bug. It has slipped in when I did a re-factoring. Sorry about that. It is now fixed on the trunk in Subversion. This fix will be part of the upcoming 3.0 release.

    2. I have change the code according to your suggestion. This is also fixed on the trunk and thus will be available in V3.0

    3. I need to test this further before doing any changes. The logString is not meant to be used as a parameter as you suggest. This is actually meant to be part of the body.

    4. I have tried with the supplied HTTP server. This is very simple and should be viewed as an example. For more advanced usage, you should create your own server. For example a PHP solution as you did.

    5. Nice that you did your own PHP solution. I have not used PHP anytime.

    I would like to include the PHP solution as part of Microlog V3.0.  It is nice to have several server solution, so that people could choose to use their own.


    Would you be interested in contributing your solution as part of the official Microlog distribution?

    Warm regards
    Johan

     
  • tvolk
    tvolk
    2010-06-08

    Hi again,

    Here you have the code needed to obtain the raw POST data from PHP without modifying the HttpAppender as I suggested in point 3:

    <?php
    //This file must exist before calling to the php file for the first time
    $filepath = 'logs/test.log';
    $fh = fopen($filepath, 'a') or die('cannot open file');
    fwrite($fh,file_get_contents('php://input')."\n");
    fclose($fh);
    ?>
    

    Regards,

    Aitor Gómez Goiri

     
  • Johan Karlsson
    Johan Karlsson
    2010-06-09

    Thank you very much, I will include this in the next Microlog release.

    Regards
    Johan