-
Nov 30th, 2007, 05:05 AM
#1
FileSystemXmlApplicationContext - JNDI - JMX
Hi,
I develop a web application running on Tomcat. And I would like to test my JNDI-dependent source code with JUnit without running Tomcat, i.e. I do not want to use Cactus. It was straightforward to use org.springframework.mock.jndi.SimpleNamingContextB uilder for binding my objects. Furthermore I use org.springframework.context.support.FileSystemXmlA pplicationContext to load application context. Everything worked fine until I added JMX components. Registering with RMI (registry on remote server) fails in my test environment while it works when starting Tomcat. Here are some code snippets:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlA pplicationContext;
import de.systemagmbh.dfs.ServerConst;
import de.systemagmbh.dfs.editor.model.CommonConst;
import de.systemagmbh.dfs.jndi.JndiContextBuilder;
public class TTT implements ServerConst, CommonConst {
private static final Log log = LogFactory.getLog(TTT.class);
@Test
public void appCtxTest() {
// logging
DOMConfigurator.configure("WebContent" + fs + "WEB-INF" + fs + "log4j"
+ XML);
// JNDI environment
JndiContextBuilder ctxBuilder = new JndiContextBuilder();
try {
ctxBuilder.bindContextXml("WebContent" + fs + "META-INF" + fs
+ "context.xml");
} catch (Exception e) {
log.error(e, e);
}
// application context
String[] path = { "test" + fs + "springforum" + fs + "appctx.xml" };
ApplicationContext ctx = new FileSystemXmlApplicationContext(path);
}
}
JndiContextBuilder reads context.xml and binds all of its objects to the JNDI environment:
import org.springframework.mock.jndi.SimpleNamingContextB uilder;
public static final String jndiRoot = "java:comp/env";
ctxBuild = SimpleNamingContextBuilder
.emptyActivatedContextBuilder();
String name = jndiRoot + "/" + el.getAttribute("name");
ctxBuild.bind(name, o);
extract from appctx.xml:
<jee:jndi-lookup id="dataSource"
jndi-name="java:comp/env/jdbc/dfsDB" resource-ref="true" />
<bean id="cleanupDaoTarget"
class="de.systemagmbh.dfs.cleanup.CleanupDao">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="mBeanServerClient"
class="de.systemagmbh.dfs.jmx.MBeanServerConnectio nFactoryBean">
<property name="serviceUrl"
value="service:jmx:rmi://${PARSER_HOST_NAME}/jndi/rmi://${PARSER_HOST_NAME}:${rmi.port}/dfsParser" />
<property name="username" value="parserRole" /><!-- for jndi configuration -->
<property name="passwd" value="parserPasswd" />
</bean>
<bean id="remoteParserServiceMBean"
class="org.springframework.jmx.access.MBeanProxyFa ctoryBean">
<property name="objectName" value="services:name=parserControl" />
<property name="server" ref="mBeanServerClient" />
<property name="proxyInterface"
value="de.systemagmbh.dfs.parser.IParserControlMBe an" />
</bean>
Exception:
Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: Name [rmi://magni:8025/dfsParser] not bound; 142 bindings: [java:comp/env/...
at javax.management.remote.rmi.RMIConnector.connect(R MIConnector.java:317)
at javax.management.remote.JMXConnectorFactory.connec t(JMXConnectorFactory.java:248)
..
Thanks for any comment,
Robert
-
Jun 9th, 2011, 09:51 AM
#2
SimpleNamingContextBuilder - JMX
I have exactly the same problem:
Using a SimpleNamingContextBuilder for my tests, i can't create a MBeanServerConnection anymore (without the SimpleNamingContextBuilder, using jndi in a container, I don't have that problem and everything works fine):
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'clientConnector' defined in class path resource [META-INF/spring/spring-context.xml]: Invocation of init method failed; nested exception is java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: Name [rmi://localhost:1099/jmxrmi] not bound; 1 bindings: [java:comp/env/jdbc/DS]
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
at
[XXX])
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:27)
at org.springframework.test.context.junit4.statements .RunBeforeTestMethodCallbacks.evaluate(RunBeforeTe stMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements .RunAfterTestMethodCallbacks.evaluate(RunAfterTest MethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements .SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:44)
at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRu nner.java:173)
at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.ev aluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.ja va:220)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:180 )
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: Name [rmi://localhost:1099/jmxrmi] not bound; 1 bindings: [java:comp/env/jdbc/Dispatcher]
at javax.management.remote.rmi.RMIConnector.connect(R MIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connec t(JMXConnectorFactory.java:248)
at org.springframework.jmx.support.MBeanServerConnect ionFactoryBean.connect(MBeanServerConnectionFactor yBean.java:131)
at org.springframework.jmx.support.MBeanServerConnect ionFactoryBean.afterPropertiesSet(MBeanServerConne ctionFactoryBean.java:119)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
... 41 more
Caused by: javax.naming.NameNotFoundException: Name [rmi://localhost:1099/jmxrmi] not bound; 1 bindings: [java:comp/env/jdbc/Dispatcher]
at org.springframework.mock.jndi.SimpleNamingContext. lookup(SimpleNamingContext.java:132)
at javax.naming.InitialContext.lookup(InitialContext. java:392)
at javax.management.remote.rmi.RMIConnector.findRMISe rverJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMISe rver(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(R MIConnector.java:257)
... 46 more
Did you solve this somehow? Or did someone else?
-
Jun 9th, 2011, 10:01 AM
#3
I did not solve that problem.
Hi ojelinski,
unfortunately I did not solve that problem - I gave up.
Nobody but you answered to my thread in 3 and a half years 
If you find a solution please post ist here!
Good luck,
Robert
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules