InfoCenter Home >
6: Administer applications >
6.6: Tools and resources quick reference >
6.6.0: About user assistance >
6.6.0.2: Command line administration >
6.6.0.2.2: WebSphere Control Program (wscp) >
6.6.0.2.2.7: Using the wscpCommand interface

6.6.0.2.2.7: Using the wscpCommand interface

Use the com.ibm.ejs.sm.ejscp.wscpcommand.WscpCommand interface to embed wscp operations in Java applications. This enables applications to evaluate wscp operations without repeated startup costs. The interface is linked through the product_installation_root/lib/wscp.jar file. The typical use of this class is to instantiate it once, and reuse the object to successively poll the WebSphere Administrative Server.


Constructors

WscpCommand(String node, String port)

where:

  • node--The name of the WebSphere Application Server node on which the wscp operation is executed (such as localhost).

  • port--The port number of the administrative server.
WscpCommand()

The default values for this constructor are localhost for node and 900 for port (the default port number of the administrative server).


Public methods

WscpResult evalCommand(String command)

This method evaluates a wscp operation and returns the results. Use the same syntax as you do for interactive or scripted wscp operations. Using abbreviated command names is not recommended.

The results of the evalCommand method are encoded in a com.ibm.ejs.sm.ejscp.wscpcommand.WscpResult object. The following methods on this object can be used to evaluate the returned value:

  • toString-- Returns a string representation of the results of the wscp operation.
    Note:
    The WscpCommand interface has no way of knowing the format of the expected output from a wscp operation. When the return format is not an attribute-value pair or list, use the toString method to evaluate the output. The application programmer must then write code to parse the output.

  • success-- Returns a boolean value indicating whether the wscp operation was successful.

  • listToVector-- If the expected result of the wscp operation is a list, use this method to return a vector containing the list elements.

  • attribPairsToVector-- If the expected result of the wscp operation is a list of attribute-value pairs, use this method to return a vector containing the list. Each element of the vector is an attribute-value pair.

  • attribPairsToHashTable-- If the expected result of thewscp operation is a set of attribute-value pairs, use this method to return a hash table containing the values keyed on the attributes.
String getErrorInfo()

This method returns the status of an evalCommand method whose results are returned in a WscpResult object.

  • If the wscp operation specified in the evalCommand executed successfully, the getErrorInfo method returns an empty string.

  • If the wscp operation did not execute successfully, the getErrorInfo method returns the exception information that was received from wscp.

The following is an example of how to use the evalCommand and getErrorInfo methods.

String cmd = "ApplicationServer list";
WscpResult results = wscpCommand.evalCommand(cmd);
if (!results.success()) {
System.out.println("command failed; exception information: " + results.getErrorInfo());
}

Utility class

The WscpCommand interface contains a utility class, WscpQualifiedName, that allows the manipulation of fully qualfied wscp object names. The constructor is as follows:

WscpQualifiedName(fullyqualifiedname)

where fullyqualifiedname is the fully-qualified wscp name of an object.

The methods for this class are as follows:

  • getName(level)--Gets the object name at the specified containment level.

  • getObject(level)--Gets the object type at the specified containment level.

  • toString--Returns a string representation of the object name.

  • numberOfLevels--Returns the number of containment levels.

The WscpQualifiedName class contains the following constants, which define the containment levels at which various components are named.

  • ENTERPRISE_APPLICATION

  • DATASOURCE

  • JDBC_DRIVER

  • NODE

  • SERVER_GROUP

  • VIRTUAL_HOST

  • APPLICATION_SERVER

  • GENERIC_SERVER

  • WEB_RESOURCE

  • WEB_APPLICATION

  • MODULE

  • JMS_PROVIDER

  • JMS_CONNECTION_FACTORY

  • JMS_LISTENER

  • J2C_RESOURCE_FACTORY

  • J2C_CONNECTOR

  • MAIL_SESSION

  • URL

  • URL_PROVIDER

An example of how this class is used is as follows:

String name = "{/Node:MyNode/ApplicationServer:MyAppServer/}"
WscpQualfiedName qName = new WscpQualifiedName(name);
qName.numberOfLevels() returns 2
qName.getObject(2) returns "ApplicationServer"
qName.getName(2) returns "MyAppServer"
qName.getName(WscpQualifiedName.APPLICATION_SERVER)
returns "MyAppServer"

Security

The wscp command-line tool runs with security enabled because it is started by using SAS from the command line, as you can see in the wscp.bat (Windows) and wscp.sh (Unix) files. However, the WscpCommand interface cannot guarantee support for a server with security enabled because it is used in client programs. If the Java program is started using SAS, WscpCommand methods execute with security enabled.

Go to previous article: 6.6.0.2.2.6: Migrating wscp scripts from version 3.5.x to version 4.0 Go to next article: Overview of editing property files by hand

 

 
Go to previous article: 6.6.0.2.2.6: Migrating wscp scripts from version 3.5.x to version 4.0 Go to next article: Overview of editing property files by hand