/** * 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); }