Zend Framework

Zend_XmlRpc_Value_Base64 is saved to XML request in decoded form

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.3
  • Component/s: Zend_XmlRpc_Client
  • Labels:
    None

Description

When XML request is created, base64'parameters are not rendered correctly. Zend_XmlRpc_Value_Scalar::saveXML() retrieves object's value via method getValue(), which returns decoded (base64_decode) form of value.

Activity

Hide
Thomas Weidner added a comment -

Assigned to Matthew

Show
Thomas Weidner added a comment - Assigned to Matthew
Hide
Chris Martin added a comment -

I've run into this issue as well using the main trunk (rev 6613)...

/**
 * GetNames
 *
 * @return array
 */
function GetNames()
{
    $ret = array(
        array(
            'id'=>1, 
            'name'=>'Jack', 
            'created_dt'=>new Zend_XmlRpc_Value_DateTime(1191877812), 
            'encoded'=>new Zend_XmlRpc_Value_Base64('testing 1..2..3')
        )
    );
    return $ret;
}
$server->addFunction("GetNames");
$response = $server->handle();

...The raw xml response from the server when calling this function is:

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse><params><param><value><array><data><value><struct>
<member><name>id</name><value><int>1</int></value></member>
<member><name>name</name><value><string>Jack</string></value></member>
<member><name>created_dt</name><value><dateTime.iso8601>20071008T14:10:12</dateTime.iso8601></value></member>
<member><name>encoded</name><value><base64>testing 1..2..3</base64></value></member>
</struct></value></data></array></value></param></params></methodResponse>

...which shows that the server is correctly wrapping the data values for the datetime and base64, but the base64 value is not encoded. The datetime value is correct.

The Zend_XmlRpc_Client is handling the response differently which confused me a little:
(from $xmlrpcClient->getLastResponse())

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse><params><param><value><array><data><value><struct>
<member><name>id</name><value><int>1</int></value></member>
<member><name>name</name><value><string>Jack</string></value></member>
<member><name>created_dt</name><value><string>20071008T14:10:12</string></value></member>
<member><name>encoded</name><value><string>µ뭊x5</string></value></member>
</struct></value></data></array></value></param></params></methodResponse>

...which shows:

  • The datetime value is wrapped as a string.
  • The base65 value has been decoded, and is wrapped as a string (the server had encoded the value "improperly" ).

Is the desired behavior of Zend_XmlRpc_Client to support automatic conversion of these datatypes, or is it up to the user to convert?

Potential workaround is below, but is undesirable long term.

/**
 * GetNames
 *
 * @return array
 */
function GetNames()
{
    $ret = array(
        array(
            'id'=>1, 
            'name'=>'Jack', 
            'created_dt'=>new Zend_XmlRpc_Value_DateTime(1191877812),
            'encoded'=>base64_encode('testing 1..2..3')
        )
    );
    return $ret;
}

... and then on the client...

$retval = $client->call('GetNames');
for ($i=0; $i<count($retval); $i++) {
    $retval[$i]['created_dt'] = strtotime($retval[$i]['created_dt']); 
    $retval[$i]['encoded'] = base64_decode($retval[$i]['encoded']);
}
Show
Chris Martin added a comment - I've run into this issue as well using the main trunk (rev 6613)...
/**
 * GetNames
 *
 * @return array
 */
function GetNames()
{
    $ret = array(
        array(
            'id'=>1, 
            'name'=>'Jack', 
            'created_dt'=>new Zend_XmlRpc_Value_DateTime(1191877812), 
            'encoded'=>new Zend_XmlRpc_Value_Base64('testing 1..2..3')
        )
    );
    return $ret;
}
$server->addFunction("GetNames");
$response = $server->handle();
...The raw xml response from the server when calling this function is:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse><params><param><value><array><data><value><struct>
<member><name>id</name><value><int>1</int></value></member>
<member><name>name</name><value><string>Jack</string></value></member>
<member><name>created_dt</name><value><dateTime.iso8601>20071008T14:10:12</dateTime.iso8601></value></member>
<member><name>encoded</name><value><base64>testing 1..2..3</base64></value></member>
</struct></value></data></array></value></param></params></methodResponse>
...which shows that the server is correctly wrapping the data values for the datetime and base64, but the base64 value is not encoded. The datetime value is correct. The Zend_XmlRpc_Client is handling the response differently which confused me a little: (from $xmlrpcClient->getLastResponse())
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse><params><param><value><array><data><value><struct>
<member><name>id</name><value><int>1</int></value></member>
<member><name>name</name><value><string>Jack</string></value></member>
<member><name>created_dt</name><value><string>20071008T14:10:12</string></value></member>
<member><name>encoded</name><value><string>µ뭊x5</string></value></member>
</struct></value></data></array></value></param></params></methodResponse>
...which shows:
  • The datetime value is wrapped as a string.
  • The base65 value has been decoded, and is wrapped as a string (the server had encoded the value "improperly" ).
Is the desired behavior of Zend_XmlRpc_Client to support automatic conversion of these datatypes, or is it up to the user to convert? Potential workaround is below, but is undesirable long term.
/**
 * GetNames
 *
 * @return array
 */
function GetNames()
{
    $ret = array(
        array(
            'id'=>1, 
            'name'=>'Jack', 
            'created_dt'=>new Zend_XmlRpc_Value_DateTime(1191877812),
            'encoded'=>base64_encode('testing 1..2..3')
        )
    );
    return $ret;
}
... and then on the client...
$retval = $client->call('GetNames');
for ($i=0; $i<count($retval); $i++) {
    $retval[$i]['created_dt'] = strtotime($retval[$i]['created_dt']); 
    $retval[$i]['encoded'] = base64_decode($retval[$i]['encoded']);
}
Hide
Chris Martin added a comment -

A test xmlrpc server and client that reproduces the issue(s).

Show
Chris Martin added a comment - A test xmlrpc server and client that reproduces the issue(s).
Hide
Lode Blomme added a comment -

I ran into the same problem with the release version 1.0.2.
I sent an email to the mailing list about it (http://www.nabble.com/Zend_XmlRpc-and-base64-tf4609278s16154.html) because I hadn't seen this bug report yet.

In short, what I did to fix it :
In : XmlRpc/Value/Scalar.php
Change : line 50
From :

 $type->appendChild($dom->createTextNode($this->getValue()));

Into :

 $type->appendChild($dom->createTextNode($this->_value));

Reason :
The method call getValue() refers back to the Zend_XmlRpc_Value_Base64 class.
That function returns the base64 decoded value of the object, which you don't want in this case.

Show
Lode Blomme added a comment - I ran into the same problem with the release version 1.0.2. I sent an email to the mailing list about it (http://www.nabble.com/Zend_XmlRpc-and-base64-tf4609278s16154.html) because I hadn't seen this bug report yet. In short, what I did to fix it : In : XmlRpc/Value/Scalar.php Change : line 50 From :
 $type->appendChild($dom->createTextNode($this->getValue()));
Into :
 $type->appendChild($dom->createTextNode($this->_value));
Reason : The method call getValue() refers back to the Zend_XmlRpc_Value_Base64 class. That function returns the base64 decoded value of the object, which you don't want in this case.
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for 1.0.3

Show
Matthew Weier O'Phinney added a comment - Scheduling for 1.0.3
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and release branch as of r6882.

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and release branch as of r6882.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1h
Original Estimate - 1 hour
Remaining:
1h
Remaining Estimate - 1 hour
Logged:
Not Specified
Time Spent - Not Specified