Home   Documentation   Demonstrations   Download

AMICO: Documentation / AMICO Modules / XML-RPC Interface

 

An XML-RPC interface to AMICO. It runs and XML-RPC server, enabling other modules to update and read variables, and in also enables definition of XML-RPC adapters, that map variables from the communicator to method calls on other XML-RPC servers (see Configuration section in this document for details).

How To Run

     java -jar %AMICO_HOME%/bin/amico-xmlrpc.jar [<conf-url>]

 


XML-RPC Methods Defined

 

Return type Method name Argument(s) Description
string updateVariable string variableName,

string variableValue

Updates the variable. If the variable does not exist, it will be added. Always returns an empty string*.
string deleteVariable string variableName Deletes the variable. If the variable does not exists, nothing happens. Always returns an empty string*.
string loadTransformation string transformationURL Loads XSLT transformation for derivation of new variables.
string removeTransformation string transformationURL Removes XSLT transformation for derivation of new variables.
string populateTemplate string template On request population of templates. Values inside <%=variable-name%> will be replaced with the value of the variable. For example template "User age = <%=age%>",  with variable age updated to 27, will be populated to "User age 27".
string get string listOfVariables Returns comma separated list of values for given variable names.
string getXml string listOfVariables Returns comma separated, XML encoded list of values for given variable names. For example "<varaibles><variable name='age'>26</variable></variables>"
string getAllXml string listOfVariables Returns comma separated, XML encoded list of values for all variables.


* AS XML-RPC does not support function with void return type, updateVariable, deleteVariable, loadTransformation, removeTransformation are defined with as string type, but they always return an empty string.


Configuration files


A main configuration file:
 

This is a minimal configuration file that uses default parameters for missing attributes.
Use this file if you want to use default settings.

---------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xml-rpc>

    <xml-rpc-adapter url="file:conf/xmlrpc/concept-net-adapter.xml"/>
    <xml-rpc-adapter url="file:conf/xmlrpc/ambulant-player-adapter.xml"/>
    <xml-rpc-adapter url="file:conf/xmlrpc/test-math.xml"/>
</xml-rpc>

This is a full configuration file that overrides default parameters.

---------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xml-rpc server-port="4310">   <!-- "server-port" is a port of XML RPC web server-->

    <communicator host="localhost" port="3320">
        <!-- Basic parameter for establishing connection with communicator. Module uses TCP connection.
             <command> element define a list of commands that will be sent to communicator
             each time a module establish a connection (see AMICO TCP protocol for details on commands)
        -->

        <command>UPDATE last-loaded-module XML-RPC</command>
        <command>ONUNLOAD DELETE last-loaded-module</command>
    </communicator>


    <xml-rpc-adapter url="file:conf/xmlrpc/concept-net-adapter.xml"/>
    <xml-rpc-adapter url="file:conf/xmlrpc/ambulant-player-adapter.xml"/>
    <xml-rpc-adapter url="file:conf/xmlrpc/test-math.xml"/>
</xml-rpc>

 

A configuration file for XML-RPC adapter variables (linked from a main configuration file):
 

<?xml version="1.0" encoding="UTF-8"?>

<xml-rpc-adapter default-server="http://localhost:8000">
    <method-call server="" method="guess_mood" trigger-variables="text-context">

        <!-- When a variable text-context changes,

              call a method guess_mood on XML-RPC server http://localhost:8000
              (server="", that means that we use default server)

              with one parameter (value of variable text-context)
              and update variable text-context-mood with the result of this method call
        -->

        <parameter param-type="variable" value="text-context"/>
        <result update-variable="text-context-mood"/>
    </method-call>


    <method-call server="" method="guess_mood" trigger-variables="say-something">
        <parameter param-type="template" value="&lt%=say-something%&gt;"/>
        <result update-variable="say-something-mood"/>
    </method-call>


    <method-call server="" method="guess_concept" trigger-variables="text-context">
        <parameter param-type="variable" value="text-context"/>
        <result update-variable="text-context-concept"/>
    </method-call>

 

    <method-call server="http://localhost:3096" method="test.&lt;%=math%&gt;" trigger-variables="a,b,math">
        <parameter param-type="variable" xml-rpc-type="int" value="a"/>
        <parameter param-type="variable" xml-rpc-type="int" value="b"/>
        <result update-variable="c"/>
    </method-call>

</xml-rpc-adapter>

 

Example of using XML-RPC from other programs

 

This is simple Java program that call updateVariable method using Apache Java XML-RPC library.

 

import java.util.Vector;
import org.apache.xmlrpc.*;

 

public class XmlRpcTest {   

    public static void main( String args[] ) {
        try {
            XmlRpcClient xmlrpc = new XmlRpcClient ( "http://localhost:4310/RPC2" );

            Vector params = new Vector ();
            params.addElement( "age" );

            params.addElement( "27" );

            xmlrpc.execute( "updateVariable", params );
        } catch (Exception e) {

            e.printStackTrace();
        }

    }

}

 

Validation Logos