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.