MBean remoting causes connection reset
I am attempting to get JSR-160 remote MBeans working over RMI in an existing piece of code, but I am having little success.
Here is the scenerio. We have a JBoss implementation using their MBean server and their custom RMI remoting for MBeans. I would like to start conversion away from the JBoss-specific stuff. The portion of code that calls the remote MBean server is being re-written, using Spring heavily, so I see this as an opportunity to start a switch to the more standard JSR-160 way of doing business.
What I have done is implemented a Spring context within the old app, adding the following bean definitions:
Code:
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="1099"/>
</bean>
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
<bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
<property name="server">
<ref local="mbeanServer"/>
</property>
<property name="objectName" value="connector:name=rmi"/>
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector"/>
</bean>
This "seems" to work ok, or at least I dont get an error. I then wrote unit test class that attempts to grab a reference to a remote MBean using the proxy generated MBeanProxyFactory as such
Code:
<bean id="mbeanServerConnection" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl">
<value>service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector</value>
</property>
</bean>
<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName">
<value>ESM:service=monitor,type=Central Application Monitor</value>
</property>
<property name="proxyInterface">
<value>com.xxx.remote.monitor.ApplicationMonitorMBean</value>
</property>
<property name="server">
<ref local="mbeanServerConnection"/>
</property>
</bean>
And the code to grab the proxy
Code:
ApplicationMonitorMBean mbean = (ApplicationMonitorMBean)ctx.getBean("proxy");
System.out.println("MBean: "+mbean);
All looks good so far, but when I try to run the JUnit, I get a big nasty error:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mbeanServerConnection' defined in file [C:\dev\Projects\Work\virtualHub\apps\node\src\conf\spring\spring_soapclient_example.xml]: Initialization of bean failed; nested exception is java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Connection reset]
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Connection reset]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:317)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at org.springframework.jmx.support.MBeanServerConnectionFactoryBean.connect(MBeanServerConnectionFactoryBean.java:146)
at org.springframework.jmx.support.MBeanServerConnectionFactoryBean.afterPropertiesSet(MBeanServerConnectionFactoryBean.java:114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:89)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:74)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:65)
at com.xxx.node.test.SimpleTaskExecution.setUp(SimpleTaskExecution.java:57)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketException: Connection reset]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:110)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1807)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1777)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:259)
... 23 more
Searching the web and this forum for info has turned a bust, so I now turn to the wisdom of my peers.
Thanks in advance for any help, and please let me know if there is any other information you might need.