Tag Archives: joomla

PHP-SOAP -> NuSOAP decoding problems

I’ve been helping our Operations team resolve some issues integrating a Joomla front-end with the SugarCRM SOAP API. The main problem: the sugarcases Joomla component refused to return any data from Sugar. After spending some time debugging the interaction between the Joomla component’s PHP-SOAP client and Sugar’s NuSOAP server, I managed to trace the following two errors:

looks like we got no XML document

SoapFault Object *RECURSION*

by enabling the SoapClient trace ('trace' => 1) feature, I was also able to call __getLastResponse to print the HTTP response content that was being sent from Sugar. What I was seeing was a completely garbled text. I concluded this must have been some sort of encoding mismatch between the client and server, so my first step was to disable SOAP compression by removing the constructor option:

$this->sugarClient = new SoapClient(null, array(
		'location' => $this->server
		,'uri' => 'http://www.sugarcrm.com/sugarcrm'
		,'soap_version'   => SOAP_1_1
		,'trace' => 1
		,'exceptions' => 0
		//,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
	));

Immediately after doing that I was seeing valid content coming through in the response, and the Joomla component was correctly displaying data. Obviously we want to use gzip compression if Sugar and Joomla are going to be sharing large amounts of data, so I needed to get to the bottom of this. Fortunately a little more research, and I found a hint, way down in the comments (comment 45) on this nonplussed blog post.
Basically both Apache and NuSOAP were gzipping the response. NuSOAP was responding correctly to the accept-encoding header and encoding the response, but then apache was also gzipping the already gzipped content. So by the time PHP-SOAP got its hands on the response and decoded it, it still had a second layer of encoding to deal with, which it couldn’t.
To workaround this I modified nusoap.php and commented out the compression logic (30 lines in total) in the send_response() method, and I could then re-enable the compression in my SoapClient instance and everything worked as intended.

Share