Error when conecting with a remote object from MBean
ovistanciu Feb 19, 2008 10:42 AMHello.
I have a remote server and a client in the form of an MBean, designed following the Serialization Server example from JBoss Remoting.
The Server
import javax.management.MBeanServer; import org.jboss.remoting.InvocationRequest; import org.jboss.remoting.InvokerLocator; import org.jboss.remoting.ServerInvocationHandler; import org.jboss.remoting.ServerInvoker; import org.jboss.remoting.callback.InvokerCallbackHandler; import org.jboss.remoting.transport.Connector; import ro.ebsoft.doorcontrol.comm.common.CommModuleMain; import ro.ebsoft.doorcontrol.interfaces.CommModule; public class Main { private static String transport = "rmi"; private static String host = "localhost"; private static int port = 5400; private static CommModule response; public void setupServer(String locatorURI) throws Exception { InvokerLocator locator = new InvokerLocator(locatorURI); System.out.println("Starting remoting server with locator URI of: " + locatorURI); Connector connector = new Connector(locator); connector.create(); SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); connector.addInvocationHandler("CommModule", invocationHandler); connector.start(); } // rmi server main class public static void main(String args[]) { String locatorURI = transport + "://" + host + ":" + port + "/?serializationtype=jboss"; Main main = new Main(); try { response = new CommModuleMain(); main.setupServer(locatorURI); while (true) { Thread.sleep(1000); } } catch (Exception e) { e.printStackTrace(); } } public static class SampleInvocationHandler implements ServerInvocationHandler { @Override public void addListener(InvokerCallbackHandler arg0) { } @Override public Object invoke(InvocationRequest invocation) throws Throwable { System.out.println("Invocation request is " + invocation.getParameter()); return new CommModuleMain(); } @Override public void removeListener(InvokerCallbackHandler arg0) { } @Override public void setInvoker(ServerInvoker arg0) { } @Override public void setMBeanServer(MBeanServer arg0) { } } }
The MBean class
package ro.ebsoft.doorcontrol.mbean.engine; import org.jboss.remoting.Client; import org.jboss.remoting.InvokerLocator; import org.jboss.system.ServiceMBeanSupport; import interfaces.CommModule; public class CommEngine extends ServiceMBeanSupport implements CommEngineMBean { private static String transport = "rmi"; private static String host = "localhost"; private static int port = 5400; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public void printMessage(){ log.info(message); } protected void startService() throws Exception{ log.info("Starting CommModuleMBean"); String locatorURI = transport + "://" + host + ":" + port + "/?serializationtype=jboss"; log.info("Connecting to " + locatorURI); //String locatorURI = transport + "://" + host + ":" + port; InvokerLocator locator = new InvokerLocator(locatorURI); Client remotingClient = new Client(locator); remotingClient.connect(); try{ CommModule cm = (CommModule)remotingClient.invoke("CommModule"); } catch(Throwable t){ t.printStackTrace(); } } protected void stopService() throws Exception{ log.info("Stopping with message: " + message); } //setters & getters }
When I run both the server and a similar client (which is not an MBean), all goes well. But when I deploy my client as a .sar in the app server, I get
ERROR [MainDeployer] Could not create deployment: file:/opt/jboss-4.2.2.GA/server/default/deploy/commengine.sar org.jboss.deployment.DeploymentException: - nested throwable: (java.lang.reflect.UndeclaredThrowableException) at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:196) at org.jboss.system.ServiceController.install(ServiceController.java:226) 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:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94) at org.jboss.mx.server.Invocation.invoke(Invocation.java:86) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210) at $Proxy4.install(Unknown Source) at org.jboss.deployment.SARDeployer.create(SARDeployer.java:249) at org.jboss.deployment.MainDeployer.create(MainDeployer.java:969) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:818) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782) 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:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94) at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133) at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142) at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210) at $Proxy9.deploy(Unknown Source) at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421) at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634) at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263) at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336) at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289) at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245) at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94) at org.jboss.mx.server.Invocation.invoke(Invocation.java:86) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659) at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978) at $Proxy0.start(Unknown Source) at org.jboss.system.ServiceController.start(ServiceController.java:417) at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94) at org.jboss.mx.server.Invocation.invoke(Invocation.java:86) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210) at $Proxy4.start(Unknown Source) at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302) at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766) 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:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94) at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133) at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142) at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210) at $Proxy5.deploy(Unknown Source) at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482) at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362) at org.jboss.Main.boot(Main.java:200) at org.jboss.Main$1.run(Main.java:508) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.reflect.UndeclaredThrowableException at org.jboss.system.ServiceCreator.install(ServiceCreator.java:236) at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:451) at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:171) ... 81 more Caused by: java.lang.NoClassDefFoundError: interfaces/CommModule at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357) at java.lang.Class.getConstructor0(Class.java:2671) at java.lang.Class.getConstructor(Class.java:1629) at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:1232) at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:286) at org.jboss.mx.server.MBeanServerImpl.createMBean(MBeanServerImpl.java:344) at org.jboss.system.ServiceCreator.install(ServiceCreator.java:157) ... 83 more
I have included a .jar which contains interfaces.CommModule in the MBean .sar.
If I change the server to return. say, a String rather than a CommModule, all goes well, the MBean deploys and works as expected (obtains the string by invoking the remote server).
All I want to do is to obtain a remote instance of a CommModule when the app server starts.
Could someone explain what am I doing wrong? Or a better idea (any idea) of doing this?
Thank you for your time.