An Unified Resource Locator (URL) interface to AMICO. It runs a Web server, enabling other modules to use AMICO commands using HTTP GET request, and in also enables definition of URL adapters, that map variables from the communicator to URLs that are then opened, returned content can optionally be placed in a variable. In this way also REST Web services could be called.
NOTE: If you want to open a connection to a resource that returns XML or HTML response and you want to process the response, for example, to extract simpler data from the content based on XPath expressions, you can use AMICO XML Processor.
java -jar %AMICO_HOME%/bin/amico-url.jar [<conf-url>]
To execute AMICO command using URL interface, simply type in your Web browser:
http://localhost:3380/amico?command=COMMAND
3380 is a default port for AMICO URL interface Web server, and it can be changed in the configuration file. Command can be any of the AMICO TCP protocol commands. For example:
http://localhost:3380/amico?command=UPDATE age 32
http://localhost:3380/amico?command=DELETE age
http://localhost:3380/amico?command=GET age
See end of this document for an example of how to use this interface from programs.
A main configuration file:
This is a minimal configuration file that uses default
parameters for missing attributes. --------------------------------------------- <?xml version="1.0"
encoding="UTF-8"?> |
This is a full configuration file that overrides default parameters. --------------------------------------------- <?xml version="1.0"
encoding="UTF-8"?> <command>UPDATE
last-loaded-module URL</command>
|
A configuration file for URL adapter variables (linked from a main
configuration file):
<?xml version="1.0"
encoding="UTF-8"?>
<url trigger-variables="web-param" update-variable="web-result">
<!-- When variable "web-param"
change, it will call Google URL with parameter from this variable http://www.google.nl/search?hl=nl&q=<%=web-param%> </url> <url trigger-variables="sound-volume">
<!-- Used for controlling
VLC Player. When "sound-volume"
changes, http://localhost:8080/?control=volume&value=<%=sound-volume%>
</url> |
This is simple Java program that uses java.net.URL class to update and read AMICO variables.
import java.net.*;
import java.io.*; public class URLTest { public static void main(String[] args) throws Exception { String command1 = URLEncoded.encode( "UPDATE variable1 test", "UTF-8" ); String command2 = URLEncoded.encode( "GET variable1", "UTF-8" );
new URL( "http://localhost:3380/amico?command=" + command1).openStream();
URL communicator = new URL( "http://localhost:3380/amico?command=" + command2); BufferedReader in =
new BufferedReader( new InputStreamReader(
communicator .openStream())); String inputLine; while ((inputLine = in.readLine()) != null)
System.out.println( inputLine ); } } } |
The following example illustrates how Asynchronous JavaScript and XML (AJAX) freamework can be used with AMICO using AMICO URL interface (click here to open this HTML page). Note: to run this example your browser have to access allow script code to access AMICO on the localhost. This may require changing some of security settings. On Internet Explorer this usually does not cause problems. With Firefox, you may need to install the following Greasemonkey script (click here for it, also available here).
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en"> <head> <script> var xmlHttp var readVariable
}
function amicoReadLoop(variable,elementId) { amicoReadLoop(variable,elementId,1000); } function amicoReadLoop(variable,elementId,cycleTime) { readVariable = getAmico( variable ); if (readVariable != document.getElementById(elementId).value) { document.getElementById(elementId).value = readVariable; } setTimeout("amicoReadLoop('" + variable + "', '" + elementId + "');",cycleTime); }
} <input type="text" id="variable_value" size="20"> <input type="button" value="Update" onclick="updateAmico(variable_name.value, variable_value.value)"> <input type="button" value="Get" onclick="variable_value.value=getAmico(variable_name.value)">
<input
type="button" value="Get Loop" onclick="amicoReadLoop(variable_name.value,
'variable_value')"> |