【发布时间】:2019-10-07 12:24:41
【问题描述】:
我正在尝试编写一个脚本来测试 WebSphere 单元/节点/集群的所有数据源。虽然这可以通过管理控制台实现,但脚本更适合某些受众。
所以我找到了来自 IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html 的以下文章,它看起来很有希望,因为它准确地描述了我的需求。
在有了一个基本的脚本之后:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
我遇到了一些未记录的行为。与上面的文章相反,testConnection 函数并不总是返回 String,但也可能会抛出异常。
所以我只是使用了一个 try-catch 块:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
现在,当我打印 exc_value 时,得到的是:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
现在,无论出现什么问题,此错误消息始终相同。我测试了身份验证错误、缺少 WebSphere 变量和缺少驱动程序类。 虽然 Admin Console 会打印合理的消息,但脚本会继续打印相同的无意义消息。
非常奇怪的是,只要我没有捕获异常并且脚本只是错误退出,就会显示描述性错误消息。
访问 Java 异常会导致 exc_value.getCause() 给出 None。
我还查看了 DataSource MBean,但由于它们仅在服务器启动时才存在,所以我很快就放弃了。
我希望有人知道如何访问我在未捕获异常时看到的错误消息。
提前致谢
【问题讨论】:
标签: error-handling websphere jython wsadmin