开发者

JNDI Access from a Django app on Jython

开发者 https://www.devze.com 2022-12-21 03:07 出处:网络
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 runtim

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. 开发者_StackOverflowIt'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.


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)


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消