0 Replies Latest reply on May 15, 2007 4:49 AM by grininger.h

    NullPointerException while binding jca pool vom java: namesp

    grininger.h Newbie

      Hello,

      for JUnit testing purposes I need to access JCA Connections from a different JVM.

      Since it's not recommended to put JCA Datasources in the global JNDI context, they are in the java: context, which means they ain't reachable by JUnit JVM.

      From the application I access the connection by using the ctx java:/comp/env.

      My idea now was to bind the datasources which are in the java: jndi context to global context with the name comp/env (like a tunnel). When I access the database from JUnit from a different JVM, the "java:" is ignored and I get the correct datasource.
      (Of course this is only done in a development environment.)

      Example:
      (global ctx) comp/env/testdb -----------> java:/mydatasources/testdb

      Unfortunately I'm having problems while binding the WrapperDatasource from the java: ctx to the global ctx. I'm getting the following NullPointerException
      Maybe this is not allowed? I'm having no problems in binding dummy objects into to the global ctx.

      
      10:25:33,593 INFO [STDOUT] bound maindb to pseudo context (for JUnit)
      10:25:33,594 INFO [STDOUT] name: maindb
      10:25:33,594 INFO [STDOUT] Try to bind maindb to Object=org.jboss.resource.adapter.jdbc.WrapperDataSource@7d41cd01
      10:25:33,594 ERROR [STDERR] java.lang.NullPointerException
      10:25:33,594 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingContext.java:556)
      10:25:33,595 ERROR [STDERR] at org.jnp.interfaces.NamingContext.bind(NamingContext.java:531)
      10:25:33,595 ERROR [STDERR] at test.TestServlet.init(TestServlet.java:126)
      10:25:33,595 ERROR [STDERR] at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4071)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:4375)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
      10:25:33,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      10:25:33,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      10:25:33,595 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,595 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,595 ERROR [STDERR] at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
      10:25:33,595 ERROR [STDERR] at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
      10:25:33,595 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,595 ERROR [STDERR] at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
      10:25:33,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      10:25:33,595 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      10:25:33,595 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,595 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,595 ERROR [STDERR] at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
      10:25:33,595 ERROR [STDERR] at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
      10:25:33,595 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,595 ERROR [STDERR] at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:300)
      10:25:33,596 ERROR [STDERR] at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
      10:25:33,596 ERROR [STDERR] at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:372)
      10:25:33,596 ERROR [STDERR] at org.jboss.web.WebModule.startModule(WebModule.java:83)
      10:25:33,596 ERROR [STDERR] at org.jboss.web.WebModule.startService(WebModule.java:61)
      10:25:33,596 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
      10:25:33,596 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
      10:25:33,596 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      10:25:33,596 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      10:25:33,596 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,596 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,596 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      10:25:33,596 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      10:25:33,596 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      10:25:33,596 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      10:25:33,596 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,596 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
      10:25:33,596 ERROR [STDERR] at $Proxy0.start(Unknown Source)
      10:25:33,596 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
      10:25:33,596 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
      10:25:33,596 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,597 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      10:25:33,597 ERROR [STDERR] at $Proxy45.start(Unknown Source)
      10:25:33,597 ERROR [STDERR] at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
      10:25:33,597 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
      10:25:33,597 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,597 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
      10:25:33,597 ERROR [STDERR] at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
      10:25:33,597 ERROR [STDERR] at org.jboss.ws.integration.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:93)
      10:25:33,597 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
      10:25:33,597 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,597 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      10:25:33,597 ERROR [STDERR] at $Proxy46.start(Unknown Source)
      10:25:33,597 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
      10:25:33,598 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
      10:25:33,598 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      10:25:33,598 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      10:25:33,598 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
      10:25:33,598 ERROR [STDERR] at $Proxy9.deploy(Unknown Source)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
      10:25:33,598 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
      


      This is the (shortened) code from my TestServlet's init method which should do the mapping:

      
      Context javaCtx = (Context) new InitialContext().lookup("java:");
      // /comp/env/jdbc exists
      Context pseudo = (Context) new InitialContext().lookup("/comp/env/jdbc");
      
      Object dbcon = null;
       try
       {
       dbcon = javaCtx.lookup("dbcons/maindb");
       }
       catch (NamingException e)
       {
       e.printStackTrace();
       }
      
       try
       {
       pseudo.bind("testdb", dbcon); ==== > NullpointerException
       }
       catch (NamingException e)
       {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      


      What I'm doing wrong?

      Thanks for your effort!! Hubert