远程访问weblogic9.2的jndi,使用iiop协议java.io.IOException:_Failed_to_retrieve_RMIServer_stub:_javax.naming.NamingException:_Unhandled_exception_in_lookup
文档上说:
Remote Connections Using Only JDK Classes
BEA recommends that you use WebLogic Server classes to connect from remote JMX clients. However, it is possible for remote JMX clients to connect to a WebLogic Server JMX agent using only the classes in the JDK. To do so:
Enable the IIOP protocol for the WebLogic Server instance that hosts your MBeans. Configure the default IIOP user to be a WebLogic Server user with Administrator privileges.
See Enable and Configure IIOP in Administration Console Online Help.
In your JMX client, construct a javax.management.JMXConnector object as follows:
String hostname = "WLS-host"
int port = WLS-port
String protocol = "rmi";
String jndiroot= new String("/jndi/iiop://" + hostname + ":" +
port + "/");
String mserver = "MBean-server-JNDI-name";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,
jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
connector = JMXConnectorFactory.connect(serviceURL, h);
where WLS-host and WLS-port are the listen address and listen port of a WebLogic Server instance and MBean-server-JNDI-name is one of the values listed in Table 4-1.
Note that the hash table you create does not include the name of a protocol package. By leaving this value as null, the JMX client uses the protocol definitions from the com.sun.jmx.remote.protocol package, which is in the JDK.
文档上说只使用jdk便可以访问weblogic的jndi树,我按照它的代码做了个例子:却
出现了问题
这是我的代码:
String hostname = "localhost";
int port = 7001;
String protocol = "rmi";
String jndiroot= new String("/jndi/iiop://" + hostname + ":" +port + "/");
String mserver = "weblogic.management.mbeanservers.runtime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, "weblogic");
h.put(Context.SECURITY_CREDENTIALS,"weblogic");
JMXConnector connector = JMXConnectorFactory.connect(serviceURL, (Map)h);
最后一行抛出异常
抛出异常:
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NamingException: Unhandled exception in lookup [Root exception is org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:323)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at IIOPConWL.getConnection(IIOPConWL.java:44)
at IIOPConWL.runtests(IIOPConWL.java:51)
at IIOPConWL.main(IIOPConWL.java:26)
Caused by: javax.naming.NamingException: Unhandled exception in lookup [Root exception is org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No]
at weblogic.corba.j2ee.naming.Utils.wrapNamingException(Utils.java:83)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:232)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:168)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1871)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1841)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
... 4 more
Caused by: org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.getSystemException(MessageBase.java:897)
at com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_2.getSystemException(ReplyMessage_1_2.java:99)
at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.getSystemExceptionReply(CorbaMessageMediatorImpl.java:572)
at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.processResponse(CorbaClientRequestDispatcherImpl.java:430)
at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.marshalingComplete(CorbaClientRequestDispatcherImpl.java:326)
at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.invoke(CorbaClientDelegateImpl.java:129)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:457)
at weblogic.corba.cos.naming._NamingContextAnyStub.resolve_any(_NamingContextAnyStub.java:80)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:208)
... 9 more
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NamingException: Unhandled exception in lookup [Root exception is org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No]
你的mserver的指定串对吗?