DB Object getting JNDI connection doesnt work
Hello. I try to use Lift 2.4-M4 Scala 2.9.1.
In Boot.scala i add such code:
DefaultConnectionIdentifier.jndiName = "jdbc/db"
logger.warn("JNDI connection available (manyally) ? " + (((new
InitialContext).lookup("java:/comp/env/jdbc/
db").asInstanceOf[DataSource]) != null))
logger.warn("JNDI connection available (lift) ? " +
DB.jndiJdbcConnAvailable_?)
And in logs i see:
10:56:55.531 [main] WARN bootstrap.liftweb.Boot - JNDI connection
available (manyally) ? true
10:56:55.546 [main] WARN bootstrap.liftweb.Boot - JNDI connection
available (lift) ? false
10:56:55.718 [ForkJoinPool-1-worker-2] INFO
o.a.sshd.common.util.SecurityUtils - BouncyCastle not registered,
using the default JCE provider
2011-09-12 10:56:55.953:INFO:oejs.AbstractConnector:Started
SelectChannelConnector@0.0.0.0:8080 STARTING
Therefore i cannot use jndi with DB object. Can anyone suggest
workaround or said where i can be wrong?
For me problems in two methods:
def jndiJdbcConnAvailable_? : Boolean = {
try {
((new InitialContext).lookup("java:/comp/
env").asInstanceOf[Context].lookup(DefaultConnectionIdentifier.jndiName).asInstanceOf[DataSource].getConnection) !
= null
} catch {
case e => false
}
}
And
private def newConnection(name: ConnectionIdentifier): SuperConnection
= {
...
val conn = (new InitialContext).lookup("java:/comp/
env").asInstanceOf[Context].lookup(name.jndiName).asInstanceOf[DataSource].getConnection
....
ret.setAutoCommit(false)
ret
}
Forgot to add that i use xsbt 0.10.1 and Jetty 8 from Eclipse. I test
JNDI with java web application and it works.
I test application on Oracle Application Server 11g and get such logs:
JNDI connection available (lift) ? true
JNDI connection available (manyally) ? true
With glassfish 3.1 i get such results:
JNDI connection available (manyally) ? - instead of this i got exception
JNDI connection available (lift) ? false
For glassfish need to lookup in such way:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/sample");
In Boot.scala i add such code:
DefaultConnectionIdentifier.jndiName = "jdbc/db"
logger.warn("JNDI connection available (manyally) ? " + (((new
InitialContext).lookup("java:/comp/env/jdbc/
db").asInstanceOf[DataSource]) != null))
logger.warn("JNDI connection available (lift) ? " +
DB.jndiJdbcConnAvailable_?)
And in logs i see:
10:56:55.531 [main] WARN bootstrap.liftweb.Boot - JNDI connection
available (manyally) ? true
10:56:55.546 [main] WARN bootstrap.liftweb.Boot - JNDI connection
available (lift) ? false
10:56:55.718 [ForkJoinPool-1-worker-2] INFO
o.a.sshd.common.util.SecurityUtils - BouncyCastle not registered,
using the default JCE provider
2011-09-12 10:56:55.953:INFO:oejs.AbstractConnector:Started
SelectChannelConnector@0.0.0.0:8080 STARTING
Therefore i cannot use jndi with DB object. Can anyone suggest
workaround or said where i can be wrong?
For me problems in two methods:
def jndiJdbcConnAvailable_? : Boolean = {
try {
((new InitialContext).lookup("java:/comp/
env").asInstanceOf[Context].lookup(DefaultConnectionIdentifier.jndiName).asInstanceOf[DataSource].getConnection) !
= null
} catch {
case e => false
}
}
And
private def newConnection(name: ConnectionIdentifier): SuperConnection
= {
...
val conn = (new InitialContext).lookup("java:/comp/
env").asInstanceOf[Context].lookup(name.jndiName).asInstanceOf[DataSource].getConnection
....
ret.setAutoCommit(false)
ret
}
Forgot to add that i use xsbt 0.10.1 and Jetty 8 from Eclipse. I test
JNDI with java web application and it works.
I test application on Oracle Application Server 11g and get such logs:
JNDI connection available (lift) ? true
JNDI connection available (manyally) ? true
With glassfish 3.1 i get such results:
JNDI connection available (manyally) ? - instead of this i got exception
JNDI connection available (lift) ? false
For glassfish need to lookup in such way:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/sample");
Leave a comment
on 2011-09-19 07:58 *
By jeppenejsum
Assigned to set to jeppenejsum
Status changed from Invalid to Accepted
(In revision:d9c6e7c10b44c7581792419e99360f4007ee02b0) Added more methods for looking up a connection using JNDI, compatible with Glassfish.
Added diagnostic logging related to connections.
Closes #1115
Branch: master
Added diagnostic logging related to connections.
Closes #1115
Branch: master