Difference between revisions of "REST API:exec Resource"

From LongJump Support Wiki
imported>Aeric
 
imported>Aeric
Line 9: Line 9:
:* Signatures:
:* Signatures:
:** The method must be <tt>public</tt>
:** The method must be <tt>public</tt>
:** The method can take no arguments: <tt>public methodName()</tt>
:** The method can either take no arguments: <tt>public methodName()</tt>
:** Otherwise, arguments should be passed in a Map: <tt>public methodName(Map params)</tt>
:** Or it take arguments passed in a Map: <tt>public methodName(Map params)</tt><br>(Parameters passed in the Request are wrapped in a Map, and passed to the method.)


:* Return Types:
:* Return Types:

Revision as of 23:13, 14 February 2012


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.
  • 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://{domain}/networking/rest/class/operation/exec
Request
<platform>
    <execClass>
        <clazz>fully.qualified.JavaClassName</clazz>
        <method>methodName</method>
        ...optional list of parameter tags, like these:...
        <firstName>Peter</firstName>
        <lastName>Smith</lastname>
    </execClass>
</platform>


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:
<platform>
    <execClass>
        <result>...result-string here...</result>
    </execClass>
    <message>
        <code>0</code>
        <description>Success</description>
    </message>
</platform>
Known issue
Null return values are not handled at this time.