/** * Test successful WSDL content generation. */ public function testDispatchWsdl() { $this->_mockGetParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL, 1); $wsdl = 'Some WSDL content'; $this->_wsdlGeneratorMock->expects($this->any())->method('generate')->will($this->returnValue($wsdl)); $this->_soapController->dispatch($this->_requestMock); $this->assertEquals($wsdl, $this->_responseMock->getBody()); }
/** * Dispatch SOAP request. * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if ($this->_isWsdlRequest()) { $this->validateWsdlRequest(); $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_request->getScheme(), $this->_request->getHttpHost(), $this->_soapServer->generateUri()); $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST); $this->_setResponseBody($responseBody); } else { if ($this->_isWsdlListRequest()) { $servicesList = []; foreach (array_keys($this->_wsdlGenerator->getListOfServices()) as $serviceName) { $servicesList[$serviceName]['wsdl_endpoint'] = $this->_soapServer->getEndpointUri() . '?' . \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL . '&services=' . $serviceName; } $renderer = $this->rendererFactory->get(); $this->_setResponseContentType($renderer->getMimeType()); $this->_setResponseBody($renderer->render($servicesList)); } else { $this->_soapServer->handle(); } } } catch (\Exception $e) { $this->_prepareErrorResponse($e); } return $this->_response; }
public function testDispatchInvalidWsdlRequest() { $params = [\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL => 1, 'param_1' => 'foo', 'param_2' => 'bar,']; $this->_mockGetParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL, 1); $this->_requestMock->expects($this->once())->method('getParams')->will($this->returnValue($params)); $this->_errorProcessorMock->expects($this->any())->method('maskException')->will($this->returnValue(new \Magento\Framework\Webapi\Exception(__('message')))); $wsdl = 'Some WSDL content'; $this->_wsdlGeneratorMock->expects($this->any())->method('generate')->will($this->returnValue($wsdl)); $encoding = "utf-8"; $this->_soapServerMock->expects($this->any())->method('getApiCharset')->will($this->returnValue($encoding)); $this->_soapController->dispatch($this->_requestMock); $expectedMessage = <<<EXPECTED_MESSAGE <?xml version="1.0" encoding="{$encoding}"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" > <env:Body> <env:Fault> <env:Code> <env:Value>env:Sender</env:Value> </env:Code> <env:Reason> <env:Text xml:lang="en">message</env:Text> </env:Reason> </env:Fault> </env:Body> </env:Envelope> EXPECTED_MESSAGE; $this->assertXmlStringEqualsXmlString($expectedMessage, $this->_responseMock->getBody()); }
/** * Test exception for handle * * @expectedException \Magento\Framework\Webapi\Exception * @expectedExceptionMessage exception message */ public function testHandleWithException() { $genWSDL = 'generatedWSDL'; $exceptionMsg = 'exception message'; $requestedService = ['catalogProduct']; $serviceMetadata = ['methods' => ['methodName' => ['interface' => 'aInterface']]]; $this->serviceMetadata->expects($this->any())->method('getServiceMetadata')->willReturn($serviceMetadata); $this->_typeProcessor->expects($this->once())->method('processInterfaceCallInfo')->willThrowException(new \Magento\Framework\Webapi\Exception(__($exceptionMsg))); $this->assertEquals($genWSDL, $this->_wsdlGenerator->generate($requestedService, 'http://', 'magento.host', '/soap/default')); }
/** * Dispatch SOAP request. * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if ($this->_isWsdlRequest()) { $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_soapServer->generateUri()); $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST); $this->_setResponseBody($responseBody); } else { $this->_soapServer->handle(); } } catch (\Exception $e) { $this->_prepareErrorResponse($e); } return $this->_response; }
/** * Dispatch SOAP request. * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if (!$this->_appState->isInstalled()) { throw new WebapiException(__('Magento is not yet installed')); } if ($this->_isWsdlRequest()) { $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_soapServer->generateUri()); $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST); $this->_setResponseBody($responseBody); } else { $consumerId = $this->_oauthService->validateAccessToken($this->_getAccessToken()); $this->_request->setConsumerId($consumerId); $this->_soapServer->handle(); } } catch (\Exception $e) { $this->_prepareErrorResponse($e); } return $this->_response; }
/** * @test */ public function testGetOutputMessageName() { $this->assertEquals("operationNameResponse", $this->_wsdlGenerator->getOutputMessageName("operationName")); }
/** * Get WSDL local URI * * Local WSDL URI is used to be able to pass wsdl schema to SoapServer without authorization * * @return string */ private function getWsdlLocalUri() { $wsdlBody = $this->wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_request->getScheme(), $this->_request->getHttpHost(), $this->generateUri()); return 'data://text/plain;base64,' . base64_encode($wsdlBody); }