Blog
Zend Amf Unable to parse null body data troubleshoot
8 years, 5 months ago Posted in: Blog 2

Those days had problems on getting to work zend_amf on a production server.

On my developement machine everything was working fine. Services were working, sending strings, arrays and custom VO's from and to flex was working like a charm.

Once uploaded via ftp to the production server I started testing and got into the famous "Unable to parse null body data..." error.

google(Unable to parse null body data zend_amf)


Magically after 5 hours reading blog posts and official zend's jira i got myserlf lost. I had typed VO's going our from the services but no way to send from flex a VO to a zend_amf Service.

The thing started working right when included directly the VO file in gateway.php
instanced in a variable and then echoed to the buffer file. see below Tweaked code

Once verified the class was instantiated and the trace was ok i switched back to the original gateway code and everything started working. see gateway.php

Now the question is.. is it a php5 common behaviour or a zend_amf problem?

Comments on this topic are welcome

Follows example code

Before tweak

PHP:
  1. <?php
  2.  
  3. require_once 'Zend/Amf/Server.php';
  4.  
  5. //include all the dao related files
  6. require_once('include_dao.php');
  7.  
  8. $server = new Zend_Amf_Server();
  9.  
  10. $server->setProduction(true);
  11.  
  12. $server->addDirectory(dirname(__FILE__) .'/dao/');
  13.  
  14. //                              as      php
  15. $server->setClassMap('User','User');
  16.  
  17. echo($server->handle());
  18.  
  19. ?>

Tweaked

PHP:
  1. <?php
  2.  
  3. require_once 'Zend/Amf/Server.php';
  4.  
  5. //include all the dao related files
  6. //require_once('include_dao.php');
  7.  
  8. // DO NOT IMPORT ALL THE CLASSES import directly the class
  9. require_once('dao/vo/User.php');
  10.  
  11. $server = new Zend_Amf_Server();
  12.  
  13. $server->setProduction(true);
  14.  
  15. $server->addDirectory(dirname(__FILE__) .'/dao/');
  16.  
  17. //                              as      php
  18. $server->setClassMap('User','User');
  19.  
  20. // do not start server
  21. //echo($server->handle());
  22.  
  23. // instance object
  24. $myuser = new User();
  25.  
  26. // trace to page buffer
  27. echo(print_r($myuser,true));
  28.  
  29. ?>

User.php in "dao/vo/"

PHP:
  1. <?php
  2.     /**
  3.      * Object representing record of table 'user'
  4.      *
  5.      * @author: MattiMatti
  6.      * @date: 2009-03-23 12:21  
  7.      */
  8.     class User{
  9.        
  10.         // ZEND AMF DO NOT REQUIRE $_explicitType
  11.        
  12.         function User(){
  13.        
  14.         }
  15.        
  16.    
  17.        
  18.         public $id;
  19.  
  20.         public $code;
  21.  
  22.         public $validated;
  23.  
  24.         public $validationDate;
  25.  
  26.         public $username;
  27.  
  28.         public $password;
  29.  
  30.         public $email;
  31.        
  32.     }
  33. ?>

include_dao.php in same folder as gateway.php

PHP:
  1. <?php
  2.     //include all DAO files
  3.     require_once('dao/DAOFactory.php');
  4.     require_once('dao/vo/User.php');
  5.     require_once('dao/UserController.php');
  6. ?>

2 Responses

  1. JaneRadriges says:

    Hi, gr8 post thanks for posting. Information is useful!

  2. LeraJenkins says:

    Bravo, very good idea

Image compression on this page is provided by WordPress Image Compressor