Dear Felix,
Thank you for your reply. The connector jar file is at
C:\Program Files\apache-tomcat-10.1.24\lib\mysql-connector-j-8.4.0.jar
The latest entry in catalina.2024-06-17.log is copied below. The latest entry
in localhost.2024-06-17.log is copied after that. The two entries are
essentially identical.
The cause of the failure is reported as
Caused by: java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource.getJsonCountries(HolidaysRestJsonWebServiceResource.java:56)
However, this is turn is caused by the failure reported in my previous email on
the line
dataSource = (DataSource) ctx.lookup("jdbc/holidays");
in a file called DataSourceSingleton.java, which is invoked by the
getJsonCountries method. The method is supposed to extract a list of countries
from the database, but the list is returned as null since the JNDI lookup
fails. I identified this failure by putting print statements immediately
before and after this line. The statement before the line outputs its message,
and the one after this line does not. You can see this in the Command Prompt
where Tomcat is running. I copied this error message in my previous email.
Dan Schwartz
----------------------------------------------------------------------------------------------------------
catalina.2024-06-17.log:
-----------------------
17-Jun-2024 15:43:06.184 SEVERE [http-nio-8080-exec-1]
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse Error while
closing the output stream in order to commit response.
org.glassfish.jersey.server.ContainerException:
java.util.concurrent.ExecutionException: java.lang.NullPointerException: Cannot
invoke "javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
org.glassfish.jersey.servlet.internal.ResponseWriter.getResponseContext(ResponseWriter.java:278)
at
org.glassfish.jersey.servlet.internal.ResponseWriter.writeResponseStatusAndHeaders(ResponseWriter.java:128)
at
org.glassfish.jersey.server.ServerRuntime$Responder$1.getOutputStream(ServerRuntime.java:667)
at
org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:171)
at
org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:276)
at
org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:232)
at
org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:247)
at
org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:865)
at
org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:403)
at
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:749)
at
org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:385)
at
org.glassfish.jersey.server.ServerRuntime$Responder.processResponseWithDefaultExceptionMapper(ServerRuntime.java:633)
at
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:458)
at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240)
at
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
at
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:357)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:663)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.util.concurrent.ExecutionException:
java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
at
java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
at
org.glassfish.jersey.servlet.internal.ResponseWriter.getResponseContext(ResponseWriter.java:276)
... 48 more
Caused by: java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource.getJsonCountries(HolidaysRestJsonWebServiceResource.java:56)
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource$Proxy$_$$_WeldClientProxy.getJsonCountries(Unknown
Source)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:146)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:189)
at
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:93)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261)
... 35 more
---------------------------------------------------------------------------------------------------------
localhost.2024-06-17.log:
------------------------
17-Jun-2024 15:43:06.199 SEVERE [http-nio-8080-exec-1]
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for
servlet
[com.worldholidaysandevents.restjsonwebservice.RestJsonWebServiceApplication]
in context with path [/RestJsonWebService-1.0-SNAPSHOT] threw exception
[java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null] with
root cause
java.lang.NullPointerException: Cannot invoke
"javax.sql.DataSource.getConnection()" because "this.dataSource" is null
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource.getJsonCountries(HolidaysRestJsonWebServiceResource.java:56)
at
com.worldholidaysandevents.restjsonwebservice.HolidaysRestJsonWebServiceResource$Proxy$_$$_WeldClientProxy.getJsonCountries(Unknown
Source)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:146)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:189)
at
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:219)
at
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:93)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
at
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
at
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:261)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
at
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:240)
at
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:697)
at
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
at
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:357)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:311)
at
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:663)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
-----Original Message-----
From: Felix Schumacher <[email protected]>
Sent: Wednesday, June 19, 2024 1:41 AM
To: Tomcat Users List <[email protected]>
Subject: Re: Tomcat MySQL Connection Pooling JNDI lookup
Am 17. Juni 2024 22:18:53 MESZ schrieb Daniel Schwartz
<[email protected]>:
>Hello,
>
>
>
>I'm trying to set up MySQL 8.0.11 database connection pooling in Tomcat
>10.1.24 on Windows 10. The MySQL database is "holidays" with user name
>"root" and password "rootpwd". I've tried to follow the examples at
>https://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto
>.html
>#MySQL_DBCP_2_Example.
>
>
>
>Attached are my files context.xml, which I put in the Tomcat conf
>directory, and web.xml, which I put in my project WEB-INF directory.
>Also attached is my file DataSourceSingleton.java, which is the program
>file that crashes on the line
>
>
>
> dataSource = (DataSource) ctx.lookup("jdbc/holidays");
>
>
>
>producing the error message
>
>
>
> javax.naming.NameNotFoundException: Name [jdbc/holidays] is not
>bound in this Context. Unable to find [jdbc].
>
>
>
>in the Command Prompt where Tomcat is running. I must be missing some
>little thing. Can anyone help?
Have you added the MySQL jar to your installation? Where did you place it?
Are there any error messages in catalina.out and/or localhost_<date>.log files?
Felix
>
>
>
>Dan Schwartz
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]