users@glassfish.java.net

Re: RE: JNDI lookup, dependency injection, datasource

From: <glassfish_at_javadesktop.org>
Date: Tue, 15 Jun 2010 10:54:34 PDT

In the class that I've annotated:

@ManagedBean
@RequestScoped

The following code returns a 'com.sun.gjc.spi.jdbc40.DataSource40' type:

        try
        {
            Context context = new InitialContext();
            DataSource ds = (DataSource)context.lookup( "java:app/env/myDataSource" );
        }
        catch( NamingException e )
        {
            e.getCause();
        }

I need to adjust connection params on the fly (e.g. user/pass/database name, etc...) so I actually need the type I specified in the data-source element returned -- com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource


Secondly, the same code above throws the following exception when run in a JSR-196 Security Authentication Module. Even with java:app specified as the JNDI root. Please advise.

javax.naming.NamingException: Lookup failed for 'java:app/env/myDataSource' in SerialContext [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
[Message sent by forum member 'andrewlaughlin']

http://forums.java.net/jive/thread.jspa?messageID=474365