6 Replies Latest reply on May 21, 2003 11:13 AM by Vyacheslav Zheltonogov

    Dynamic Databas Connection mBean

    Vyacheslav Zheltonogov Newbie

      Hi,

      I'm sorry if this has been discussed already and I couldn't find in this forum. I'm trying to figure it out how to write a mBean that would be creating a db connection pool on the fly based on the info gotten at the login time. The app has the only static predefined connection to the system schema. Based on the user's login, the app determines the login info (user_name/password@service) for the user's business schema.

      Our app has been written for Weblogic WL 7.0 I ported it to JBoss 3.0.7, Oracle is back-end, running on Windows. Under WL 7.0 it's been using proprietary WL classes (mBean) that create dynamic db connection based on the provided user_name/password@service. Now I'm trying to write the same thing, mBean that would provide db connection pool at runtime.

      I was wondering if there are any examples or someone has already done something like that?

      Thank you,

      Slava

        • 1. Re: Dynamic Databas Connection mBean
          David Jencks Master

          Sorry, but I can't understand if you are trying to connect to many database instances or trying to connect as many users to one database instance.

          -- many database instances, one per user.
          a. (not so easy) Look at the testsuite jca module (might be jmx, I can't remember) at the DeployConnectionManagerUnitTestCase. It has example code to set up and start a datasource.
          b. Switch to 3.2, generate a *-ds.xml on the fly and deploy it by calling the MainDeployer.
          c. Write a custom login module that includes additional information about the target db in the Subject it supplies, and modify the jca ManagedConnectionFactory to connect to the database specified in the subject. (I believe at least one person has used this approach)

          -- one database, many user accounts. Use the CallerIdentityLoginModule or write a mapping login module and use ContainerManagedSecurity.

          • 2. Re: Dynamic Databas Connection mBean
            Vyacheslav Zheltonogov Newbie

            My case is the first one - many database schemas, one per client (every client might have more than one user).

            I'm looking at the DeployConnectionManagerUnitTestCase example. Looks like it's exactly what I need, thank you very much.

            But since I'm planning to switch to 3.2 anyway, I'm curious what is the best way to generate the oracle-ds.xml file on-the-fly?

            • 3. Re: Dynamic Databas Connection mBean
              David Jencks Master

              Well, the *-ds.xml isn't that long, you just have to replace the jndi name and the db url, so you could just concatenate strings. You can also use something like dom4j to construct an xml object model, but I think that would be more work.

              The most straightforward approach would be to save the string as a file and deploy it based on a file: url. It might be possible to do this entirely in memory, by constructing a DeploymentInfo mbean instance and setting the Document directly.

              • 4. Re: Dynamic Databas Connection mBean
                Vyacheslav Zheltonogov Newbie

                Hi,

                I reproduced an example connection manager from the DeployConnectionManagerUnitTestCase class. Everything makes sence. Now when I ran my app I got the following error below. I did some research on the net and I found this class was failed previously on the same spot. The info was found in the JBoss mail-archive (here is a reference to that http://www.mail-archive.com/jboss-development@lists.sourceforge.net/msg31836.html//www.mail-archive.com/jboss-development@lists.sourceforge.net/msg31836.html)

                I was wondering if you got a chance to take a look at it and you could tell me what's wrong with the code.

                Thank you again
                Slava
                <--------->
                17:20:09,434 INFO [JBossManagedConnectionPool] Creating
                17:20:09,434 INFO [JBossManagedConnectionPool] Created
                17:20:09,434 INFO [JBossManagedConnectionPool] Starting
                17:20:09,434 INFO [JBossManagedConnectionPool] Started
                17:20:09,434 INFO [LocalTxConnectionManager] Creating
                17:20:09,454 INFO [LocalTxConnectionManager] Created
                17:20:09,464 INFO [LocalTxConnectionManager] Starting
                17:20:09,464 ERROR [LocalTxConnectionManager] Starting failed
                java.lang.NullPointerException
                at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:258)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at org.jboss.mx.loading.UnifiedClassLoader.loadClassLocally(UnifiedClass
                Loader.java:229)
                at org.jboss.mx.loading.UnifiedLoaderRepository3.loadClassFromClassLoade
                r(UnifiedLoaderRepository3.java:217)
                at org.jboss.mx.loading.LoadMgr.beginLoadTask(LoadMgr.java:130)
                at org.jboss.mx.loading.UnifiedClassLoader3.loadClass(UnifiedClassLoader
                3.java:161)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:566)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
                at org.mortbay.http.ContextLoader.loadClass(ContextLoader.java:215)
                at org.mortbay.http.ContextLoader.loadClass(ContextLoader.java:199)
                at org.jboss.resource.connectionmanager.RARDeployment.startManagedConnec
                tionFactory(RARDeployment.java:540)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.resource.connectionmanager.BaseConnectionManager2.startServ
                ice(BaseConnectionManager2.java:382)
                at org.jboss.resource.connectionmanager.LocalTxConnectionManager.startSe
                rvice(LocalTxConnectionManager.java:179)
                at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:1
                65)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceControl
                ler.java:1003)
                at $Proxy87.start(Unknown Source)
                at org.jboss.system.ServiceController.start(ServiceController.java:413)
                at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl.invoke(RMIAdaptorImpl.java:2
                83)
                at com.pricewaterhousecoopers.elke.online.PoolValidationBE.createDynamic
                Pool(PoolValidationBE.java:231)
                at org.apache.jsp.Login$jsp._jspService(Login$jsp.java:92)
                at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
                vlet.java:201)
                at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
                81)
                at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360
                )
                at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati
                onHandler.java:280)
                at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5
                53)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)
                at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication
                Context.java:549)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)
                at org.mortbay.http.HttpServer.service(HttpServer.java:862)
                at org.jboss.jetty.Jetty.service(Jetty.java:497)
                at org.mortbay.http.HttpConnection.service(HttpConnection.java:759)
                at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:923)
                at org.mortbay.http.HttpConnection.handle(HttpConnection.java:776)
                at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
                202)
                at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
                at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
                17:20:09,474 WARN [ServiceController] Problem starting service jboss.jca:servic
                e=LocalTxCM,name=555/DS
                java.lang.NullPointerException
                at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:258)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at org.jboss.mx.loading.UnifiedClassLoader.loadClassLocally(UnifiedClass
                Loader.java:229)
                at org.jboss.mx.loading.UnifiedLoaderRepository3.loadClassFromClassLoade
                r(UnifiedLoaderRepository3.java:217)
                at org.jboss.mx.loading.LoadMgr.beginLoadTask(LoadMgr.java:130)
                at org.jboss.mx.loading.UnifiedClassLoader3.loadClass(UnifiedClassLoader
                3.java:161)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
                at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:566)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
                at org.mortbay.http.ContextLoader.loadClass(ContextLoader.java:215)
                at org.mortbay.http.ContextLoader.loadClass(ContextLoader.java:199)
                at org.jboss.resource.connectionmanager.RARDeployment.startManagedConnec
                tionFactory(RARDeployment.java:540)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.resource.connectionmanager.BaseConnectionManager2.startServ
                ice(BaseConnectionManager2.java:382)
                at org.jboss.resource.connectionmanager.LocalTxConnectionManager.startSe
                rvice(LocalTxConnectionManager.java:179)
                at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:1
                65)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceControl
                ler.java:1003)
                at $Proxy87.start(Unknown Source)
                at org.jboss.system.ServiceController.start(ServiceController.java:413)
                at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl.invoke(RMIAdaptorImpl.java:2
                83)
                at com.pricewaterhousecoopers.elke.online.PoolValidationBE.createDynamic
                Pool(PoolValidationBE.java:231)
                at org.apache.jsp.Login$jsp._jspService(Login$jsp.java:92)
                at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
                vlet.java:201)
                at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
                81)
                at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360
                )
                at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati
                onHandler.java:280)
                at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5
                53)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)
                at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication
                Context.java:549)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)
                at org.mortbay.http.HttpServer.service(HttpServer.java:862)
                at org.jboss.jetty.Jetty.service(Jetty.java:497)
                at org.mortbay.http.HttpConnection.service(HttpConnection.java:759)
                at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:923)
                at org.mortbay.http.HttpConnection.handle(HttpConnection.java:776)
                at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
                202)
                at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
                at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
                17:20:09,544 WARN [jbossweb] WARNING: Exception for /elke/elke/jsp/Login.jsp
                RuntimeMBeanException: RuntimeException in MBean operation 'setManagedConnection
                FactoryAttribute(,java.lang.String,java.lang.Class,java.lang.Object)'
                Cause: java.lang.NullPointerException
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:299)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl.invoke(RMIAdaptorImpl.java:2
                83)
                at com.pricewaterhousecoopers.elke.online.PoolValidationBE.createDynamic
                Pool(PoolValidationBE.java:237)
                at org.apache.jsp.Login$jsp._jspService(Login$jsp.java:92)
                at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
                vlet.java:201)
                at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
                81)
                at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360
                )
                at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati
                onHandler.java:280)
                at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5
                53)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)
                at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication
                Context.java:549)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)
                at org.mortbay.http.HttpServer.service(HttpServer.java:862)
                at org.jboss.jetty.Jetty.service(Jetty.java:497)
                at org.mortbay.http.HttpConnection.service(HttpConnection.java:759)
                at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:923)
                at org.mortbay.http.HttpConnection.handle(HttpConnection.java:776)
                at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
                202)
                at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
                at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
                getTargetException():
                java.lang.NullPointerException
                at org.jboss.resource.connectionmanager.RARDeployment.setManagedConnecti
                onFactoryAttribute(RARDeployment.java:660)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                nDispatcher.java:284)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
                at org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl.invoke(RMIAdaptorImpl.java:2
                83)
                at com.pricewaterhousecoopers.elke.online.PoolValidationBE.createDynamic
                Pool(PoolValidationBE.java:237)
                at org.apache.jsp.Login$jsp._jspService(Login$jsp.java:92)
                at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
                vlet.java:201)
                at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
                81)
                at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360
                )
                at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati
                onHandler.java:280)
                at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5
                53)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)
                at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication
                Context.java:549)
                at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)
                at org.mortbay.http.HttpServer.service(HttpServer.java:862)
                at org.jboss.jetty.Jetty.service(Jetty.java:497)
                at org.mortbay.http.HttpConnection.service(HttpConnection.java:759)
                at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:923)
                at org.mortbay.http.HttpConnection.handle(HttpConnection.java:776)
                at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
                202)
                at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
                at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)

                • 5. Re: Dynamic Databas Connection mBean
                  David Jencks Master

                  Are you sure you copied a version of the test for the jboss version you are running? It looks like the name of the class of the managed connection factory is not supplied to the classloader.

                  This method of setting up the mbeans and starting them is somewhat different for each jboss version and is likely to continue to change in the future. Using a *-ds.xml file is more likely to be stable.

                  • 6. Re: Dynamic Databas Connection mBean
                    Vyacheslav Zheltonogov Newbie

                    Yes, I'm pretty sure I've used an example from 3.07 version the one I'm running right now. That's too bad, because this would've perfect solution for me.

                    Well, I'm going to try 3.2.1 now with *-ds.xml deploying.

                    Thank you