Calling the Engine From a Java Program

The server normally accepts input from an external port, such as FTP or IBM MQ Series. Applications can, however, use the complete services of the server within their own programs, such as a servlet or EJB. The server is instantiated as a class that offers methods for passing documents and controlling operation.

To use the server within a Java program, you must first create an instance of the server itself. This is an instance of a "local master," a channel for documents that operates from a local source. To create such a master, use either constructor:

XDLclMaster(String[] argv)

passing in token=value pairs as for an ADD command line starting a standard listener, or

XDLclMaster(Hashtable h)

passing in a hash table of the token/value pairs.

The following diagram shows how your applications interact with iWay Service Manager XDLclMaster. Your program creates an instance of the XDLclMaster, and then uses that to pass documents through the engine. In iWay Service Manager, the document passes through the various stages of analysis and execution and the resultant document is returned to the caller.

Once the object has been created, its methods can be used. You should call setMasterName() to give traces a differentiable name. Once this is done, you can call the xml() method, passing a string representing a document (it need not be in XML), and receiving a string representing a result.

Your application might contain the following fragment of code:

String[] args = new String[2]; // this holds configuration properties
 args[0] = "dictionary=c:\\dictionary.xml";  // where is the dictionary?
 args[1] = "properties="+properties;   // properties file location was passed in
 XDLclMaster xdlm = null;
 try
 {
     xdlm = new XDLclMaster(args); // construct an eBI/X service
     if (isDebug)  // if my ap wants debug...
     {
         xdlm.setDebug(true);  // then set the debug mode in the service
     }
 }
 catch (Exception e)
 {
     logger.debug("Error creating XML service: " + e.toString());
     return;
 }
 String inXml=parmIn; // assume a parameter held the XML to process
 String out;
 out = xdlm.xml(inXml); // process the XML, if error it is returned as a document

In addition, you might wish to pass the dictionary in as a string:

String ds = "<edaxml><listener>fred\n<active>true</active<dsn>SAPDSN</dsn><agent>
XDSapIfrAgent(dsn=SAPDSN)</agent></listener><system><properties><JDBC><SAPDSN>
<prop name='driver'>ibi.sap.jdbc.SapDriver</prop><prop name='url'>jdbc:ecb:Sap
</prop><prop name='traceOn'>true</prop><prop name='traceToFile'>false</prop>
<prop name='hostName'>isdhp</prop><prop name='systemNumber'>03</prop>
<prop name='clientNumber'>800</prop><prop name='language'>EN</prop>
<prop name='user'>omni</prop><prop name='password'>ENCR(3183322631833225)</prop>
</SAPDSN></JDBC></properties><license><item>external</item></license><define><agent>
<name value='XDCopyAgent'>COPY</name><name value='XDJdbcAgent'>JDBC</name>
<name value='com.ibi.agents.XDSapIfrAgent'>IFR</name></agent><preemit>
<name value='IDOCPreEmit'>IDOC</name></preemit></define></system></edaxml>";
        XDLclMaster xdlm = null;
        Hashtable h = new Hashtable();
        Properties p = new Properties();
        p.setProperty("JLINK.LOCALSRV.PROTOCOL","tcp");
        p.setProperty("JLINK.LOCALSRV.HOST","edardb"); 
        p.setProperty("JLINK.LOCALSRV.SERVICE","8100");
        p.setProperty("JLINK.LOCALSRV.PORT","8100");
        p.setProperty("JLINK.TRACE","1234");
        p.setProperty("JLINK.TRACEFILE","System.out");
        h.put("properties_object",p);
        h.put("dictionary",ds);
        try
        {
            xdlm = new com.ibi.edaqm.XDLclMaster(h,true,null,false,"fred"); 
        }
        catch (Exception e)
        {
            logger.debug("Error creating local service: " + e.toString());
            return;
        }
        // fix the password
        String inXml="<eda><request reqtag=\"001\"><connection cnctag=\"CNC1\">
<dsn>LOCALSRV</dsn><user>edardb</user><password>000009</password><sql>
<query>select car, country, model, seats from car</query><maxrows>10</maxrows>
</sql></connection></request></eda>";
        String outs = xdlm.xml(inXml); // process XML, error is returned as document
        logger.debug(outs);

A complete description of these methods along with sample code is provided in the Javadoc under XDLclMaster.


iWay Software