Beispiel #1
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return stdClass
  * @throws Mage_Webapi_Model_Soap_Fault
  * @throws Mage_Webapi_Exception
  */
 public function __call($operation, $arguments)
 {
     if (in_array($operation, $this->_requestHeaders)) {
         $this->_processSoapHeader($operation, $arguments);
     } else {
         try {
             if (is_null($this->_usernameToken)) {
                 throw new Mage_Webapi_Exception($this->_helper->__('WS-Security UsernameToken is not found in SOAP-request.'), Mage_Webapi_Exception::HTTP_UNAUTHORIZED);
             }
             $this->_authentication->authenticate($this->_usernameToken);
             $resourceVersion = $this->_getOperationVersion($operation);
             $resourceName = $this->_apiConfig->getResourceNameByOperation($operation, $resourceVersion);
             if (!$resourceName) {
                 throw new Mage_Webapi_Exception($this->_helper->__('Method "%s" is not found.', $operation), Mage_Webapi_Exception::HTTP_NOT_FOUND);
             }
             $controllerClass = $this->_apiConfig->getControllerClassByOperationName($operation);
             $controllerInstance = $this->_controllerFactory->createActionController($controllerClass, $this->_request);
             $method = $this->_apiConfig->getMethodNameByOperation($operation, $resourceVersion);
             $this->_authorization->checkResourceAcl($resourceName, $method);
             $arguments = reset($arguments);
             $arguments = get_object_vars($arguments);
             $versionAfterFallback = $this->_apiConfig->identifyVersionSuffix($operation, $resourceVersion, $controllerInstance);
             $this->_apiConfig->checkDeprecationPolicy($resourceName, $method, $versionAfterFallback);
             $action = $method . $versionAfterFallback;
             $arguments = $this->_helper->prepareMethodParams($controllerClass, $action, $arguments, $this->_apiConfig);
             $outputData = call_user_func_array(array($controllerInstance, $action), $arguments);
             return (object) array(self::RESULT_NODE_NAME => $outputData);
         } catch (Mage_Webapi_Exception $e) {
             throw new Mage_Webapi_Model_Soap_Fault($e->getMessage(), $e->getOriginator(), $e);
         } catch (Exception $e) {
             $maskedException = $this->_errorProcessor->maskException($e);
             throw new Mage_Webapi_Model_Soap_Fault($maskedException->getMessage(), Mage_Webapi_Model_Soap_Fault::FAULT_CODE_RECEIVER, $maskedException);
         }
     }
 }
Beispiel #2
0
 /**
  * Fetch data from request and prepare it for passing to specified action.
  *
  * @param object $controllerInstance
  * @param string $action
  * @return array
  */
 public function fetchRequestData($controllerInstance, $action)
 {
     $methodReflection = Mage_Webapi_Helper_Data::createMethodReflection($controllerInstance, $action);
     $methodName = $this->_configHelper->getMethodNameWithoutVersionSuffix($methodReflection);
     $bodyParamName = $this->_configHelper->getOperationBodyParamName($methodReflection);
     $requestParams = array_merge($this->_request->getParams(), array($bodyParamName => $this->_getRequestBody($methodName)));
     /** Convert names of ID and Parent ID params in request to those which are used in method interface. */
     $idArgumentName = $this->_configHelper->getOperationIdParamName($methodReflection);
     $parentIdParamName = Mage_Webapi_Controller_Router_Route_Rest::PARAM_PARENT_ID;
     $idParamName = Mage_Webapi_Controller_Router_Route_Rest::PARAM_ID;
     if (isset($requestParams[$parentIdParamName]) && $idArgumentName != $parentIdParamName) {
         $requestParams[$idArgumentName] = $requestParams[$parentIdParamName];
         unset($requestParams[$parentIdParamName]);
     } elseif (isset($requestParams[$idParamName]) && $idArgumentName != $idParamName) {
         $requestParams[$idArgumentName] = $requestParams[$idParamName];
         unset($requestParams[$idParamName]);
     }
     return $this->_apiHelper->prepareMethodParams($controllerInstance, $action, $requestParams, $this->_apiConfig);
 }
Beispiel #3
0
 /**
  * @dataProvider dataProviderForTestPrepareMethodParamsNegative
  * @param string|object $class
  * @param string $methodName
  * @param array $requestData
  * @param string $exceptionClass
  * @param string $exceptionMessage
  */
 public function testPrepareMethodParamsNegative($class, $methodName, $requestData, $exceptionClass, $exceptionMessage)
 {
     $this->setExpectedException($exceptionClass, $exceptionMessage);
     $this->_helper->prepareMethodParams($class, $methodName, $requestData, $this->_getApiConfig());
 }