0 Replies Latest reply: Mar 27, 2013 5:22 AM by 999418 RSS

    How to resole  addTarget method problem?

    999418
      hello, all
      please help me ,how to resovle this problem addTarget method ?

      javax.management.ReflectionException
           at weblogic.management.jmx.modelmbean.WLSModelMBean.invoke(WLSModelMBean.java:395)
           at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
           at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
           at weblogic.management.mbeanservers.domainruntime.internal.FederatedMBeanServerInterceptor.invoke(FederatedMBeanServerInterceptor.java:255)
           at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$16.run(WLSMBeanServerInterceptorBase.java:447)
           at java.security.AccessController.doPrivileged(Native Method)
           at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.invoke(WLSMBeanServerInterceptorBase.java:445)
           at weblogic.management.mbeanservers.internal.SecurityMBeanMgmtOpsInterceptor.invoke(SecurityMBeanMgmtOpsInterceptor.java:65)
           at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase$16.run(WLSMBeanServerInterceptorBase.java:447)
           at java.security.AccessController.doPrivileged(Native Method)
           at weblogic.management.jmx.mbeanserver.WLSMBeanServerInterceptorBase.invoke(WLSMBeanServerInterceptorBase.java:445)
           at weblogic.management.mbeanservers.internal.SecurityInterceptor.invoke(SecurityInterceptor.java:443)
           at weblogic.management.mbeanservers.internal.AuthenticatedSubjectInterceptor$10$1.run(AuthenticatedSubjectInterceptor.java:582)
           at java.security.AccessController.doPrivileged(Native Method)
           at weblogic.management.mbeanservers.internal.AuthenticatedSubjectInterceptor$10.run(AuthenticatedSubjectInterceptor.java:580)
           at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
           at weblogic.management.mbeanservers.internal.AuthenticatedSubjectInterceptor.invoke(AuthenticatedSubjectInterceptor.java:573)
           at weblogic.management.jmx.mbeanserver.WLSMBeanServer.invoke(WLSMBeanServer.java:307)
           at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1426)
           at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72)
           at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1264)
           at java.security.AccessController.doPrivileged(Native Method)
           at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1366)
           at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
           at javax.management.remote.rmi.RMIConnectionImpl_WLSkel.invoke(Unknown Source)
           at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
           at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
           at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
           at weblogic.security.service.SecurityManager.runAs(Unknown Source)
           at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
           at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
           at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
           at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
      Caused by: java.lang.NoSuchMethodException: addTarget(javax.management.ObjectName,) for com.bea:Name=EsbServer,Location=esbdomain4,Type=Server
           ... 33 more



      public static MBeanServerConnection getConnection() throws IOException,
                     MalformedURLException, MalformedObjectNameException,
                     NullPointerException {
                // 描述MBean Server的地址
                
      //          String EDIT_SERVICE = "com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean";
                String EDIT_SERVICE = "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
      //          String EDIT_SERVICE = "com.bea:Name=EditService,Type=weblogic.management.mbeanservers.edit.EditServiceMBean";
                ObjectName service = new ObjectName(EDIT_SERVICE);

                String jndiroot = "/jndi/";
                String mserver = "weblogic.management.mbeanservers.domainruntime";
      //          String mserver = "weblogic.management.mbeanservers.runtime";
      //          String mserver = "weblogic.management.mbeanservers.edit";
                


                JMXServiceURL serviceURL = new JMXServiceURL("t3","172.21.34.69", 51900, jndiroot+ mserver);
                
                Hashtable h = new Hashtable();
                // 登录weblogic该域的用户名和密码
                h.put(Context.SECURITY_PRINCIPAL, "chnesb");
                h.put(Context.SECURITY_CREDENTIALS, "_chnesb!2008");
                h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                          "weblogic.management.remote");
                // 构造JMXConnector对象。
                JMXConnector connector = JMXConnectorFactory.connect(serviceURL, h);
                // 连接到MBean
                MBeanServerConnection connection = connector.getMBeanServerConnection();

                try {
                     ObjectName beans = (ObjectName) connection.getAttribute(service,
                               "DomainConfiguration");
                     
                     ObjectName[] WTCServer = (ObjectName[]) connection.getAttribute(beans,
                               "WTCServers");
                     ObjectName wtc_Server = null;
                     
                     for(int i=0; i<WTCServer.length;i++){
                          
                          String wtc = (String) connection.getAttribute(WTCServer,"Name");
                          if("chnesbWTC".equals(wtc)){
                               wtc_Server = WTCServer[i];
                               
                          }
                     }
                     
                     ObjectName target = null;
                     ObjectName[] targets = (ObjectName[]) connection.getAttribute(wtc_Server,"Targets");
                     for(int j=0; j<targets.length;j++){
                          String targetName = (String) connection.getAttribute(targets[j],"Name");
                          if("EsbServer".equals(targetName)){
                               target = targets[j];
                          }
                     }
                     
      //               connection.invoke(target, "addTarget", new Object[]{target}, new String[]{"weblogic.management.configuration.TargetMBean"});
                     connection.invoke(target, "addTarget", new Object[]{target}, new String[]{"javax.management.ObjectName"});
                     
                } catch (AttributeNotFoundException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (InstanceNotFoundException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (MBeanException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (ReflectionException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } /*catch (InvalidAttributeValueException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (DistributedManagementException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }*/

                
                
                
                return connection;

           }