Beispiel #1
0
    public function testConstructor()
    {
        $message = "Soap fault reason.";
        $details = ['param1' => 'value1', 'param2' => 2];
        $code = 111;
        $webapiException = new \Magento\Webapi\Exception($message, $code, \Magento\Webapi\Exception::HTTP_INTERNAL_ERROR, $details);
        $soapFault = new \Magento\Webapi\Model\Soap\Fault($this->_requestMock, $this->_soapServerMock, $webapiException, $this->_localeResolverMock, $this->_appStateMock);
        $actualXml = $soapFault->toXml();
        $wsdlUrl = urlencode(self::WSDL_URL);
        $expectedXml = <<<FAULT_XML
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:m="{$wsdlUrl}">
    <env:Body>
        <env:Fault>
            <env:Code>
                <env:Value>env:Receiver</env:Value>
            </env:Code>
            <env:Reason>
                <env:Text xml:lang="en">{$message}</env:Text>
            </env:Reason>
            <env:Detail>
                <m:GenericFault>
                    <m:Parameters>
                        <m:GenericFaultParameter>
                            <m:key>param1</m:key>
                            <m:value>value1</m:value>
                        </m:GenericFaultParameter>
                        <m:GenericFaultParameter>
                            <m:key>param2</m:key>
                            <m:value>2</m:value>
                        </m:GenericFaultParameter>
                    </m:Parameters>
                </m:GenericFault>
            </env:Detail>
        </env:Fault>
    </env:Body>
</env:Envelope>
FAULT_XML;
        $this->assertEquals($this->_sanitizeXML($expectedXml), $this->_sanitizeXML($actualXml), "Soap fault is invalid.");
    }
Beispiel #2
0
 /**
  * Set body and status code to response using information extracted from provided exception.
  *
  * @param \Exception $exception
  * @return void
  */
 protected function _prepareErrorResponse($exception)
 {
     $maskedException = $this->_errorProcessor->maskException($exception);
     if ($this->_isWsdlRequest()) {
         $httpCode = $maskedException->getHttpCode();
         $contentType = self::CONTENT_TYPE_WSDL_REQUEST;
     } else {
         $httpCode = Response::HTTP_OK;
         $contentType = self::CONTENT_TYPE_SOAP_CALL;
     }
     $this->_setResponseContentType($contentType);
     $this->_response->setHttpResponseCode($httpCode);
     $soapFault = new \Magento\Webapi\Model\Soap\Fault($this->_request, $this->_soapServer, $maskedException, $this->_localeResolver, $this->_appState);
     $this->_setResponseBody($soapFault->toXml());
 }