Integration Toolbox
for IBM® TIVOLI® Storage Manager

package miscellaneous; import hu.user.toolbox.tsm.Toolbox; import hu.user.toolbox.tsm.exception.TSMException; import hu.user.toolbox.tsm.exception.ToolboxErrorCodes; import hu.user.toolbox.tsm.exception.ToolboxException; /** * <b>Function:</b><br> * Demonstrates how exceptions are reported. * <p> * The following operations are performed: * <ol> * <li>Initializing a single-threaded TSM API environment.</li> * <li>Creating a new TSMSession instance. * Setting default connection options. Connecting to the server using * the node name "NODE_DOES_NOT_EXIST" and password "PASSWORD".</li> * <li>Catching the exception and printing the return code and the associated * message (RC53).</li> * <li>Cleaning up the resources.</li> * </ol> * <p> * <b>Compile:</b> * <pre> * javac -d bin -cp ../lib/toolboxfortsm.jar miscellaneous/PrintException.java * </pre> * <p> * <b>Execute:</b><br> * You should first set the environment variables to point to the correct * files/directories. * <pre> * set DSMI_CONFIG={Full path of your dsm.opt} * set DSMI_DIR={Tivoli Storage Manager API installation directory} * set DSMI_LOG={Any arbitrary directory} * </pre> * Then use the java command to execute the program: * <p> * <pre> * java -cp bin:../lib/toolboxfortsm.jar:../lib/ext/log4j-1.2.17.jar:../config * -Djava.library.path=../lib miscellaneous.PrintException * </pre> */ public class PrintException { private static final String NODE_NAME = "NODE_DOES_NOT_EXIST"; private static final String PASSWORD = "PASSWORD"; public static void main(final String args[]) throws ToolboxException { try { // Initializing a single-threaded environment Toolbox.initSingleThreading(); // Connecting to the server with the default connection options Toolbox.createSession(NODE_NAME, PASSWORD); } catch (ToolboxException e) { // Getting the underlying native API return codes and messages if (e.getReturnCode() == ToolboxErrorCodes.TSM_EXCEPTION) { TSMException exception = (TSMException) e.getCause(); System.out.println("Return code: " + exception.getReturnCode()); System.out.println("Message: " + exception.getMessage()); } e.printStackTrace(); } finally { // Cleaning up the environment Toolbox.cleanUp(); } } }