我正在建立一个JMX连接,如:
String currentHost = getRequest().getRequestURL().toString().replaceAll(getRequest().getRequestURI(), "");
String hostname = currentHost.substring(currentHost.lastIndexOf("/") + 1, currentHost.lastIndexOf(":"));
int port = Integer.parseInt(currentHost.substring(currentHost.lastIndexOf(":") + 1));
ObjectName service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
String username = <system user name>;
String password = <system user password>;
String url = "service:jmx:rmi:///jndi/iiop://" + hostname + ":" + port + "/weblogic.management.mbeanservers.domainruntime";
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
JMXServiceURL jmxServiceURL = new JMXServiceURL(url);
JMXConnector connector = JMXConnectorFactory.connect(jmxServiceURL, h);
MBeanServerConnection connection = connector.getMBeanServerConnection();
然后我尝试通过以下代码检索域配置:
ObjectName domain = (ObjectName) connection.getAttribute(service, "DomainConfiguration");
DomainRuntimeServiceMBean domainRuntimeService = MBeanServerInvocationHandler.newProxyInstance(connection, service, DomainRuntimeServiceMBean.class, false);
DomainMBean domainConfiguration = domainRuntimeService.getDomainConfiguration();
这样做我得到了例外:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool.testSettings(ConnectivityTestTool.java:577)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool$ManualStepsCheckerSheet.printWindowContent(ConnectivityTestTool.java:1729)
at com.netcracker.jsp.Sheet.printWindow(Sheet.java:380)
at com.netcracker.jsp.CommonPage.printWindowContent(CommonPage.java:2075)
at com.netcracker.jsp.UniPage.printWindowContent(UniPage.java:719)
at com.netcracker.jsp.ModernPage.printWindow(ModernPage.java:737)
at com.netcracker.jsp.CommonPage.printContent(CommonPage.java:1502)
at com.netcracker.jsp.UniPage.printContent(UniPage.java:285)
at com.netcracker.jsp.Sheet.printContent(Sheet.java:367)
at com.netcracker.jsp.Sheet._service(Sheet.java:304)
at com.netcracker.jsp.Sheet.service(Sheet.java:268)
at com.netcracker.jsp.CommonPage.service(CommonPage.java:930)
at com.netcracker.jsp.CommonPage$SecureRunner.run(CommonPage.java:325)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.security.Security.runAs(Security.java:61)
at com.netcracker.configuration.weblogic.weblogic81.Config81.doAs(Config81.java:43)
at com.netcracker.security.UserSession.doTask(UserSession.java:311)
at com.netcracker.jsp.CommonUserPage.secureRun(CommonUserPage.java:393)
at com.netcracker.jsp.CommonUserPage.secureService(CommonUserPage.java:344)
at com.netcracker.jsp.CommonPage.debugSecureService(CommonPage.java:1297)
at jsp_servlet._solutions._dhl.__connectivitytesttool._jspService(__connectivitytesttool.java:322)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.mediation.dataflow.impl.util.trigger.http.FilterImpl.doFilter(FilterImpl.java:215)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.framework.domain.filters.ThreadDomainFilter.doFilterInternal(ThreadDomainFilter.java:225)
at com.netcracker.framework.domain.filters.ThreadDomainFilter.doFilter(ThreadDomainFilter.java:99)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.presentation.process.SessionTouchFilter.doFilter(SessionTouchFilter.java:74)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.audit.NCSessionsFilter.doFilter(Unknown Source)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.clientaddress.ClientAddressFilter.doFilter(ClientAddressFilter.java:77)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.platform.core.filters.security.HttpSecurityFilter.doFilterInternal(HttpSecurityFilter.java:71)
at com.netcracker.platform.core.filters.security.HttpSecurityFilter.doFilter(HttpSecurityFilter.java:54)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.netcracker.jsp.httpcache.JSPHeadersFilter.doFilter(JSPHeadersFilter.java:105)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3748)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1491)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.ClassCastException: javax.management.ObjectName cannot be cast to weblogic.management.configuration.DomainMBean
at com.sun.proxy.$Proxy128.getDomainConfiguration(Unknown Source)
at com.netcracker.solutions.dhl.pages.test.ConnectivityTestTool.getSSLParams(ConnectivityTestTool.java:428)
实际上,堆栈跟踪底部提到的第428行 DomainMBean domainConfiguration = domainRuntimeService.getDomainConfiguration(); 来自上面的代码片段。
我尝试通过MBeanServerInvocationHandler.newProxyInstance()调用访问其他几个MBean,并且总是有类似的例外。
有人可以建议我的代码有什么问题吗?我怀疑服务器设置可能有问题,但我对此知之甚少......