XML Test Drivers
Revised: July 2010, OL-23043-01
This appendix describes the XML test drivers.
XML Request Batch File
The following example of an XML/CORBA interface test driver executes an XML request batch file built as a CLI script. This allows compatibility with older CLI scripts used to provision the system.
package com.sswitch.oam.drv;
import org.apache.ecs.xml.*;
import org.apache.xml.serialize.*;
// BTS Interface Code objects...
import com.sswitch.oam.cad.*;
import com.sswitch.oam.xml.*;
import com.sswitch.oam.util.*;
import com.sswitch.oam.ccc.*;
* Copyright (c) 2002, 2003 by Cisco Systems, Inc.
* --Test driver for the XML/CORBA interface...
* This test driver executes a batch file built as a CLI script as XML
* requests. This allows compatibility with the older CLI scripts used to
* provision the system. Note that this example can be built with the
* provided tool "oo-cc" this simple script creates the correct CLASSPATH
* and invokes the compiler with the correct options. Also, the "oo-idl"
* tool can be used to generate the correct IDL output.
* @author A. J. Blanchard
private String [] objArgs;
private CorbaXmlIntf objBts;
private RandomAccessFile objFileHandle;
* Generic Constructor for the test driver.
protected XmlBatch(String[] args)
objBts = new CorbaXmlIntf(args);
* This is the main method for the application.
public static void main(String[] args)
// Verify that the argument match what is expected...
// oo-run XmlRequest <CLI Request File> \
// -ORBopenorb.config="./OpenORB.xml"
System.out.println("\nStart program as: oo-run XmlRequest <XML Request File>
-ORBopenorb.config=\"./OpenORB.xml\"\n");
XmlBatch me = new XmlBatch(args);
* This is the primary execution method for the object. It performs the
* actual request and calls for the print of the reply.
// Log into the target machine with generic optiuser
System.out.println("BTS10200 Login successful...");
System.out.println("Exception in login = " + e);
// Read in the file and send request...
CommandParser parser = new CommandParser();
String cmd = readCLI(); // Fetch the request file....
if(cmd.startsWith("#") || cmd.length()==0)
// Issue request to BTS 10200
reply = objBts.request(parser.toXML(cmd));
System.out.println("RETURN VALUE: ");
parser.prettyPrint(reply);
catch (CadExceptions ce) {
System.out.println("CIS Command Exception: CODE="+ce.error_code +
System.out.println("Batch Command Exception = " + e);
* Open the input file for reading. This allows the read method to suck
* a line at a time of the CLI style input.
objFile=new File(objArgs[1]);
objFileHandle=new RandomAccessFile(objFile,"r");
// In the event of an error. just bail out of the program
System.out.println("Error in processing file:\n"+e.toString());
* This is the method that closes and clean up after a file has been
protected void closeCLI() throws java.io.IOException
* Read in the file provided as the request. Just exit on errors. Don't
* worry about throwing an error exception.
protected String readCLI()
if((data = objFileHandle.readLine())!=null)
System.out.println("Unable to read "+objFile.toString()+
" with error:\n"+e.toString());
// May return a valid string or a NULL object...
//=====================================================================
// Tools and utilities...
//=====================================================================
CLI to CORBA XML Transaction
The following example of a test driver executes a normal CLI command but processes it as a CORBA XML transaction.
package com.sswitch.oam.drv;
import org.apache.ecs.xml.*;
import org.apache.xml.serialize.*;
// BTS Utility Code objects...
import com.sswitch.oam.cad.*;
import com.sswitch.oam.xml.*;
import com.sswitch.oam.util.*;
import com.sswitch.oam.ccc.*;
* Copyright (c) 2002, 2003 by Cisco Systems, Inc.
* --Test driver for the XML/CORBA interface...
* This test driver executes a normal CLI command and processes the request
* as a CORBA XML transaction. The reply is then displayed. I am no as
* concerned with complex data show(s) as with the ability to issue
* provisioning commands. Note that this exmaple can be built with the
* provided tool "oo-cc" this simple script creates the correct CLASSPATH
* and invokes the compiler with the correct options. Also, the "oo-idl"
* tool can be used to generate the correct IDL output.
* @author A. J. Blanchard
private String [] objArgs;
private CorbaXmlIntf objBts;
* Generic Constructor for the test driver.
protected XmlCli(String[] args)
// Initialize the BTS ORB interface object.
objBts = new CorbaXmlIntf(args);
* This is the main method for the application.
public static void main(String[] args)
// Verify that the argument match what is expected...
// oo-run XmlCli -ORBopenorb.config="./OpenORB.xml"
System.out.println("\nStart program as: oo-run XmlCli
-ORBopenorb.config=\"./OpenORB.xml\" \n");
XmlCli me = new XmlCli(args);
* This is the primary execution method for the object. It performs the
* actual request and calls for the print of the reply.
// Log into the target machine with generic optiuser
System.out.println("BTS10200 Login successful...");
System.out.println("Exception in login = " + e);
// Read in the file and send request...
openCLI(); // Put out the prompt...
CommandParser parser = new CommandParser();
String cmd = readCLI().trim(); // Fetch the request file...
// Issue request to BTS 10200
reply = objBts.request(parser.toXML(cmd));
System.out.println("RETURN VALUE: ");
parser.prettyPrint(reply);
catch (CadExceptions ce) {
System.out.println("CIS Command Exception: CODE="+ce.error_code +
System.out.println("CIS Command Exception: \n"+e.toString());
* Open the input file for reading. This allows the read method to suck
* a line at a time of the CLI style input.
System.out.print("CORBA-CLI> ");
* This is the method that closes and clean up after a file has been
protected void closeCLI() throws java.io.IOException
System.out.println("\n Bye...");
* Read in the file provided as the request. Just exit on errors. Don't
* worry about throwing an error exception.
protected String readCLI() throws java.io.IOException
byte [] buf= new byte[256];
if(temp==10) // <ENTER Key>
//=====================================================================
// Tools and utilities...
//=====================================================================