Welcome Guest, Not a member yet? Register   Sign In
XML-RPC Datamapper problem
#1

[eluser]Unknown[/eluser]
Hey there,

I'm new to CI + Datamapper and XML-RPC so forgive me if I have made an newbie error. I have read through all the posts I could find on XML-RPC issues but couldn't find a solution, though I found similar issues in http://ellislab.com/forums/viewthread/78177/ and http://ellislab.com/forums/viewthread/63287/. I tried the solutions there but to no avail.

I am trying to setup a test with XML-RPC requests from a client class coming in to a server class which then uses Datamapper to get data from the database and return it. However, when I run it I get this error:

Code:
---DATA---
HTTP/1.1 200 OK
Date: Fri, 14 Aug 2009 03:32:52 GMT
Server: Apache/2.0.63 (CentOS)
X-Powered-By: PHP/5.1.6
Content-Length: 346
Connection: close
Content-Type: text/xml

                      
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>username</name>
<value>
<string>paul</string>
</value>
</member>
<member>
<name>emailAddress</name>
<value>
<string>[email protected]</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END DATA---


The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

I think I am having the same issue mentioned in the related posts (see above), where there is an extra line added for reasons unknown to the top of the xml data. The XML-RPC spec requires that the first line contains the &lt;?xml version="1.0" encoding="UTF-8"?&gt; info and this extra line at the top seems to be causing the error. If I comment out all references to the 'user' object and model then it works (lines 8, 18, 32, 33, 35 of the server class 'User_controller') - there is no extra line at the top of the xml data. However if I un-comment any one of them, then it doesn't work , with the exception being line 27 (I noticed though there is an extra line added to the bottom of the xml data):

Code:
$u = new User(); // this works!?! method

Here are the classes.

Server class
Code:
&lt;?php

class User_controller extends Controller {
    
    public function __construct()
    {
        parent::__construct();
        //$u = new User();                    // this doesn't work
        $this->load->library('xmlrpc');
        $this->load->library('xmlrpcs');
    }

    function index()
    {
//        $this->load->library('xmlrpc');
//        $this->load->library('xmlrpcs');
        
        //$this->load->model('User');        // this doesn't work
        
        $config['functions']['getUserData'] = array('function' => 'User_controller.getUserData');
        
        //$config['object'] = $this;
        
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
        
        $u = new User();                    // this works!?!
    }

    function getUserData($request)
    {
        //$this->load->model('User');          // this doesn't work
        //$u = new User();                    // this doesn't work
        $parameters = $request->output_parameters();            
        //$u->where('username', $parameters[0])->get();    
        
        /*      
        $response = array(
                            array(
                                    'username'  => $u->username,
                                    'emailAddress'  => $u->emailAddress),
                            'struct');              
        */
        $response = array(
                            array(
                                    'username'  => 'paul',
                                    'emailAddress'  => '[email protected]'),
                            'struct');              
        
        return $this->xmlrpc->send_response($response);
    }    
}
?&gt;

Client Class
Code:
&lt;?php

class Xmlrpc_client extends Controller {

    function index()
    {
        $this->load->helper('url');
        $server_url = site_url('user_controller');
        //$server_url = site_url('xmlrpc_server');
        //$server_url = '../models/user.php';
        
        //echo $server_url;
       // echo '<br />';

        $this->load->library('xmlrpc');
        $this->xmlrpc->set_debug(TRUE);

        $this->xmlrpc->server($server_url, 80);
        $this->xmlrpc->method('getUserData');

        $request = array('matt', 'string');
        $this->xmlrpc->request($request);

        if ( ! $this->xmlrpc->send_request())
        {
            echo $this->xmlrpc->display_error();
        }
        else
        {
            echo '<pre>';
            print_r($this->xmlrpc->display_response());
            echo '</pre>';
        }
    }
}
?&gt;

Where is this extra line coming from? Is it a bug or am I missing something obvious here?

Any help would be much appreciated.

PS. Using CI v.1.7.1, DataMapper v.1.6.0, PHP v.5.1.6, MySQL v.5.0.68

Cheers,
Matt
#2

[eluser]tomcode[/eluser]
Don't know neither XML-RPC nor Datamapper, but it looks to me like Your User library might have some whitespace outside the PHP tags.
#3

[eluser]Unknown[/eluser]
[quote author="tomcode" date="1250258545"]Don't know neither XML-RPC nor Datamapper, but it looks to me like Your User library might have some whitespace outside the PHP tags.[/quote]

Yes!!! Thanks tomcode, that was the issue. My 'user' model class had trailing white-space on the same line as the closing php tag.

Code:
&lt;?php
class User extends DataMapper {

    public function __construct()
    {
        parent::__construct();
    }
}
?&gt;   // the problem was the white-spaces here

Thanks again for your help tomcode.
Cheers,
Matt




Theme © iAndrew 2016 - Forum software by © MyBB