Difference between revisions of "REST API:exec Resource"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 6: Line 6:
:* A [[Class]] must be defined. (The <tt>exec</tt> resource invokes a method in the class.)
:* A [[Class]] must be defined. (The <tt>exec</tt> resource invokes a method in the class.)
:* An instance of the class is created automatically, so the method need not be <tt>static</tt>.
:* An instance of the class is created automatically, so the method need not be <tt>static</tt>.
:* Whether passed in XML or JSON, parameters passed to the method in the <tt><execClass></tt> segment must consist of a flat structure, as in the example that follows. (The structure is converted to a HashMap, so it cannot contain any complex elements or attributes.)


:* Signatures:
:* Signatures:
Line 27: Line 28:
         <clazz>fully.qualified.JavaClassName</clazz>
         <clazz>fully.qualified.JavaClassName</clazz>
         <method>methodName</method>
         <method>methodName</method>
         ...optional list of parameter tags, like these:...
         ...optional list of additional parameter tags like these...
         <firstName>Peter</firstName>
         <firstName>Peter</firstName>
         <lastName>Smith</lastname>
         <lastName>Smith</lastname>
Line 33: Line 34:
</platform>
</platform>
</syntaxhighlight>
</syntaxhighlight>
 
:(Note that the items in the <tt><execClass></tt> tag form a flat structure.)
   
   
;Response:
;Response:

Revision as of 01:24, 21 January 2014


Provides the ability to execute a class method using the REST API.

Considerations
  • A Class must be defined. (The exec resource invokes a method in the class.)
  • An instance of the class is created automatically, so the method need not be static.
  • Whether passed in XML or JSON, parameters passed to the method in the <execClass> segment must consist of a flat structure, as in the example that follows. (The structure is converted to a HashMap, so it cannot contain any complex elements or attributes.)
  • Signatures:
    • The method must be public
    • The method can either take no arguments: public methodName()
    • Or it take arguments passed in a Map: public methodName(Map params)
      (Parameters passed in the Request are wrapped in a Map, and passed to the method.)
  • Return Types:
    • A method may return void.
    • If the return type is a Map, it can be used to return key-value pairs.
    • Otherwise the return value is automatically converted to a string using result.toString()
Method
POST
URI
https://{yourDomain}/networking/rest/class/operation/exec
Request
<syntaxhighlight lang="xml" enclose="div">

<platform>

   <execClass>
       <clazz>fully.qualified.JavaClassName</clazz>
       <method>methodName</method>
       ...optional list of additional parameter tags like these...
       <firstName>Peter</firstName>
       <lastName>Smith</lastname>
   </execClass>

</platform> </syntaxhighlight>

(Note that the items in the <execClass> tag form a flat structure.)
Response
The output structure is the same, except that the key/value pairs are those returned by the class method, when the return value is a Map. When the return value is converted to a string, the response looks like this:
<syntaxhighlight lang="xml" enclose="div">

<platform>

   <execClass>
       <result>...result-string here...</result>
   </execClass>
   <message>
       0
       <description>Success</description>
   </message>

</platform> </syntaxhighlight>

Known issue
Null return values are not handled at this time.