/** * Covers object with custom attributes * * @dataProvider customAttributesDataProvider * @param $customAttributeType * @param $inputData * @param $expectedObject */ public function testCustomAttributesProperties($customAttributeType, $inputData, $expectedObject) { $this->customAttributeTypeLocator->expects($this->any())->method('getType')->willReturn($customAttributeType); $result = $this->serviceInputProcessor->process('Magento\\Framework\\Webapi\\Test\\Unit\\ServiceInputProcessor\\TestService', 'ObjectWithCustomAttributesMethod', $inputData); $this->assertTrue($result[0] instanceof ObjectWithCustomAttributes); $this->assertEquals($expectedObject, $result[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->serviceInputProcessor->process($serviceClass, $serviceMethod, $arguments); }
/** * 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\Framework\Webapi\Exception(__('Operation allowed only in HTTPS')); } /** @var array $inputData */ $inputData = $this->_request->getRequestData(); $serviceMethodName = $route->getServiceMethod(); $serviceClassName = $route->getServiceClass(); $inputData = $this->paramsOverrider->override($inputData, $route->getParameters()); $inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData); $service = $this->_objectManager->get($serviceClassName); /** @var \Magento\Framework\Api\AbstractExtensibleObject $outputData */ $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); $outputData = $this->serviceOutputProcessor->process($outputData, $serviceClassName, $serviceMethodName); if ($this->_request->getParam(FieldsFilter::FILTER_PARAMETER) && is_array($outputData)) { $outputData = $this->fieldsFilter->filter($outputData); } $this->_response->prepareResponse($outputData); } catch (\Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_response->setException($maskedException); } return $this->_response; }
/** * Process and resolve input parameters * * @return array * @throws \Magento\Framework\Webapi\Exception */ public function resolve() { $this->requestValidator->validate(); $route = $this->getRoute(); $serviceMethodName = $route->getServiceMethod(); $serviceClassName = $route->getServiceClass(); /* * Valid only for updates using PUT when passing id value both in URL and body */ if ($this->request->getHttpMethod() == RestRequest::HTTP_METHOD_PUT) { $inputData = $this->paramsOverrider->overrideRequestBodyIdWithPathParam($this->request->getParams(), $this->request->getBodyParams(), $serviceClassName, $serviceMethodName); $inputData = array_merge($inputData, $this->request->getParams()); } else { $inputData = $this->request->getRequestData(); } $inputData = $this->paramsOverrider->override($inputData, $route->getParameters()); $inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData); return $inputParams; }
/** * Execute API request * * @return void * @throws AuthorizationException * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Webapi\Exception */ protected function processApiRequest() { $this->validateRequest(); /** @var array $inputData */ $inputData = $this->_request->getRequestData(); $route = $this->getCurrentRoute(); $serviceMethodName = $route->getServiceMethod(); $serviceClassName = $route->getServiceClass(); $inputData = $this->paramsOverrider->override($inputData, $route->getParameters()); $inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData); $service = $this->_objectManager->get($serviceClassName); /** @var \Magento\Framework\Api\AbstractExtensibleObject $outputData */ $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); $outputData = $this->serviceOutputProcessor->process($outputData, $serviceClassName, $serviceMethodName); if ($this->_request->getParam(FieldsFilter::FILTER_PARAMETER) && is_array($outputData)) { $outputData = $this->fieldsFilter->filter($outputData); } $this->_response->prepareResponse($outputData); }
/** * Cover invalid custom attribute data * * @dataProvider invalidCustomAttributesDataProvider * @expectedException \Magento\Framework\Webapi\Exception */ public function testCustomAttributesExceptions($inputData) { $this->serviceInputProcessor->process('Magento\\Framework\\Webapi\\Test\\Unit\\ServiceInputProcessor\\TestService', 'ObjectWithCustomAttributesMethod', $inputData); }