On Magento 1.14.2.0.
I am connecting to the SOAP API via a URL like http://example.com/api/soap?wsdl=1
However, when I try and access the API it fatals filling my apache error log fills with
[Wed Jul 22 14:05:55 2015] FastCGI: server "/tmp/php-fpm5.5" stderr: PHP message: PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://custom-admin-url.example.com/index.php/api/soap/index/?SID=a_sid&wsdl=1' : Extra content at the end of the document
[Wed Jul 22 14:05:55 2015] FastCGI: server "/tmp/php-fpm5.5" stderr: in /var/www/vhosts/development/example/lib/Zend/Soap/Server.php on line 814
The interesting thing to note is that we are no longer trying to access the API via http://example.com/api/soap?wsdl=1
, but by https://custom-admin-url.example.com/index.php/api/soap/index/?SID=a_sid&wsdl=1
instead.
This admin url is correct, and is the one stored in the core_config_data
table under the path admin/url/custom
.
There is functionality to prevent the admin panel being accessed by anyone not coming from a certain IP address. The "Extra content at the end of the document
" in the error is actually the html home page we view after being redirected.
How can I best solve this redirect issue?
Best Answer
It was not an option to remove the IP blocker on the admin panel, so a code change to force Magento to internally use a valid URL was the only solution I can see.
Mage_Api_Model_Server_Adapter_Soap::_instantiateServer
is responsible for initialising the soap server for incoming requests,Here's the relevant snippet of
_instantiateServer
Here's the important part of
getWsdlUrl
Because this is operating within the admin scope, the url retrieved by
Mage_Core_Model_Url
iscustom-admin-url.example.com
. Which is causing the problem.To "solve" this I created a new module, extended the soap adapter and forced the
getWsdlUrl
function to operate within the default website scope, which is NOTMage_Core_Model_App:ADMIN_STORE_ID
.This correctly retrieves a web accessible url.
etc/api.xml
New adapter model