A number of support libraries have been provided to simplify third-party ESA development. Currently, the only libraries available are for the Java programming language. To develop an ESA in Java, all you need do is to develop a class implementing a single ExternalSystemAdapter
interface and write about 10 lines to construct your ESA using either STDIO or HTTP transport.
The ESA example package contains a Sample ESA class, com.supportwizard.sync.sampleesa.SampleEsa
, and a number of other classes which form the ESA Java Support Library. The library API is very simple and only contains two methods for the com.supportwizard.sync.remoteesa.EsaRunner
class, both of which receive an ESA implementation as a parameter:
Method | Description |
---|---|
| Runs command line ESA. This method starts by reading standard input, converts received XML messages into ESA calls, dispatches them and prints the XML-ized responses to standard output. This method exits after processing ExternalSystemAdapter.release() call. Normally, the command line ESA application should terminate after this method exits. |
| Runs HTTPs ESA. This method connects to an host, waits for sync message, processes it by calling ESA methods and posts back the reply. This method exits after processing ExternalSystemAdapter.release() call or upon a timeout. Normally, HTTPs ESA should re-invoke it in a cycle, probably with some delay. |
Please see JavaExecutableEsa on using EsaRunner.
Usually, you will not need to use any other parts of the Java support library directly. However, if you plan to implement an ESA using a programming language other than Java, or plan to change the way XML messages are passed to and from or the way they are processed, such as by implementing some kind of internal queuing, you may find this useful to explore.
Major classes of interest are:
Class | Description |
---|---|
JavaExecutableEsa | CL ESA 'main' class. To make a minimal change, it is sufficient to replace the line:
with
to get a fully working command line ESA. |
Transport:
| These classes are responsible for the XML message flow. StreamTransport passes messages over STDIO streams HttpXmlEsaTransport passes messages over HTTP(S) |
| These classes encapsulate particular XML messages. Note: there is a Message.dispatch method, which invokes an ESA method, corresponding to the message. |
| These classes handle XML message generation and parsing. |
| These classes translate ESA and HelperApi calls into XML messages. |
EsaReceiver | This class takes messages from Transport and invokes ESA methods according to the message received. |
The library classes are supplied in the source form. You are free to reuse them for any ESA-related development.
The Java ESA Example following contains a number or classes, which can be reused by any Java ESA. These classes are:
ExternalSystemAdapter
interface. Your ESA implementation must include a class, implementing this interface. In fact, this is the only piece of code you must write to get a fully working ESA, based on the example code.com.supportwizard.sync.interfaces.transport.xml
and com.supportwizard.sync.interfaces.transport.xml.jaxb
packages, notably JaxbParser and JaxbSerializer, parsing and generating XML.StreamTransport
class, implementing STDIO TransportHttpXmlEsaTransport
class, implementing HTTP(s) TransportExternalSystemAdapter
when a message arrives, and marshaling the result back to the message exchange stream.The only things needed to build an ESA using STDIO transport are:
ExternalSystemAdapter
interfacemake.bat
, you will have to add your package(s) to the Java compiler (javac) call arguments.You may reuse any classes of the example and handle messages in some other manner, if you choose, but we recommend the method above to facilitate incorporating future changes and fixes.
The following example is a command-line ESA, with an alternative transport class to make an HTTPs ESA, synchronizable with a set of files in some file system directory. For the sake of clarity, some details of XML parsing, logging and message-to-method dispatching are omitted here. The full source files are available in sync-example.zip.
The External System that this example fits holds files in the Java properties file format in either plain or XML properties.
"Plain" properties: #comment fieldA=value A fieldB=value B "XML" properties: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>comment</comment> <entry key=" fieldA"> value A</entry> <entry key=" fieldB"> value B </entry> </properties> |
The particular type is to be defined by the ESA Parameter format. The set of fields is defined by the ESA Parameter fields.
To test the ESA compilation...
sync-example.zip
to some directory - $ESA_DIR$
.$ESA_DIR$/out
directory and build "fileesa.jar" JAR file.You should get an output such as:
E:\sync-example>run.bat < in.txt <sync> <result>2009-06-16T19:58:49.062+00:00</result> </sync> <sync> <result></result> </sync> |
If you see this, you have compiled the example successfully.
Two classes are central to this example: FileDirectoryEsa and JavaExecutableEsa. Other classes in the example can be treated as a Java support library. You don't have to modify them and may use them as is in your own ESA.
To use this ESA in Sync configuration...
run.bat
file to read @cd $ESA_DIR$
, where $ESA_DIR$
is the directory where the example is unzipped.cmd /c $ESA_DIR$\run.bat
in the input box labelled Command Line.This is an interface which every Java ESA should implement:
|
This is a helper class and it is not mandatory for a Java ESA. Instead, a Java ESA may implement the ExternalSystemAdapter
interface directly. However, most simple ESAs will benefit from using it as a sub-class:
|
FileDirectoryEsa
is an ESA implementation class. Its methods are called on receiving corresponding messages and it may call the Helper Api to make a call back to the server.
|
The FileDataGate
interface referenced in FileDirectoryEsa
is a pure implementation class. The example ESA uses the FileDataGate
interface implementation to access plain text and XML property files. This is a FileDirectoryEsa
implementation specific interface, not a sync interface.
|
JavaExecutableEsa
is the main class of the command-line application. You may modify line 28 - new StreamTransport(true, System.in, System.out)
- replacing it with new HttpXmlEsaTransport(externalSystemID, ewHost)
to transform the example ESA into an independent ESA, connecting over HTTP. You will have to supply or hard-code ExternalSystemID
and hostname:port.
This class does several primary things:
ESA
class instance is constructed in line 25StreamTransport
class instance handling STDIO transportation is constructed in line 28.EsaReceiver
is constructed and run in lines 27, 30. EsaReceiver
glues together the ESA implementation class and transport.To convert an example into full-featured ESA, you only have to provide an implementation of the ExternalSystemAdapter
interface and modify lines 25 and probably 29 of JavaExecutableEsa.
Other sources, including XML parsing/generating, message dispatching, etc, are available as a reference within example.jar
.
|
Related articles |