Exemplo n.º 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\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;
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * Execute API request
  *
  * @return void
  * @throws AuthorizationException
  * @throws \Magento\Framework\Exception\InputException
  * @throws \Magento\Framework\Webapi\Exception
  */
 protected function processApiRequest()
 {
     $inputParams = $this->getInputParamsResolver()->resolve();
     $route = $this->getInputParamsResolver()->getRoute();
     $serviceMethodName = $route->getServiceMethod();
     $serviceClassName = $route->getServiceClass();
     $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);
     }
     $header = $this->getDeploymentConfig()->get(ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT);
     if ($header) {
         $this->_response->setHeader('X-Frame-Options', $header);
     }
     $this->_response->prepareResponse($outputData);
 }