This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Change Webapi extension to use Inject Pool logic #1
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
066141b
Change Webapi extension to use Inject Pool login and configuration in…
nuzil 3137727
MBI-3 Modified Magento_Webapi module:
82a7783
MBI-3 Edited 'RestTest.php' test file in Magento_Webapi module: tempo…
f5b78dc
Clean the code
nuzil c09f916
Webapi and Swagger module changes for WebapiAsync PoC 0.0.1
4b58c8a
WebapiAsync new xsd attribute for handler which allow to pass service…
1a92d84
formating code to follow EcgM2,PSR2 standards
04847a2
formating code to follow EcgM2,PSR2 standards
b05d6a7
clean swagger async, updated rest Unit test, updated Restcontroller a…
3c8eea2
formating
707cc65
formating paddings
602e4e9
formating code to MEQP2 standard
0d612e7
mess code detector fixes
aa45d49
fix for undefined method Magento\Webapi\Controller\Rest\Router\Route:…
5d5d48d
Merge magento/bulk-api-ce#1.
vrann 01a87c2
Merge magento-partners/magento2ce/2.3-develop.
vrann fe992e3
Merge branch '2.3-develop' into async-webapi-1
vrann f8fced8
removed request_schema attribute added in previous commits
e736b7a
Testing of Travis automated tests execution
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Webapi\Controller; | ||
|
||
use Magento\Framework\App\DeploymentConfig; | ||
|
@@ -13,15 +14,13 @@ | |
use Magento\Framework\Webapi\Request; | ||
use Magento\Framework\Webapi\Rest\Request as RestRequest; | ||
use Magento\Framework\Webapi\Rest\Response as RestResponse; | ||
use Magento\Framework\Webapi\Rest\Response\FieldsFilter; | ||
use Magento\Framework\Webapi\ServiceInputProcessor; | ||
use Magento\Framework\Webapi\ServiceOutputProcessor; | ||
use Magento\Store\Model\Store; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Webapi\Controller\Rest\ParamsOverrider; | ||
use Magento\Webapi\Controller\Rest\Router; | ||
use Magento\Webapi\Controller\Rest\Router\Route; | ||
use Magento\Webapi\Model\Rest\Swagger\Generator; | ||
use Magento\Webapi\Controller\Rest\RequestProcessorPool; | ||
|
||
/** | ||
* Front controller for WebAPI REST area. | ||
|
@@ -31,7 +30,11 @@ | |
*/ | ||
class Rest implements \Magento\Framework\App\FrontControllerInterface | ||
{ | ||
/** Path for accessing REST API schema */ | ||
/** | ||
* Path for accessing REST API schema | ||
* | ||
* @deprecated 100.3.0 | ||
*/ | ||
const SCHEMA_PATH = '/schema'; | ||
|
||
/** | ||
|
@@ -93,11 +96,6 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface | |
*/ | ||
protected $areaList; | ||
|
||
/** | ||
* @var \Magento\Framework\Webapi\Rest\Response\FieldsFilter | ||
*/ | ||
protected $fieldsFilter; | ||
|
||
/** | ||
* @var \Magento\Framework\Session\Generic | ||
*/ | ||
|
@@ -110,31 +108,16 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface | |
protected $paramsOverrider; | ||
|
||
/** | ||
* @var \Magento\Framework\Webapi\ServiceOutputProcessor | ||
*/ | ||
protected $serviceOutputProcessor; | ||
|
||
/** | ||
* @var \Magento\Webapi\Model\Rest\Swagger\Generator | ||
* @var RequestProcessorPool | ||
*/ | ||
protected $swaggerGenerator; | ||
protected $requestProcessorPool; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
* @deprecated 100.1.0 | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var DeploymentConfig | ||
*/ | ||
private $deploymentConfig; | ||
|
||
/** | ||
* @var Rest\InputParamsResolver | ||
*/ | ||
private $inputParamsResolver; | ||
|
||
/** | ||
* Initialize dependencies | ||
* | ||
|
@@ -148,11 +131,9 @@ class Rest implements \Magento\Framework\App\FrontControllerInterface | |
* @param ErrorProcessor $errorProcessor | ||
* @param PathProcessor $pathProcessor | ||
* @param \Magento\Framework\App\AreaList $areaList | ||
* @param FieldsFilter $fieldsFilter | ||
* @param ParamsOverrider $paramsOverrider | ||
* @param ServiceOutputProcessor $serviceOutputProcessor | ||
* @param Generator $swaggerGenerator , | ||
* @param StoreManagerInterface $storeManager | ||
* @param RequestProcessorPool $requestProcessorPool | ||
* | ||
* TODO: Consider removal of warning suppression | ||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||
|
@@ -168,11 +149,9 @@ public function __construct( | |
ErrorProcessor $errorProcessor, | ||
PathProcessor $pathProcessor, | ||
\Magento\Framework\App\AreaList $areaList, | ||
FieldsFilter $fieldsFilter, | ||
ParamsOverrider $paramsOverrider, | ||
ServiceOutputProcessor $serviceOutputProcessor, | ||
Generator $swaggerGenerator, | ||
StoreManagerInterface $storeManager | ||
StoreManagerInterface $storeManager, | ||
RequestProcessorPool $requestProcessorPool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to operate with Underhood of |
||
) { | ||
$this->_router = $router; | ||
$this->_request = $request; | ||
|
@@ -184,37 +163,9 @@ public function __construct( | |
$this->_errorProcessor = $errorProcessor; | ||
$this->_pathProcessor = $pathProcessor; | ||
$this->areaList = $areaList; | ||
$this->fieldsFilter = $fieldsFilter; | ||
$this->paramsOverrider = $paramsOverrider; | ||
$this->serviceOutputProcessor = $serviceOutputProcessor; | ||
$this->swaggerGenerator = $swaggerGenerator; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* Get deployment config | ||
* | ||
* @return DeploymentConfig | ||
*/ | ||
private function getDeploymentConfig() | ||
{ | ||
if (!$this->deploymentConfig instanceof \Magento\Framework\App\DeploymentConfig) { | ||
$this->deploymentConfig = \Magento\Framework\App\ObjectManager::getInstance() | ||
->get(\Magento\Framework\App\DeploymentConfig::class); | ||
} | ||
return $this->deploymentConfig; | ||
} | ||
|
||
/** | ||
* Set deployment config | ||
* | ||
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig | ||
* @return void | ||
* @deprecated 100.1.0 | ||
*/ | ||
public function setDeploymentConfig(\Magento\Framework\App\DeploymentConfig $deploymentConfig) | ||
{ | ||
$this->deploymentConfig = $deploymentConfig; | ||
$this->requestProcessorPool = $requestProcessorPool; | ||
} | ||
|
||
/** | ||
|
@@ -231,17 +182,14 @@ 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); | ||
->load(\Magento\Framework\App\Area::PART_TRANSLATE); | ||
try { | ||
if ($this->isSchemaRequest()) { | ||
$this->processSchemaRequest(); | ||
} else { | ||
$this->processApiRequest(); | ||
} | ||
$this->requestProcessorPool->process($this->_request); | ||
} catch (\Exception $e) { | ||
$maskedException = $this->_errorProcessor->maskException($e); | ||
$this->_response->setException($maskedException); | ||
} | ||
|
||
return $this->_response; | ||
} | ||
|
||
|
@@ -267,6 +215,7 @@ protected function getCurrentRoute() | |
if (!$this->_route) { | ||
$this->_route = $this->_router->match($this->_request); | ||
} | ||
|
||
return $this->_route; | ||
} | ||
|
||
|
@@ -289,60 +238,6 @@ protected function checkPermissions() | |
} | ||
} | ||
|
||
/** | ||
* Execute schema request | ||
* | ||
* @return void | ||
*/ | ||
protected function processSchemaRequest() | ||
{ | ||
$requestedServices = $this->_request->getRequestedServices('all'); | ||
$requestedServices = $requestedServices == Request::ALL_SERVICES | ||
? $this->swaggerGenerator->getListOfServices() | ||
: $requestedServices; | ||
$responseBody = $this->swaggerGenerator->generate( | ||
$requestedServices, | ||
$this->_request->getScheme(), | ||
$this->_request->getHttpHost(false), | ||
$this->_request->getRequestUri() | ||
); | ||
$this->_response->setBody($responseBody)->setHeader('Content-Type', 'application/json'); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
/** | ||
* Validate request | ||
* | ||
|
@@ -364,20 +259,4 @@ protected function validateRequest() | |
throw new \Magento\Framework\Webapi\Exception(__('Cannot perform GET operation with store code \'all\'')); | ||
} | ||
} | ||
|
||
/** | ||
* The getter function to get InputParamsResolver object | ||
* | ||
* @return \Magento\Webapi\Controller\Rest\InputParamsResolver | ||
* | ||
* @deprecated 100.1.0 | ||
*/ | ||
private function getInputParamsResolver() | ||
{ | ||
if ($this->inputParamsResolver === null) { | ||
$this->inputParamsResolver = \Magento\Framework\App\ObjectManager::getInstance() | ||
->get(\Magento\Webapi\Controller\Rest\InputParamsResolver::class); | ||
} | ||
return $this->inputParamsResolver; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/code/Magento/Webapi/Controller/Rest/RequestProcessorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Webapi\Controller\Rest; | ||
|
||
/** | ||
* Request processor interface | ||
*/ | ||
interface RequestProcessorInterface | ||
{ | ||
|
||
/** | ||
* @param \Magento\Framework\Webapi\Rest\Request $request | ||
* @return void | ||
* @throws \Magento\Framework\Exception\AuthorizationException | ||
* @throws \Magento\Framework\Exception\InputException | ||
* @throws \Magento\Framework\Webapi\Exception | ||
*/ | ||
public function process(\Magento\Framework\Webapi\Rest\Request $request); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getProcessorPath(); | ||
} |
75 changes: 75 additions & 0 deletions
75
app/code/Magento/Webapi/Controller/Rest/RequestProcessorPool.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Webapi\Controller\Rest; | ||
|
||
/** | ||
* Request Processor Pool | ||
*/ | ||
class RequestProcessorPool implements RequestProcessorInterface | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $requestProcessors; | ||
|
||
/** | ||
* Initial dependencies | ||
* | ||
* @param array $requestProcessors | ||
*/ | ||
public function __construct($requestProcessors = []) | ||
{ | ||
$this->requestProcessors = $requestProcessors; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function process(\Magento\Framework\Webapi\Rest\Request $request) | ||
{ | ||
$processed = false; | ||
|
||
/** | ||
* @var RequestProcessorInterface $processor | ||
*/ | ||
foreach ($this->requestProcessors as $processor) { | ||
if (strpos(ltrim($request->getPathInfo(), '/'), $processor->getProcessorPath()) === 0) { | ||
$processor->process($request); | ||
$processed = true; | ||
break; | ||
} | ||
} | ||
if (!$processed) { | ||
throw new \Magento\Framework\Exception\LocalizedException( | ||
__('Specified request cannot be processed.'), | ||
null, | ||
400 | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Get array of rest processors from di.xml | ||
* | ||
* @return array | ||
*/ | ||
public function getProcessors() | ||
{ | ||
return $this->requestProcessors; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getProcessorPath() | ||
{ | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to follow Backward Compatibility
ObjectManager::getInstance()->create(...::class)