Show Advanced KnowledgeHide Advanced KnowledgeSOAP Plugin Slot
Page Overview
[Hide] [Show] 1 Initial Problem
Currently, it is not possible to extend the Soap webservice with new methods or types. The Soap methods offered by the ILIAS core are not always sufficent or their business logic must be patched due to client specific needs.
2 Conceptual Summary
This feature request suggests the introduction of a new Soap plugin slot. A Soap plugin defines a set of new Soap methods and, if required, complex types. The methods and types are registered in the internal Soap server in ILIAS.
3 User Interface Modifications
This feature does not include any user interface modifications.
4 Technical Information
The plugin slot depends on the internal Soap server of ILIAS (nusoapserver).
5 Contact
6 Funding
Interest in funding:
- Funded by a client of Studer + Raimann AG
7 Discussion
The introduction of a Soap plugin slot was approved by Leifos. Due to time limits, it was not possible for Leifos to develop this feature. It was an oral agreement that studer+raimann develops the plugin slot, please see the implementation chapter below for more information.
JourFixe, ILIAS [jourfixe], April 24, 2017: We highly appreciate this feature request and schedule it for 5.3. Stefan Wanzenried will offer a pull request. Details might be discussed between Stefan M. and Stefan W.
8 Implementation
A SOAP plugin is implemented by extending the plugin base class ilSoapHookPlugin. The plugin must implement two abstract methods:
- getSoapMethods : ilSoapMethod[]
- getWsdlTypes : ilWsdlType[]
The first method returns new Soap methods that are registered to the Soap server. Should any of the new methods require additional types beside the ones already available (tns:int, tns:string...), they can be returned in the second method. Please see the next section for more details how the interfaces looks like.
Interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <?php /** * Interface ilSoapMethod * * Describes a soap method which can be added to the ILIAS SOAP webservice * by a plugin of the SoapHook plugin slot */ interface ilSoapMethod { /** * Get the name of the method. Used as endpoint for SOAP requests. * Note that this name must be unique in combination with the service namespace. * * @return string */ public function getName(); /** * Get the input parameters. Array keys must correspond to parameter names and values must correspond * to a valid SOAP data-type * * @see ilNusoapUserAdministrationAdapter::__registerMethods() for examples * * @return array */ public function getInputParams(); /** * Get the output parameters in the same format as the input parameters * * @return array */ public function getOutputParams(); /** * Get the namespace of the service where this method belongs to * * @return string */ public function getServiceNamespace(); /** * Get the service style, e.g. 'rpc' * * @return string */ public function getServiceStyle(); /** * Get the service use, e.g. 'encoded' * * @return string */ public function getServiceUse(); /** * Get the documentation of this method * * @return string */ public function getDocumentation(); /** * Execute the business logic for this SOAP method (when a SOAP request hits the endpoint defined by the name). * Note: This Method must return the data in the format specified by getOutputParams(). * * @param array $params Key/Value pair of parameters defined by getInputParams() * @return mixed */ public function execute(array $params); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <?php /** * Interface ilWsdlType */ interface ilWsdlType { /** * @return string */ public function getName(); /** * @return string */ public function getTypeClass(); /** * @return string */ public function getPhpType(); /** * @return string */ public function getCompositor(); /** * @return string */ public function getRestrictionBase(); /** * @return array */ public function getElements(); /** * @return array */ public function getAttributes(); /** * @return string */ public function getArrayType(); } |
There exists an abstract base class ilAbstractSoapMethod which implements ilSoapMethod and provides basic functionality to validate a given session-ID and bootstraping ILIAS. It wraps ilSoapAdministration so that any errors are converted to ilSoapPluginExceptions. These exceptions should be throwed by the developer in case of errors. The plugin slot catches the exceptions and returns the message and code to the Soap caller, in the correct form. See the example plugin section for more information.
Sample Plugin
The sample plugin returns a single ilSoapMethod which returns the title of an object by a given ref-Id. The new Soap method is defined by:
- Name: getObjectTitleByRefId
- Input parameters
- sid: Session-ID obtained by the core Soap method "login"
- ref_id: A ref-ID of an object
- Output parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | <?php require_once('./Services/WebServices/SOAP/classes/class.ilAbstractSoapMethod.php'); /** * Class SampleSoapMethod * * Returns the title of an object from a given Ref-ID */ class SampleSoapMethod extends ilAbstractSoapMethod { /** * @inheritdoc */ public function getName() { return 'getObjectTitleByRefId'; } /** * @inheritdoc */ public function getInputParams() { return array( 'sid' => 'xsd:string', 'ref_id' => 'xsd:int', ); } /** * @inheritdoc */ public function getOutputParams() { return array( 'title' => 'xsd:string', ); } /** * @inheritdoc */ public function getServiceNamespace() { return 'urn:sample'; } /** * @inheritdoc */ public function getServiceStyle() { return 'rpc'; } /** * @inheritdoc */ public function getServiceUse() { return 'encoded'; } /** * @inheritdoc */ public function getDocumentation() { return "Returns the title of an object by the given Ref-ID - just for demo purposes!"; } /** * @inheritdoc */ public function execute(array $params) { $session_id = (isset($params[0])) ? $params[0] : ''; $ref_id = (isset($params[1])) ? (int) $params[1] : 0; $this->initIliasAndCheckSession($session_id); // Throws exception if session is not valid if (!$ref_id) { throw new ilSoapPluginException("Ref-Id $ref_id is not provided"); } $obj_id = ilObject::_lookupObjId($ref_id); if (!$obj_id) { throw new ilSoapPluginException("Could not load object"); } return ilObject::_lookupTitle($obj_id); } } |
Calling Soap methods of plugins
The new Soap methods of plugins are added to the existing service endpoint:
- http://your-ilias-domain.com/webservice/soap/server.php
However, it is needed to pass the client-ID as GET parameter in order see methods of plugins and also to perform SOAP requests. That's because SOAP plugins exist under a given ILIAS client and the plugin slot must bootstrap ILIAS with the correct client ID to load the Soap plugins. Thus, the service endpoint becomes
- http://your-ilias-domain.com/webservice/soap/server.php?client_id=ilias
Test Cases
A dummy plugin has to be offered in https://github.com/ILIAS-eLearning to test the plugin functionality.
Testcase:
- C18829: Neuen Endpunkt mit Plugin Hook hinzufügen
Approval
Approved at 14. Aug 2017 by Meyer, Stefan [smeyer], see https://github.com/ILIAS-eLearning/ILIAS/pull/517