Previous Topic

Next Topic

Book Contents

Book Index

Example: emapiXMLgenerator classes to track a job in Control-M

The following code snippet uses the emapiXMLgenerator classes to track a job in Control-M. For simplicity, exception handling is omitted.

NOTE: The full working program can be found on the DVD.

import java.util.Enumeration;

import java.io.IOException;

import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;

import com.bmc.ctm.bpi.tester.emapiXMLgenerator.*;

// Produce the Job Tracking XML request to track the job in Control-M

JobTrackingRequest trackRequest = new JobTrackingRequest();

trackRequest.addJob( m_dataCenter, orderID );

String trackRequestXML = trackRequest.getRequestXmlString();

// Loop until the job is finished

String jobStatus = null;

do

{

// Sleep for a while

Thread.sleep(1000);

...

Send the trackRequestXML string to the message queue

...

Receive the EMResponseXML string from the response queue

...

// Analyze EM's response to the Job Tracking request

String jobStatus = null;

Response myResponse = new Response( EMResponseXML );

System.out.println( "EM response to Job Track request:" );

// Check the return status of our request

String respStatus = myResponse.getStatus();

System.out.println( " STATUS = " + respStatus );

if (respStatus.equalsIgnoreCase( Response.GENERAL_STATUS_OK ))

{

// If our request was successful, retrieve the details of the response

Enumeration respData = myResponse.getResponseData();

while (respData.hasMoreElements())

{

JobTrackingResponseData trackData = (JobTrackingResponseData)

respData.nextElement();

if (trackData.isStatusOk())

{

jobStatus = trackData.getJobStatus();

System.out.println( " JOBSTATUS = " + jobStatus );

System.out.println( " JOBSTATE = " + trackData.getJobState() );

System.out.println( " CONTROLM = " + trackData.getControlM() );

}

else

{

System.out.println( " MAJOR = " + trackData.getMajorCode() );

System.out.println( " MINOR = " + trackData.getMinorCode() );

System.out.println( " SEVERITY = " + trackData.getSeverity() );

System.out.println( " MESSAGE = " + trackData.getErrorMessage()

);

}

}

}

// If the return status is not OK, print return codes and error message

else if (respStatus.equalsIgnoreCase( Response.GENERAL_STATUS_ERROR ))

{

System.out.println (" MAJOR = " + myResponse.getMajorCode());

System.out.println (" MINOR = " + myResponse.getMinorCode());

System.out.println (" SEVERITY = " + myResponse.getSeverity());

System.out.println (" MESSAGE = " + myResponse.getMessage());

}

else if (respStatus.equalsIgnoreCase( Response.SYSTEM_ERROR ))

{

System.out.println (" DESCRIPTION = " +

myResponse.getSystemErrorDescription());

System.out.println (" EXCEPTION = " +

myResponse.getSystemExceptionText());

System.out.println (" STACKTRACE = " +

myResponse.getSystemExceptionStackTrace());

}

else

{

System.out.println (" MESSAGE = " + myResponse.getMessage());

}

if (jobStatus == null)

{

break;

}

}

while (!jobStatus.startsWith("Ended"));

Parent Topic

Control-M Messaging API administration