示例#1
0
 /**
  * Handle REST request.
  *
  * @return Mage_Webapi_Controller_Dispatcher_Rest
  */
 public function dispatch()
 {
     try {
         $this->_authentication->authenticate();
         $route = $this->_router->match($this->_request);
         $operation = $this->_request->getOperationName();
         $resourceVersion = $this->_request->getResourceVersion();
         $this->_apiConfig->validateVersionNumber($resourceVersion, $this->_request->getResourceName());
         $method = $this->_apiConfig->getMethodNameByOperation($operation, $resourceVersion);
         $controllerClassName = $this->_apiConfig->getControllerClassByOperationName($operation);
         $controllerInstance = $this->_controllerFactory->createActionController($controllerClassName, $this->_request);
         $versionAfterFallback = $this->_apiConfig->identifyVersionSuffix($operation, $resourceVersion, $controllerInstance);
         /**
          * Route check has two stages:
          * The first is performed against full list of routes that is merged from all resources.
          * The second stage of route check can be performed only when actual version to be executed is known.
          */
         $this->_router->checkRoute($this->_request, $method, $versionAfterFallback);
         $this->_apiConfig->checkDeprecationPolicy($route->getResourceName(), $method, $versionAfterFallback);
         $action = $method . $versionAfterFallback;
         $this->_authorization->checkResourceAcl($route->getResourceName(), $method);
         $inputData = $this->_restPresentation->fetchRequestData($controllerInstance, $action);
         $outputData = call_user_func_array(array($controllerInstance, $action), $inputData);
         $this->_restPresentation->prepareResponse($method, $outputData);
     } catch (Exception $e) {
         $this->_response->setException($e);
     }
     $this->_response->sendResponse();
     return $this;
 }
示例#2
0
 /**
  * Test sendResponse method with exception rendering.
  *
  * @dataProvider dataProviderForSendResponseWithExceptionInDeveloperMode
  */
 public function testSendResponseWithExceptionInDeveloperMode($exception, $expectedResult, $assertMessage)
 {
     /** Mock all required objects. */
     $this->_rendererMock->expects($this->any())->method('getMimeType')->will($this->returnValue('application/json'));
     $this->_rendererMock->expects($this->any())->method('render')->will($this->returnCallback(array($this, 'callbackForSendResponseTest'), $this->returnArgument(0)));
     $this->_appMock->expects($this->any())->method('isDeveloperMode')->will($this->returnValue(true));
     $this->_responseRest->setException($exception);
     /** Start output buffering. */
     ob_start();
     $this->_responseRest->sendResponse();
     /** Clear output buffering. */
     ob_end_clean();
     $actualResponse = $this->_responseRest->getBody();
     $this->assertStringStartsWith($expectedResult, $actualResponse, $assertMessage);
 }