How to get the correct error message in websphere wsadmin jython?

5.5k views Asked by At

I need code which could handling the exception and continue the process. but the error handling routine seems unable to get the correct error message:

without exception handling:

wsadmin>AdminControl.testConnection (SomeDataSource)

WAS7015E: Exception Running command: "AdminControl.testConnection (SomeDataSource)"
com.ibm.websphere.management.exception.AdminException
javax.management.MBeanException
java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: DSRA8000E: Java archive (JAR) or compressed files do not exist in the path or the required access is not allowed.  Path: /ojdbc6.jar

with exception handling:

wsadmin>try:
wsadmin>  AdminControl.testConnection (SomeDataSource)
wsadmin>except:
wsadmin>  typ,val,tb = sys.exc_info()
wsadmin>  print typ
wsadmin>  print val
wsadmin>  print tb

com.ibm.ws.scripting.ScriptingException
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
<traceback object at -1765990050>

Another version (although i believe there should be smarter way to perform it)

wsadmin>fname='${Server log folder}\SystemOut.log'
wsadmin>file=open(fname,'r')
wsadmin>junk=file.readlines()
wsadmin>file.seek(-1,1)
wsadmin>try:
wsadmin>  AdminControl.testConnection (SomeDataSource)
wsadmin>except:
wsadmin>  err='yes'
wsadmin>
wsadmin>file.seek(1,1)
wsadmin>if err='yes':
wsadmin>  msg=file.readlines()
wsadmin>  print 'Error: '.join(msg)

Seems i finally get the thing i want, although it is really ugly by skipping the entire error handling but directly getting the content of error log.

1

There are 1 answers

3
Eder Luis Jorge On

I don't know why in wsadmin jython it happens, but you can try this:

    try:
     SomeDataSource = "Test"
     AdminControl.testConnection (SomeDataSource)
    except:
     typ,val,tb = sys.exc_info()[1]
     print typ
     print val
     print tb

There are the results:

    wsadmin>try:
    wsadmin> SomeDataSource = "Test"
    wsadmin> AdminControl.testConnection (SomeDataSource)
    wsadmin>except:
    wsadmin> typ,val,tb = sys.exc_info()[1]
    wsadmin> print typ
    wsadmin> print val
    wsadmin> print tb
    wsadmin>
    WASX7015E: Exception running command: ""; exception information:
     com.ibm.ws.scripting.ScriptingException: AdminControl service not available

Note sys.exc_info()[1]

Regards