_router = $router; $this->_request = $request; $this->_response = $response; $this->_objectManager = $objectManager; $this->_appState = $appState; $this->authorization = $authorization; $this->serviceInputProcessor = $serviceInputProcessor; $this->_errorProcessor = $errorProcessor; $this->_pathProcessor = $pathProcessor; $this->areaList = $areaList; $this->paramsOverrider = $paramsOverrider; $this->storeManager = $storeManager; $this->requestProcessorPool = $requestProcessorPool; } /** * Handle REST request * * Based on request decide is it schema request or API request and process accordingly. * Throws Exception in case if cannot be processed properly. * * @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 { $processor = $this->requestProcessorPool->getProcessor($this->_request); $processor->process($this->_request); } catch (\Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_response->setException($maskedException); } return $this->_response; } /** * Check if current request is schema request. * * @return bool */ protected function isSchemaRequest() { return $this->_request->getPathInfo() === self::SCHEMA_PATH; } /** * Retrieve current route. * * @return Route * @deprecated 100.1.0 * @see \Magento\Webapi\Controller\Rest\InputParamsResolver::getRoute */ protected function getCurrentRoute() { if (!$this->_route) { $this->_route = $this->_router->match($this->_request); } return $this->_route; } /** * Perform authentication and authorization. * * @throws \Magento\Framework\Exception\AuthorizationException * @return void * @deprecated 100.1.0 * @see \Magento\Webapi\Controller\Rest\RequestValidator::checkPermissions */ protected function checkPermissions() { $route = $this->getCurrentRoute(); if (!$this->authorization->isAllowed($route->getAclResources())) { $params = ['resources' => implode(', ', $route->getAclResources())]; throw new AuthorizationException( __("The consumer isn't authorized to access %resources.", $params) ); } } /** * Validate request * * @throws AuthorizationException * @throws \Magento\Framework\Webapi\Exception * @return void * @deprecated 100.1.0 * @see \Magento\Webapi\Controller\Rest\RequestValidator::validate */ protected function validateRequest() { $this->checkPermissions(); if ($this->getCurrentRoute()->isSecure() && !$this->_request->isSecure()) { throw new \Magento\Framework\Webapi\Exception(__('Operation allowed only in HTTPS')); } if ($this->storeManager->getStore()->getCode() === Store::ADMIN_CODE && strtoupper($this->_request->getMethod()) === RestRequest::HTTP_METHOD_GET ) { throw new \Magento\Framework\Webapi\Exception(__('Cannot perform GET operation with store code \'all\'')); } } }