You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John MccLain <jm...@tcshealthcare.com> on 2005/05/03 01:23:05 UTC

Question on JNDI configuration

Is it possible to add a datasource to JNDI AFTER the server has started? We
have a webapp that creates a DbConnection pool AFTER first user
authentication. I would like to access this pool via JNDI conventions
(because of 3rd party requirements), as well as through a context variable.

John McClain
Senior Software Engineer
TCS Healthcare
jmcclain@tcshealthcare.com
(530)886-1700x235
"Before you criticize someone, walk a mile in their shoes.
That way, you'll be a mile from them, and you'll have their shoes."


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Question on JNDI configuration

Posted by QM <qm...@brandxdev.net>.
On Mon, May 02, 2005 at 04:23:05PM -0700, John MccLain wrote:
: Is it possible to add a datasource to JNDI AFTER the server has started?

If you create the DataSource yourself, yes, you can bind it.

I had to test the same thing tonight, so I'll share an excerpt of my
stub code.  The short story is, get the InitialContext and call bind().

IIRC, java:comp/env isn't writable, but any other path should be...


  public void contextInitialized(ServletContextEvent sce) {

    try{

      // "StoreMe" is a serializable class created just
      // for this experiment...

      final String bindPath = "/some/SomeObject" ;
      final StoreMe original = new StoreMe() ;
      original.setProperty1( "x" ) ;
      original.setProperty1( "Z" ) ;
      
      Context ctx = new InitialContext() ;

      ctx.bind( "/some" , new InitialContext() ) ;
      ctx.bind( bindPath , original ) ;

      StoreMe fromJndi = (StoreMe) ctx.lookup( bindPath ) ;
      log.info( "Do the objects match? " + original.equals( fromJndi ) ) ;
      
      
    }catch( final Exception rethrow ){
      log.error( rethrow ) ;

      // yank the context if this fails...
      throw( new RuntimeException( rethrow ) ) ;
    }

  } // contextInitialized()


-QM

-- 

software   -- http://www.brandxdev.net/
tech news  -- http://www.RoarNetworX.com/
code scan  -- http://www.JxRef.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Question on JNDI configuration

Posted by Will Hartung <wi...@msoft.com>.
> From: "John MccLain" <jm...@tcshealthcare.com>
> Sent: Monday, May 02, 2005 4:23 PM

> Is it possible to add a datasource to JNDI AFTER the server has started?
We
> have a webapp that creates a DbConnection pool AFTER first user
> authentication. I would like to access this pool via JNDI conventions
> (because of 3rd party requirements), as well as through a context
variable.

Have you tried simply binding it after you've created it? I think it's
writable.

Are you creating user specific DBPools, and using JNDI as a global name
space for the 3rd party app (passing in the context name key for them to
look it up)?

Context ctx = new InitialContext();
ctx.bind("yourDBPool", getNewDBPool());

Can you leverage a Custom Resource Factory to do this for you (assuming
simply binding it doesn't work)?

Regards,

Will Hartung
(willh@msoft.com)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org