English

How To: Use the Java Connector to Send Automated Requests to ArcIMS

Summary

The Java programming language provides a number of techniques for automating a procedure or task over a period of time. Coupled with the ArcIMS Java Connector, a cross-platform solution can be developed to automatically send ArcXML requests to and process responses from ArcIMS services. The following document provides some high-level steps to consider when developing a solution as well as a downloadable example. The sample, AimsPinger.zip, includes comprehensive documentation (readme.html) and source code.

Procedure

  1. Keep application properties in a separate text file.

    This enables the user of the application to modify site-specific properties without recompiling the application.

    Code:
    InputStream in = this.getClass().getResourceAsStream("/aimspinger.properties");
    java.util.Properties prop = new java.util.Properties();
    prop.load(in);
    in.close();
    hostname = prop.getProperty("AppServerHostname");


  2. Determine the method used to automate the task of sending an ArcXML request.

    Java includes a number of methods for automating a task. The general guideline is as follows:

    If the task will be completed as a later time, or periodically use java.util.TimerTask and java.util.Timer.
    If the task will take a long time or may block another thread, use java.lang.Thread.

    In this case, TimerTask and Timer should suffice. The TimerTask's task queue is managed by the Java runtime so one task will not run while another is executing. To use:

    a) Create a class that extends from TimerTask.

    Code:
    public class AimsPinger extends java.util.TimerTask {


    b) Override the static void run() method to include the custom task you want to execute.

    Code:
    public void run() {


    c) From the main() method, create a new java.util.Timer and schedule the Timer to execute the class that extends TimerTask at a defined rate.

    Code:
    timer = new java.util.Timer();
    timer.scheduleAtFixedRate(new AimsPinger(), 10000, (interval * 60) * 1000);


  3. Use the Java Connector to generate ArcXML requests and process responses.

    The Java Connector provides a relatively rich API for communicating with ArcIMS. Use its classes, properties and methods to send requests and evaluate responses from ArcIMS. If the Java Connector does not expose specific methods for communicating with ArcIMS service functionality, then another XML parsing mechanism must be used. Java contains two predefined methods for parsing XML documents, SAX and DOM. While either can be used, the DOM may be the easiest. Here is an example of sending an ArcXML request to an ArcIMS feature service through the Java Connector. The DOM is packaged with the Java Connector and used to retrieve the number of features in the FEATURES response:

    Code:
    String axlResponse = map.sendArcXML(axlRequest,com.esri.aims.mtier.model.map.Map.GET_IMAGE);
    com.esri.jx.xml.parsers.DocumentBuilderFactory factory = com.esri.jx.xml.parsers.DocumentBuilderFactory.newInstance();
    com.esri.jx.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
    com.esri.w3c.dom.Document document = builder.parse(new com.esri.xml.sax.InputSource(new StringReader(axlResponse)));
    com.esri.w3c.dom.Node resultNode = document.getElementsByTagName("FEATURECOUNT").item(0);
    com.esri.w3c.dom.NamedNodeMap nnm = resultNode.getAttributes();
    String count = nnm.getNamedItem("count").getNodeValue();


  4. Enable logging to a text file to troubleshoot problems when they occur.

    Retrieving information on the success or failure of a request from the client application may assist in determining when or if a problem occurs. You can use the Java's java.util.logging.Logger class or create your own. Below is a simple example of how to log information to a file on disk:

    Code:
    String logfilename = "C:/temp/out.log";
    File logfile = new File(logfilename);
    BufferedWriter out = new BufferedWriter(new FileWriter(logfile));
    DateFormat df = new SimpleDateFormat("MM/dd/yy hh:mm:ss aa");
    String time = df.format(new Date());
    out.write("**** Application Started **** \n");
    out.newLine();
    out.flush();

Related Information