2

I am evaluating Quakus as a replacement for a Tomcat environment. I understand the challenges of what I am trying to do, but I first need to validate my existing, legacy JSP application will work using Quarkus. I am using quarkus.undertow as my servlet container.

I've overcome several obstacles thus far. The one I am running into now is how to use my data sources.

Currently, our data sources are set in Tomcat's server.xml as GlobalNamingResources and binding them in the web app's META-INF/context.xml as ResourceLinks.

I've transferred the data source setting to Quarkus' application.properties as such:

quarkus.datasource.menudb.url=jdbc:mysql://some.server.url/menuadmin
quarkus.datasource.menudb.driver=com.mysql.cj.jdbc.Driver
quarkus.datasource.menudb.username=web
quarkus.datasource.menudb.password=<password>

which I understand, from the documentation, is the way to do it. But, the documentation then shows injecting the datasource:

@Inject
@DataSource("users")
AgroalDataSource dataSource1;

In my case, i would replace users with my data source name menudb in the annotation. However, I have data access classes I need to be able to reuse that create the InitialContext, lookup the data source using the JNDI resource name passed in, and creates the data source:

InitialContext ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("java:comp/env/<jndi name>");
conn = ds.getConnection();

This is causing the following error:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.gy.obj.ContextManager.contextInitialized(ContextManager.java:367)
    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:188)
...

Initial research has lead me to Apache Camel, but that, at first glance, does not seem to be an appropriate solution. I've also read about setting a jndi.properties as so:

# Needed env settings for JNDI.
java.naming.factory.initial=<Some JNDI Service Provider Name>

But I am not certain which provider to use and as of now can't seem to locate documentation on the various providers.

My question is, am I at least on the right track and what provider would I use? I would really not like to touch my existing data access classes to provide injection, if I do not have too. However, I would not be opposed to such as what we currently have configured works for Tomcat.

1 Answer 1

6

JNDI is intentionally not supported, as we consider it an unnecessary complexity which is not useful in the Quarkus model: there are no runtime deployments and all code is known at build time so there's no need for such decoupling.

The solution is simple: just adapt the code to not look it up from the JDNI context but look it up from the CDI bean manager.

While we're able to support most high level APIs, it should be easy to port existing applications but don't assume that all legacy technologies will be provided - it's a good time to get rid of some and move on.

That said I supposed JNDI could easily be emulated, but so far we'd prefer to avoid that; feel free to open an issue if this is very important to you.

3
  • Hi Sanne, Could you help me emulate JNDI in quarkus? I 'm using pentaho reports and all of them are using JNDI to connect to database, I'm trying to avoid change all the .prpt reports connection anytime the database connection changes. So this way i will just change that in quarkus and all my reports will not be affected Thanks in advance Apr 20, 2022 at 17:10
  • I've used Pentaho in the past but it's been many years; we'll need some more details - hopefully Pentaho offers alternative binding options. Please open an issue on the Quarkus tracker? Would be great to have some more details and ideally an example we can run & explore.
    – Sanne
    Apr 21, 2022 at 8:09
  • I opened a discution there some days ago github.com/quarkusio/quarkus/discussions/25039. I will open a issue as you requested , thanks a lot for your help Apr 22, 2022 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.