我正在尝试编写一个独立的jython JMX客户端来监视WebSphere Application Server。它使用SOAP和SSL连接到DMGR。
代码在使用WSADMIN运行时有效,但在尝试将其作为独立的jython客户端运行时失败。这使我相信代码是正确的,并且在尝试将其作为独立客户端运行时,我缺少JAR或配置文件。此外,这适用于SSL禁用。
我有以下问题:
WAS版本: 7.0.0.21 Solaris on Solaris
import java.util.Properties as Properties
import javax.management.ObjectName as ObjectName
import com.ibm.websphere.management.AdminClient as AdminClient
import com.ibm.websphere.management.AdminClientFactory as AdminClientFactory
class DeploymentManager:
def __init__(self, host, soapport, user, password):
self.host = host
self.soapport = soapport
self.user = user
self.password = password
def create_admin_client(dmgrhost, dmgrsoapport, user, password):
props = Properties()
props.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP)
props.setProperty(AdminClient.CONNECTOR_HOST, dmgrhost)
props.setProperty(AdminClient.CONNECTOR_PORT, dmgrsoapport)
props.setProperty(AdminClient.CONNECTOR_SECURITY_ENABLED, "true");
props.setProperty(AdminClient.USERNAME, user);
props.setProperty(AdminClient.PASSWORD, password);
props.setProperty("javax.net.ssl.trustStore",
"/opt/IBM/Profiles/dmgr01/etc/DummyClientTrustFile.jks");
props.setProperty("javax.net.ssl.keyStore",
"/opt/IBM/Profiles/dmgr01/etc/DummyClientKeyFile.jks");
adminClient = AdminClientFactory.createAdminClient(props)
return adminClient
def get_servers():
servers = [s for s in adminClient.queryNames(queryName, None).toArray()]
return servers
def get_server_states(servers):
serverstates = {}
for server in servers:
name = adminClient.getAttribute(server, "name")
pid = adminClient.getAttribute(server, "pid")
state = adminClient.getAttribute(server, "state")
serverstates[name] = {'name' : name, 'state' : state, 'pid' : pid}
return serverstates
DMGRs = []
DMGRs.append(DeploymentManager('dmgr1_host', 'dmgr1_soap_port', 'dmgr1_user', 'dmgr1_pw'))
DMGRs.append(DeploymentManager('dmgr2_host', 'dmgr2_soap_port', 'dmgr2_user', 'dmgr2_pw'))
DMGRs.append(DeploymentManager('dmgr3_host', 'dmgr3_soap_port', 'dmgr3_user', 'dmgr3_pw'))
for DMGR in DMGRs:
adminClient = create_admin_client(DMGR.host, DMGR.soapport, DMGR.user, DMGR.password)
queryName = ObjectName("WebSphere:*,node=*,type=Server,name=srv*")
servers = get_servers()
serverstates = get_server_states(servers)
print '## %s ##' % DMGR.host
keys = serverstates.keys()
keys.sort()
for key in keys:
print '%s %s: %s' % (serverstates[key]['name'],
serverstates[key]['pid'],
serverstates[key]['state'])
print
这是我在运行时看到的错误:
jython -Dpython.path=/opt/IBM/WebSphere/AppServer/runtimes/com.ibm.ws.admin.client_7.0.0.jar:/opt/IBM/WebSphere/AppServer/plugins/com.ibm.ws.security.crypto.jar:/opt/IBM/WebSphere/AppServer/plugins/com.ibm.ws.runtime.jar -Dcom.ibm.SOAP.ConfigURL=/opt/IBM/Profiles/dmgr01/properties/soap.client.props was_common.py
Apr 16, 2012 3:07:39 PM com.ibm.ws.management.connector.interop.JMXClassLoader
WARNING: Could not find tmx4jTransform.jar in null/etc/tmx4jTransform.jar - Interoperability to older versions of WebSphere is disabled
Apr 16, 2012 3:07:40 PM com.ibm.ws.ssl.config.SSLConfigManager
INFO: ssl.disable.url.hostname.verification.CWPKI0027I
Apr 16, 2012 3:07:40 PM com.ibm.ws.security.config.SecurityObjectLocator
INFO: Client code attempting to load security configuration
Traceback (most recent call last):
File "was_common.py", line 56, in <module>
adminClient = create_admin_client(DMGR.host, DMGR.soapport, DMGR.user, DMGR.password)
File "was_common.py", line 30, in create_admin_client
adminClient = AdminClientFactory.createAdminClient(props)
at com.ibm.websphere.management.AdminClientFactory.createAdminClientPrivileged(AdminClientFactory.java:632)
at com.ibm.websphere.management.AdminClientFactory.access$000(AdminClientFactory.java:123)
at com.ibm.websphere.management.AdminClientFactory$1.run(AdminClientFactory.java:206)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
at com.ibm.websphere.management.AdminClientFactory.createAdminClient(AdminClientFactory.java:202)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
com.ibm.websphere.management.exception.ConnectorException: com.ibm.websphere.management.exception.ConnectorException: ADMC0016E: The system cannot create a SOAP connector to connect to host dmgr1_host at port dmgr1_soap_port
注意:我将此示例中的某些值更改为通用值。