从 Jython 上的 Django 应用程序进行 JNDI 访问

发布于 2024-08-22 08:18:37 字数 171 浏览 2 评论 0原文

是否可以从 Jython 上运行的 Django 应用程序访问 Tomcat 配置中的 JNDI 值?

我的配置有一个可通过 JDNI 访问的 Web 服务 URL,我需要在运行时进入 Django 应用程序。它不是数据库连接,只是 Web 服务部署的 URL。它可能位于也可能不在同一个 Tomcat 实例上。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撧情箌佬 2024-08-29 08:18:37

是的,您可以: http://packages.python.org /django-jython/database-backends.html#jndi-support

(只要 django-jython 支持底层数据库引擎。目前是 PostgreSQL、MySQL 和 Oracle)

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)

虐人心 2024-08-29 08:18:37

谢谢 Leo,我追求的不是数据库连接,而是 Web 服务的 URL。

我通过以下方法进行了管理:

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"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文