Exemple #1
0
 /**
  * Handle REST 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 {
         $this->checkPermissions();
         $route = $this->getCurrentRoute();
         if ($route->isSecure() && !$this->_request->isSecure()) {
             throw new \Magento\Webapi\Exception(__('Operation allowed only in HTTPS'));
         }
         /** @var array $inputData */
         $inputData = $this->_request->getRequestData();
         $serviceMethodName = $route->getServiceMethod();
         $serviceClassName = $route->getServiceClass();
         $inputData = $this->overrideParams($inputData, $route->getParameters());
         $inputParams = $this->_serializer->getInputData($serviceClassName, $serviceMethodName, $inputData);
         $service = $this->_objectManager->get($serviceClassName);
         /** @var \Magento\Framework\Service\Data\AbstractExtensibleObject $outputData */
         $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams);
         $outputData = $this->dataObjectConverter->processServiceOutput($outputData);
         if ($this->_request->getParam(PartialResponseProcessor::FILTER_PARAMETER) && is_array($outputData)) {
             $outputData = $this->partialResponseProcessor->filter($outputData);
         }
         $this->_response->prepareResponse($outputData);
     } catch (\Exception $e) {
         $maskedException = $this->_errorProcessor->maskException($e);
         $this->_response->setException($maskedException);
     }
     return $this->_response;
 }
Exemple #2
0
 /**
  * Convert SOAP operation arguments into format acceptable by service method.
  *
  * @param string $serviceClass
  * @param string $serviceMethod
  * @param array $arguments
  * @return array
  */
 protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments)
 {
     /** SoapServer wraps parameters into array. Thus this wrapping should be removed to get access to parameters. */
     $arguments = reset($arguments);
     $arguments = $this->_dataObjectConverter->convertStdObjectToArray($arguments, true);
     return $this->_serializer->getInputData($serviceClass, $serviceMethod, $arguments);
 }
Exemple #3
0
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_appStateMock->expects($this->any())->method('isInstalled')->will($this->returnValue(true));
     $this->_authzServiceMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
 /**
  * @param array $requestData Data from the request
  * @param array $parameters Data from config about which parameters to override
  * @param array $expectedOverriddenParams Result of overriding $requestData when applying rules from $parameters
  * @param int $userId The id of the user invoking the request
  * @param int $userType The type of user invoking the request
  *
  * @dataProvider overrideParmasDataProvider
  */
 public function testOverrideParams($requestData, $parameters, $expectedOverriddenParams, $userId, $userType)
 {
     $this->_routeMock->expects($this->once())->method('getParameters')->will($this->returnValue($parameters));
     $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1']));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->_requestMock->expects($this->any())->method('getRequestData')->will($this->returnValue($requestData));
     $this->userContextMock->expects($this->any())->method('getUserId')->will($this->returnValue($userId));
     $this->userContextMock->expects($this->any())->method('getUserType')->will($this->returnValue($userType));
     // serializer should expect overridden params
     $this->serializerMock->expects($this->once())->method('getInputData')->with($this->equalTo('Magento\\Webapi\\Controller\\TestService'), $this->equalTo('testMethod'), $this->equalTo($expectedOverriddenParams));
     $this->_restController->dispatch($this->_requestMock);
 }
 public function testNestedArrayOfDataObjectProperties()
 {
     $data = array('dataObjects' => array('items' => array(array('entityId' => 1, 'name' => 'First'), array('entityId' => 2, 'name' => 'Second'))));
     $result = $this->serializer->getInputData('\\Magento\\Webapi\\Service\\Entity\\TestService', 'nestedDataArray', $data);
     $this->assertNotNull($result);
     /** @var array $result */
     $this->assertEquals(1, count($result));
     /** @var DataArrayData $dataObjects */
     $dataObjects = $result[0];
     $this->assertTrue($dataObjects instanceof DataArrayData);
     /** @var array $items */
     $items = $dataObjects->getItems();
     $this->assertEquals(2, count($items));
     /** @var SimpleData $first */
     $first = $items[0];
     /** @var SimpleData $second */
     $second = $items[1];
     $this->assertTrue($first instanceof SimpleData);
     $this->assertEquals(1, $first->getEntityId());
     $this->assertEquals('First', $first->getName());
     $this->assertTrue($second instanceof SimpleData);
     $this->assertEquals(2, $second->getEntityId());
     $this->assertEquals('Second', $second->getName());
 }