public function testProcessWithoutStoreCode()
 {
     $path = 'rest/V1/customerAccounts/createCustomer';
     $result = $this->pathProcessor->process($path);
     $this->assertEquals('/V1/customerAccounts/createCustomer', $result);
     $this->assertEquals('default', $this->storeManager->getStore()->getCode());
 }
 /**
  * @dataProvider processPathDataProvider
  *
  * @param string $storeCodeInPath
  * @param string $storeCodeSet
  * @param int $setCurrentStoreCallCtr
  */
 public function testAllStoreCode($storeCodeInPath, $storeCodeSet, $setCurrentStoreCallCtr = 1)
 {
     $storeCodeInPath = !$storeCodeInPath ?: '/' . $storeCodeInPath;
     // add leading slash if store code not empty
     $inPath = 'rest' . $storeCodeInPath . $this->endpointPath;
     $this->storeManagerMock->expects($this->exactly($setCurrentStoreCallCtr))->method('setCurrentStore')->with($storeCodeSet);
     $result = $this->model->process($inPath);
     $this->assertSame($this->endpointPath, $result);
 }
Example #3
0
 /**
  * Dispatch SOAP 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 {
         if ($this->_isWsdlRequest()) {
             $this->validateWsdlRequest();
             $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_request->getScheme(), $this->_request->getHttpHost(), $this->_soapServer->generateUri());
             $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST);
             $this->_setResponseBody($responseBody);
         } else {
             if ($this->_isWsdlListRequest()) {
                 $servicesList = [];
                 foreach (array_keys($this->_wsdlGenerator->getListOfServices()) as $serviceName) {
                     $servicesList[$serviceName]['wsdl_endpoint'] = $this->_soapServer->getEndpointUri() . '?' . \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL . '&services=' . $serviceName;
                 }
                 $renderer = $this->rendererFactory->get();
                 $this->_setResponseContentType($renderer->getMimeType());
                 $this->_setResponseBody($renderer->render($servicesList));
             } else {
                 $this->_soapServer->handle();
             }
         }
     } catch (\Exception $e) {
         $this->_prepareErrorResponse($e);
     }
     return $this->_response;
 }
Example #4
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;
 }
Example #5
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 {
         if ($this->isSchemaRequest()) {
             $this->processSchemaRequest();
         } else {
             $this->processApiRequest();
         }
     } catch (\Exception $e) {
         $maskedException = $this->_errorProcessor->maskException($e);
         $this->_response->setException($maskedException);
     }
     return $this->_response;
 }
Example #6
0
 /**
  * Dispatch SOAP 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 {
         if ($this->_isWsdlRequest()) {
             $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_soapServer->generateUri());
             $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST);
             $this->_setResponseBody($responseBody);
         } else {
             $this->_soapServer->handle();
         }
     } catch (\Exception $e) {
         $this->_prepareErrorResponse($e);
     }
     return $this->_response;
 }