Magento-在Lion下使用MAMP堆栈时SOAP API响应不完整 [英] Magento - SOAP API response incomplete when using a MAMP stack under Lion

查看:32
本文介绍了Magento-在Lion下使用MAMP堆栈时SOAP API响应不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用soapUI测试了Magento的SOAP API.我成功登录并获得了登录哈希. 然后,我尝试检索产品列表,但效果很好.

I tested Magento's SOAP API using soapUI. I successfully logged in and got a login hash. Then I tried to retrieve a list of products and this worked fine.

这是在使用最新版本的Apache,mySQL和PHP的Linux服务器上.

This was on a Linux server using the latest version of Apache, mySQL and PHP.

然后,我创建了Magento和数据库的备份.我想使用MAMP堆栈在Lion服务器上创建测试环境. Magento备份似乎可以正常工作,但是SOAP API不能正常工作.

I then created a backup of Magento and the database. I wanted to create a test environment on a Lion server using a MAMP stack. The Magento backup seems to work fine, but the SOAP API doesn't.

我再次使用soapUI来获取登录哈希值,并尝试检索所有产品.但是现在,响应似乎是不完整的:

Again I used soapUI to get a login hash and tried to retrieve all products. But now the response seems to be incomplete:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:catalogProductListResponseParam>
<result>
<complexObjectArray>
<product_id>7167</product_id>
<sku>000140</sku>
... etc ...
<complexObjectArray>34</complexObjectArray>
</category_ids>
<website_ids>
<complexObjectArray>1</complexObjectArray>
</website_ids>
</complexObjectArray>
<complexObjectArray>
<product

为什么在Lion/MAMP下响应不完整?

Why is the reponse incomplete under Lion/MAMP?

推荐答案

我曾经遇到一次不完整的SOAP XML响应问题.

I had a problem with incomplete SOAP XML responses once.

设置是这样的:

  • Linux服务器
  • Magento CE 1.5.1.0
  • 启用WS-I遵从性的SOAP v2的使用
  • 致电sales_order.info

即使您使用不同的Magento版本和不同的SOAP调用,您也可能遭受与我相似的错误.问题是 HTTP Content-Length标头对于> 8000字节的响应计算不正确.

Even if you use a different Magento version and a different SOAP call, you may suffer from a similar bug as I did. The problem was that the HTTP Content-Length header was calculated incorrectly for responses > 8000 bytes.

如何验证您是否受此错误影响:

  1. 执行一个传递简短响应的调用(例如,"catalog_category.info"仅具有一个商店视图且只有很少的属性).如果XML完整,请检查响应的长度是否小于< = 8000个字节.
  2. 将文件app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php复制到您的app/code/local文件夹中,然后编辑run()方法.如果在SOAP URL中使用"wsdl"参数,请编辑"if"结构的第一部分,否则请编辑"else"部分.

由于第二种方法是更准确的方法,因此我将继续.

As the second way is the more accurate way to do it, I'll go with this.

  1. 打开文件并搜索-> setBody()方法调用.如您所见,正在发生一些搜索/替换魔术.
  2. 将搜索/替换操作的结果写入变量,并将其记录下来以进行进一步检查.代码可能看起来像这样:

  1. Open the file and search for the ->setBody() method call. As you can see, there is some search/replace magic going on.
  2. Write the result of the search/replace operations into a variable and log it for further examination. The code may look like this:

public function run()
{
    $apiConfigCharset = Mage::getStoreConfig("api/config/charset");

    if ($this->getController()->getRequest()->getParam('wsdl') !== null) {
        /* don't modify the first part ... */
    } else {
        try {
            $this->_instantiateServer();

            $content = preg_replace(
                    '/(\>\<)/i',
                    ">\n<",
                    str_replace(
                            '<soap:operation soapAction=""></soap:operation>',
                            "<soap:operation soapAction=\"\" />\n",
                            str_replace(
                                    '<soap:body use="literal"></soap:body>',
                                    "<soap:body use=\"literal\" />\n",
                                    preg_replace(
                                        '/<\?xml version="([^\"]+)"([^\>]+)>/i',
                                        '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>',
                                        $this->_soap->handle()
                                    )
                            )
                    )
            );
            Mage::log($content, null, 'soap.log');
            $this->getController()->getResponse()
                 ->clearHeaders()
                 ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
                 ->setBody($content);
        } catch( Zend_Soap_Server_Exception $e ) {
            $this->fault( $e->getCode(), $e->getMessage() );
        } catch( Exception $e ) {
            $this->fault( $e->getCode(), $e->getMessage() );
        }
    }
}

  • 执行SOAP API调用,并在Magento目录中打开var/log/soap.log.如果XML在日志文件中完整而不是您的响应中完整,则问题在于Content-Length标头.

  • Execute the SOAP API call and open var/log/soap.log in your Magento directory. If the XML is complete in the log file but not in your response, then the Content-Length header is the problem.

    如何更正Content-Length标头

    1. 留在Mage_Api_Model_Server_Wsi_Adapter_Soap的副本中,然后在我们刚刚修改的代码中添加一行:

    1. Stay in your copy of Mage_Api_Model_Server_Wsi_Adapter_Soap and add one line to the code we just modified:

    public function run()
    {
        $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
    
        if ($this->getController()->getRequest()->getParam('wsdl') !== null) {
            /* don't modify the first part ... */
        } else {
            try {
                $this->_instantiateServer();
    
                $content = preg_replace(
                        '/(\>\<)/i',
                        ">\n<",
                        str_replace(
                                '<soap:operation soapAction=""></soap:operation>',
                                "<soap:operation soapAction=\"\" />\n",
                                str_replace(
                                        '<soap:body use="literal"></soap:body>',
                                        "<soap:body use=\"literal\" />\n",
                                        preg_replace(
                                            '/<\?xml version="([^\"]+)"([^\>]+)>/i',
                                            '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>',
                                            $this->_soap->handle()
                                        )
                                )
                        )
                );
                Mage::log($content, null, 'soap.log');
                $this->getController()->getResponse()
                     ->clearHeaders()
                     ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
                     ->setHeader('Content-Length',strlen($content), true)
                     ->setBody($content);
            } catch( Zend_Soap_Server_Exception $e ) {
                $this->fault( $e->getCode(), $e->getMessage() );
            } catch( Exception $e ) {
                $this->fault( $e->getCode(), $e->getMessage() );
            }
        }
    }
    

    请注意以下行:

    ->setHeader('Content-Length',strlen($content), true)
    

    我们计算并设置Content-Length标头.第三个参数true是重要的,因为它告诉框架覆盖现有的Content-Length标头.

    We calculate and set the Content-Length header. The third parameter, true, is important because it tells the framework to overwrite the existing Content-Length header.

    如果您问为什么,则会发生此问题,因为我没有完全消除该错误,所以我无法确切地告诉您.

    If you ask why this problem occurs I can't tell you exactly because I didn't hunt the bug all the way down.

    从我看到的情况来看,只要XML响应的长度< = 8000字节,一切都很好.如果响应长度超过8000个字节,并且XML由x行组成,则响应将被x个字符截断.看起来这是一个问题,其中有不同的回车码和/或编码问题,这些错误导致对响应内容长度的错误计算.

    From what I saw, everything is fine as long as the XML response has a length <= 8000 bytes. If the response is longer than 8000 bytes and the XML consists of x lines, the response is truncated by x characters. It looks like it is a problem with the different carriage return codes and/or with encoding issues which lead to the wrong calculation of the response content length.

    这篇关于Magento-在Lion下使用MAMP堆栈时SOAP API响应不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆