2 Replies Latest reply on Jul 25, 2006 6:38 PM by falazar

    Problem running remote MBean

    jaleyba


      Hi

      I'm trying to run a method of a MBean service from remote machine.

      Well, after read docs I did the following:


      First I did an interface:


      public interface ActiveMQNetworkMBean {
      
       public void setPropertiesResource( String propertiesResource );
      
       public String getPropertiesResource();
      
       public void start() throws Exception;
      
       public void stop() throws Exception;
      
       public void startSlave() throws Exception;
      
       public void stopSlave() throws Exception;
      
       public String myTestAction() throws Exception;
      
       Object invoke(org.jboss.invocation.Invocation mi) throws Exception;
      }
      
      






      Then I did the implementation:

      public class ActiveMQNetwork implements ActiveMQNetworkMBean {
       private String propertiesResource;
       private BrokerService service = null;
       private BrokerService serviceSlave = null;
       private boolean started = false;
       private boolean startedSlave = false;
       private static Logger log = Logger.getLogger(ActiveMQNetwork.class);
      
      
       /**
       * Returns current propertie resource or null if wasn't
       * yet configured.
       *
       * @return string with propertie resource.
       */
       public String getPropertiesResource() {
       return this.propertiesResource;
       }
      
      
       /**
       * Set properties Resource.
       *
       * @param propertiesResource
       */
       public void setPropertiesResource(String propertiesResource) {
       this.propertiesResource = propertiesResource;
       }
      
      
       /**
       * Start service.
       *
       * @throws Exception
       */
       public void start() throws Exception {
       started = true;
       log.info("BROKER SERVICE: Starting ActiveMQNetwork ... " + propertiesResource);
       createNetwork();
       }
      
       /**
       * Stop service.
       *
       * @throws Exception
       */
       public void stop() throws Exception {
       started = false;
       log.info("BROKER SERVICE: Stoping ActiveMQNetwork ...");
       if (service != null) {
       service.stop();
       service = null;
       }
       // do what you want ...
       }
      
       /**
       * Create a broker.
       *
       * Configuration will be read from a file.
       */
       private void createNetwork() {
       log.info("BROKER SERVICE: trying to crete broker");
      
       try {
       URI brokerURI = new URI("xbean:" + System.getProperty("jboss.server.config.url") + "activemq_master.xml");
       service = BrokerFactory.createBroker(brokerURI);
       if (service != null) {
       service.start();
       }
       } catch (Exception e) {
       log.error("BROKER SERVICE: createNetwork Exception: " + e.getMessage());
       e.printStackTrace();
       }
       }
      
       /**
       * Start service.
       *
       * @throws Exception
       */
       public void startSlave() throws Exception {
       startedSlave = true;
       log.info("BROKER SERVICE: Starting ActiveMQNetwork Slave Broker... ");
       createNetworkSlave();
       }
      
       /**
       * Stop service.
       *
       * @throws Exception
       */
       public void stopSlave() throws Exception {
       startedSlave = false;
       log.info("BROKER SERVICE: Stoping ActiveMQNetwork Slave Broker...");
       if (serviceSlave != null) {
       serviceSlave.stop();
       serviceSlave = null;
       }
       // do what you want ...
       }
      
       /**
       * Create a broker.
       *
       * Configuration will be read from a file.
       */
       private void createNetworkSlave() {
       log.info("BROKER SERVICE: trying to crete broker slave");
      
       try {
       URI brokerURI = new URI("xbean:" + System.getProperty("jboss.server.config.url") + "activemq_slave.xml");
       serviceSlave = BrokerFactory.createBroker(brokerURI);
       if (serviceSlave != null) {
       serviceSlave.start();
       }
       } catch (Exception e) {
       log.error("BROKER SERVICE: createNetwork Slave Exception: " + e.getMessage());
       e.printStackTrace();
       }
       }
      
       public String myTestAction() {
       return "MyAction";
       }
      
      
       public Object invoke(Invocation mi) throws Exception {
       log.info("BROKER SERVICE: MyService.invoke> method=" + mi.getMethod().getName());
       return "invoke";
       }
      
      }
      
      






      I deployed this service as sar file with the follown jboss-service.xml


      
      <mbean code="com.bs.activemq.mbean.service.ActiveMQNetwork"
       name="jms.ActiveMQ:service=ActiveMQNetwork">
       <depends>jboss:service=Naming</depends>
       </mbean>
      
       <!-- Proxy factory for MyService that will call target method on the target service -->
       <mbean code="org.jboss.invocation.jrmp.server.JRMPProxyFactory"
       name="jboss.jmx:type=adaptor,name=MyServiceInvokeTarget,protocol=jrmp,service=proxyFactory">
       <!-- Use the standard JRMPInvoker from conf/jboss-service.xxml -->
       <depends optional-attribute-name="InvokerName">jboss:service=invoker,type=jrmp</depends>
       <!-- The target MBean -->
       <depends optional-attribute-name="TargetName">jms.ActiveMQ:service=ActiveMQNetwork</depends>
       <!-- Where to bind the proxy factory -->
       <attribute name="JndiName">ActiveMQNetworkInvokeTarget</attribute>
       <!-- Invoke target method instead of invoke(Invocation mi) -->
       <attribute name="InvokeTargetMethod">true</attribute>
       <!-- Comma-separated list of exported interfaces -->
       <attribute name="ExportedInterfaces">com.bs.activemq.mbean.service.ActiveMQNetworkMBean</attribute>
       <!-- client-side interceptors -->
       <attribute name="ClientInterceptors">
       <interceptors>
       <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
       <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
       <interceptor>org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor</interceptor>
       <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
       </interceptors>
       </attribute>
       </mbean>
      
      






      Then I did a client that work as follows:



      
       public static void main(String[] args) {
       try {
       Hashtable env = new Hashtable();
       env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       env.put("java.naming.provider.url", "jnp://172.31.112.9:1099");
       //env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
      
       InitialContext ic = new InitialContext(env);
       ActiveMQNetworkMBean myService = (ActiveMQNetworkMBean) ic.lookup("ActiveMQNetworkInvokeTarget");
       String res = myService.myTestAction();
      
      
       } catch(Exception e) {
       e.printStackTrace();
       }
      
      
      





      But when I run the client I get the message:

      
      javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.invo
      cation.InvokerInterceptor; unable to create instance]
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:707)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:347)
       at com.bs.activemq.mbean.service.Test.main(Test.java:23)
       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:324)
       at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
      Caused by: java.io.InvalidClassException: org.jboss.invocation.InvokerInterceptor; unable to create
      instance
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1633)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.skipCustomData(ObjectInputStream.java:1810)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1698)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
       at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:66)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1686)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
       at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:66)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1686)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
       at org.jboss.proxy.ClientContainer.readExternal(ClientContainer.java:142)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1686)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1644)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
       at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
       at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:57)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:637)
       ... 8 more
      
      




      I really don't know what am I doing wrong.

      Could please somebody help me ?


      Thanks in advance

      J