Hello,

dans un projet, j'ai un mbean server:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
    private static String hostName = "localhost"; 
    private static int rmiPort = 1099;
    private static String rmiDomain = "myDomain";
    private static String rmiAppName = "jmxApp";
    private static String protocol = "rmi";
 
    public static void main(String[] argv){        
        startRmiServer();
        createMBeanServer();
    }
 
    private static void startRmiServer(){
        try {
            LocateRegistry.createRegistry(rmiPort);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
    private static void createMBeanServer(){
        MBeanServer server = MBeanServerFactory.createMBeanServer(rmiDomain);
        JMXServiceURL addr = null;
        RMIConnectorServer connector = null;
        try {
            addr = new JMXServiceURL(protocol,hostName,rmiPort,"/jndi/"+rmiAppName);
 
            HashMap<String, String> h = new HashMap<String, String>();
            h.put(Context.INITIAL_CONTEXT_FACTORY, RegistryContextFactory.class.getName());
 
            connector = new RMIConnectorServer(addr, h, server);
            server.registerMBean(connector, new ObjectName(rmiDomain+":name="+rmiAppName));
            connector.start();
 
            System.out.println("MBean server started: "+connector.getAddress());
 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }    
 
    public void testMBean(){
        System.out.println("Victoire!");
    }
dans un autre projet, j'essaie d'y accéder:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
    private static String hostName = "localhost"; 
    private static int rmiPort = 1099;
    private static String rmiDomain = "myDomain";
    private static String rmiAppName = "jmxApp";
    private static String protocol = "rmi";
 
    public static void main(String[] argv){
 
        JMXServiceURL url;
        try {
            url = new JMXServiceURL(protocol,hostName,rmiPort,"/jndi/"+rmiAppName);
 
            HashMap<String, String> h = new HashMap<String, String>();
            h.put(Context.INITIAL_CONTEXT_FACTORY, RegistryContextFactory.class.getName());
 
            JMXConnector jmxc = JMXConnectorFactory.connect(url, h);
 
            MBeanServerConnection mbsc=jmxc.getMBeanServerConnection();
 
            System.out.println("found " + mbsc.queryMBeans(null, null).size() + " mbeans");
 
            mbsc.invoke(new ObjectName(rmiDomain+":name="+rmiAppName), "testMBean",null,null);
 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
    }
L'affichage me retourne
found 2 mbeans
, donc le serveur est accessible!

Mais l'appel de invoke me génère une exception:
javax.management.ReflectionException: No such operation: testMBean
at com.sun.jmx.mbeanserver.PerInterface.noSuchMethod(PerInterface.java:152)
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:94)
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
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 javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1359)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
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)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.invoke(RMIConnector.java:978)
at Test1MBean.main(Test1MBean.java:36)
Caused by: java.lang.NoSuchMethodException: testMBean()
at com.sun.jmx.mbeanserver.PerInterface.noSuchMethod(PerInterface.java:150)
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:94)
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
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 javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1359)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788)
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)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Pourquoi? Qu'est-ce qui est faux?

Merci d'avance.

A+