views:

77

answers:

2

Is it possible to access a JNDI value from Tomcat's config from a Django app running on Jython?

My config has a web service URL, accessible via JDNI, that I need to get into the Django App at runtime. It's not a database connection, it's just the URL to a web service deployment. It might or might not be on the same Tomcat instance.

A: 

Yes, you can: http://packages.python.org/django-jython/database-backends.html#jndi-support

(As long as the underlying database engine is supported by django-jython. Right now PostgreSQL, MySQL and Oracle)

Leo Soto
A: 

Thanks Leo, I wasn't after a database connection, but the URL of a web service.

I managed it with the following:

try:
    from javax.naming import InitialContext
    lContext = InitialContext()
    lLookupURI = "java:comp/env/%s" % "WarFileName";
    lWsUrl = lContext.lookup(lLookupURI);
    lRegEx = 'http://(\w+:\d+)/WarFileName'
    lMatches = re.match(lRegEx, lWsUrl) 
    lHostPort = lMatches.group(1).strip()
except:
    lHostPort = "localhost:8080"
Tim