Issues

ZF-5704: SoapServer->fault() will not correct encode the exception-message

Issue Type: Improvement Created: 2009-02-06T00:30:44.000+0000 Last Updated: 2009-09-09T11:11:34.000+0000 Status: Resolved Fix version(s): Reporter: Sven (sunnysven) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Soap_Server

Related issues: Attachments:

Description

Setting up an SoapServer with another encoding as UTF-8 - for example ISO-8859-1 - SoapServer->fault() will not correct encode the message. By throwing a SoapFault with an message, the encoding will be done correctly, but SoapServer->fault() does not.

To suppress this php error (I reported that bug to php.net), I run an internal encoding. mb_convert_encoding($string, 'UTF-8', $this->getEncoding());

Reproduce code:

All code listed here is part of a complex class hierarchy.


SERVER-CODE


<pre class="highlight">
$server = new Zend_Soap_Server('<a href="http://xxx.de/?wsdl">http://xxx.de/?wsdl</a>', array('encoding' => 'ISO-8859-1'));
$server->setClass('SoapFaultTest');
$server->registerFaultException(array('Exception'));
$server->handle();

CLIENT-CODE

<pre class="highlight">
try {
    $client = new SoapClient('<a href="http://xxx.de/?wsdl">http://xxx.de/?wsdl</a>', array('encoding' => 'ISO-8859-1'));
    echo $client->test();
}
catch (SoapFault $fault) {
    echo 'error: ' . $fault->getMessage();
}

SERVICE-CLASS SoapFaultTest

<pre class="highlight">
class SoapFaultTest
{
    public function test() {
        throw new Exception('Exception with some special chars: Äßö');
    }
}

IMPROVEMENT FOR Zend_Soap_Server on line 941 (SVN)

<pre class="highlight">
return new SoapFault($code, $this->_convertEncoding($message));

/**
 * Converts non UTF-8 characters to UTF-8 charachters.
 * That is essential, otherwise PHPs Soap Extension will throw a SoapFault
 * SOAP-ERROR: Encoding: string '...' is not a valid utf-8 string
 * 
 * @param string String to encode
 * @return string correct Encoded String
 */
protected function _convertEncoding($string) {
    return 0 === strlen($this->getEncoding() || 'utf-8' === strtolower($this->getEncoding())) ? $string : mb_convert_encoding($string, 'UTF-8', $this->getEncoding());
}

So by throwing exceptions the exception-message will be converted correctly and the php bug can be circumvented.

Comments

Posted by Benjamin Eberlei (beberlei) on 2009-02-06T01:43:54.000+0000

thanks for the report, i'll look into it.

the problem, why i can't use your solution is the mbstring extension, which is not allowed in ZF components without a fallback. But iconv should be doing roughly good too :-)

Posted by Benjamin Eberlei (beberlei) on 2009-02-06T06:25:02.000+0000

I do wait for this bug to be confirmed on bugs.php.net (link: http://bugs.php.net/bug.php?id=47273), then i will implement a workaround.

Posted by Benjamin Eberlei (beberlei) on 2009-09-09T11:11:34.000+0000

The underlying PHP bug has been fixed, so this is marked as non-issue.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts