Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JSON-RPC API support #2273

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions app/code/core/Mage/Api/Model/Server/Adapter/Jsonrpc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
fballiano marked this conversation as resolved.
Show resolved Hide resolved
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Api
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Api_Model_Server_Adapter_Jsonrpc extends Varien_Object implements Mage_Api_Model_Server_Adapter_Interface
{
protected $_jsonRpc = null;

/**
* Set handler class name for webservice
*
* @param string $handler
* @return $this
*/
public function setHandler($handler)
{
$this->setData('handler', $handler);
return $this;
}

/**
* Retrieve handler class name for webservice
*
* @return string
*/
public function getHandler()
{
return $this->getData('handler');
}

/**
* Set webservice api controller
*
* @param Mage_Api_Controller_Action $controller
* @return $this
*/
public function setController(Mage_Api_Controller_Action $controller)
{
$this->setData('controller', $controller);
return $this;
}

/**
* Retrieve webservice api controller. If no controller have been set - emulate it by the use of Varien_Object
*
* @return Mage_Api_Controller_Action|Varien_Object
*/
public function getController()
{
$controller = $this->getData('controller');

if (null === $controller) {
$controller = new Varien_Object(
array('request' => Mage::app()->getRequest(), 'response' => Mage::app()->getResponse())
);

$this->setData('controller', $controller);
}
return $controller;
}

/**
* Run webservice
*
* @return $this
*/
public function run()
{
$this->_jsonRpc = new Zend_Json_Server();
$this->_jsonRpc->setClass($this->getHandler());
$this->getController()->getResponse()
->clearHeaders()
->setHeader('Content-Type', 'application/json; charset=utf8')
->setBody($this->_jsonRpc->handle());
return $this;
}

/**
* Dispatch webservice fault
*
* @param int $code
* @param string $message
*/
public function fault($code, $message)
{
throw new Zend_Json_Exception($message, $code);
}
}
10 changes: 10 additions & 0 deletions app/code/core/Mage/Api/controllers/JsonrpcController.php
kiatng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

class Mage_Api_JsonrpcController extends Mage_Api_Controller_Action
{
public function indexAction()
{
$this->_getServer()->init($this, 'jsonrpc')
->run();
}
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Api/etc/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<handler>default</handler>
<active>1</active>
</xmlrpc>
<jsonrpc>
<model>api/server_adapter_jsonrpc</model>
<handler>default</handler>
<active>1</active>
</jsonrpc>
<default>
<use>soap</use>
</default>
Expand Down