Tomcat 7 connection pooling error - java

we have move the code on new server, as previously we are using the tomcat6 but on new system installed the tomcat7. so we are getting the below error, i did the googling and make the changes but still getting same error. the error as below.
Sep 21, 2014 6:15:14 PM org.apache.tomcat.jdbc.pool.ConnectionPool abandon
WARNING: Connection has been abandoned PooledConnection[com.mysql.jdbc.JDBC4Connection#2365914f]:java.lang.Exception
at org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1063)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:780)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:619)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
at com.fstl.resellermg.util.DbUtils.getConnection(DbUtils.java:34)
at com.fstl.resellermg.bo.LeadExtBO.getListUploadStatus(LeadExtBO.java:1350)
at com.fstl.resellermg.servlet.GetLeadCountByUserName.doPost(GetLeadCountByUserName.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:193)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
My context.xml configuration is
<Context>
<Resource name="jdbc/testDB"
auth="Container"
type="javax.sql.DataSource"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/xxx"
validationQuery="SELECT 1"
validationInterval="30000"
maxWait="1000"
removeAbandoned="true"
initialSize="10"
maxActive="100"
maxIdle="50"
minIdle="10"
suspectTimeout="60"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
testOnBorrow="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

The error clearly says the connection was abandoned. This means one of two things. Either somewhere in your code, you're not closing the connection properly, or you have a long running query that exceeds the timeout (a minute in your case) so Tomcat wrongly believes it's been abandoned. Make your DB log slow queries, or profile your app to figure out if the latter is the case.

This is working with Tomcat 6 because that version doesn't include timeout functionality. That's why the query is running properly without a timeout.

Related

after 2 days web stopped working but Tomcat still running. Restart of Tomcat fixes issue

I am running Tomcat7 on a provisioning server (Ubuntu OS) to provision devices. Issue is http stops working after couple of more days and when i restart tomcat everything get back on normal.
I've gathered below logs.
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [main] in context with path [/web] threw exception [java.io.IOException: <p>An error occured</p>ClientAbortException: java.net.SocketException: Broken pipe (Write failed)] with root cause
java.io.IOException: <p>An error occured</p>ClientAbortException: java.net.SocketException: Broken pipe (Write failed)
at com.owera.xaps.web.app.Output.deliverHTML(Output.java:455)
at com.owera.xaps.web.app.Output.deliverResponse(Output.java:140)
at com.owera.xaps.web.app.Main.doImpl(Main.java:183)
at com.owera.xaps.web.app.Main.doGet(Main.java:94)
at com.owera.xaps.web.app.Main.doPost(Main.java:84)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.owera.xaps.web.app.security.LoginServlet.doFilter(LoginServlet.java:248)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:748)
Any idea / help
Bill, you will have to analyse thread dumps and will have to go through your application code once. It seems objects are not getting GC.
But before that, to prove this analogy, you can try to double your Memory.
In your catalina.sh/catalina.bat (depending on OS) please try to modify your -Xmx, -Xms and -XX:MaxPermSize and observe if it has any impact on your server uptime.

JDBC tomcat connection pool is not working

Apache tomcat log
Jul 19, 2014 9:31:31 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [FrontController] in
context with path [/GroupFound] threw exception
java.lang.ClassCastException:
org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to
org.apache.tomcat.jdbc.pool.DataSource at
models.bean.Customer.act(Customer.java:32) at
controller.FrontController.processRequest(FrontController.java:40) at
controller.FrontController.doGet(FrontController.java:61) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Error
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at models.bean.Customer.act(Customer.java:33) at
controller.FrontController.processRequest(FrontController.java:40) at
controller.FrontController.doGet(FrontController.java:61) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662) Caused by:
java.lang.NullPointerException at
sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) at
sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) at
sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) at
java.sql.DriverManager.getDriver(DriverManager.java:253) at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 26 more
context.xml
changed from META-INF folder. catalina-home/conf/Catalina/localhost/[projectname].xml also have been changed while changing META-INF copy.
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/GroupFound">
<Resource auth="Container"
defaultReadOnly="false"
driverClassName="com.mysql.jdbc.jdbc2.optional"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
initialSize="0"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
jmxEnabled="true"
logAbandoned="true"
maxActive="300" maxIdle="50"
maxWait="10000"
minEvictableIdleTimeMillis="300000"
minIdle="30"
name="jdbc/testcp"
password=""
removeAbandoned="true"
removeAbandonedTimeout="60"
testOnBorrow="true"
testOnReturn="false"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="30000"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/test"
username="root"
validationInterval="30000"
validationQuery="SELECT 1"/>
</Context>
Web.xml
changed from application context (netbeans IDE)
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>FrontController</servlet-name>
<servlet-class>controller.FrontController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>/jdbc/testcp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Have been trying to fix it from hours. Searched google and similar issues with no success. I am exhausted. How to fix it? I just want to see DataSource working.
Details
JDK 6.1
netbeans 7.2
tomcat 7.0.27
This appears to be the best guide that I can find:
http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
A quick test would be to put it here:
$CATALINA_BASE/conf/context.xml

Tomcat 7.0 Connection pooling - jdbc driver exception

I want to implement connection pooling on my Tomcat server. Here is my context.xml file (placed under WebContent/META-INF/context.xml:
<Context path="/evappserver" reloadable="true">
<Resource
name="jdbc/evapp"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
initialSize="34"
maxActive="377"
maxIdle="233"
minIdle="89"
timeBetweenEvictionRunsMillis="34000"
minEvictableIdleTimeMillis="55000"
validationQuery="SELECT 1"
validationInterval="34"
testOnBorrow="true"
removeAbandoned="true"
removeAbandonedTimeout="55"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/evapp?allowMultiQueries=true"
/>
</Context>
I have a maven project so the mysql jdbc driver is imported via the pom.xml file, like this:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
Here is my java code which throws the exception:
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
dataSource = (DataSource) envContext.lookup("jdbc/evapp"); //here is the exception
Here is the exception:
May 13, 2014 10:39:58 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:702)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:634)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:488)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:539)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:237)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at com.evappserver.dblayer.DBType.<init>(DBType.java:62)
at com.evappserver.dblayer.MySqlDB.<init>(MySqlDB.java:16)
at com.evappserver.logiclayer.BaseLogic.getMainDbConnection(BaseLogic.java:19)
at com.evappserver.logiclayer.PasswordLoginLogic.doLogin(PasswordLoginLogic.java:27)
at com.evappserver.servlets.PasswordLoginServlet.doGet(PasswordLoginServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)
... 38 more
Is there something wrong with this configuration?
I think you should include the driver for MySQL in your tomcat /lib folder instead of deploying it along with your web application. This way the server will find the proper classes to instantiate your connection pool and everything should go fine.
check if the classpath of your project contains the file mysql-connector-java-5.1.6.jar. Did maven run without problems?
I had this same problem. For a reason unknown to me, putting the mysql-connector-java*.jar in WEB-INF/lib no longer works in Ubuntu LTS 14.04
I solved it by copying this file (and this file alone) to /usr/share/tomcat7/lib and restarted tomcat7 as a service service tomcat7 restart and everything sprang to life.
Best of luck

ClassNotFoundException when upgraded to Tomcat 8

I recently upgraded my NetBeans IDE from v7.3 to v8 and all of a sudden my application throws an exception at server startup while connecting to DB. The only difference between these two versions of IDE are that the later one is using Tomcat 8.
Exception Log:
javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:82)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.istore.core.listeners.AppContextListener.initdb(AppContextListener.java:44)
at com.istore.core.listeners.AppContextListener.contextInitialized(AppContextListener.java:27)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5158)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:579)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:455)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1554)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1428)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:885)
at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:343)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1132)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:80)
... 58 more
META-INF/context.xml
<!-- PostgreSQL Datasource -->
<Resource auth="Container" driverClassName="org.postgresql.Driver" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" maxActive="50" maxIdle="10" maxWait="-1" name="jdbc/mydb" type="javax.sql.DataSource" url="jdbc:postgresql://myorg.corp.net:5432/mydb" username="abc" password="def" />
Please guide.
The name of the default factory changed between Tomcat 7 and Tomcat 8. A couple of attribute names also changed. This is all as a result of switching from DBCP 1.x to DBCP 2.x in Tomcat 8. You want the following in your META-INF/context.xml file:
<!-- PostgreSQL Datasource -->
<Resource auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"
maxTotal="50"
maxIdle="10"
maxWaitMillis="-1"
name="jdbc/mydb"
type="javax.sql.DataSource"
url="jdbc:postgresql://myorg.corp.net:5432/mydb"
username="abc"
password="def" />
Since this factory is used by default for resources of type javax.sql.DataSource you can just drop that attribute all together. The other changes were:
maxActive -> maxTotal
maxWait -> maxWaitMillis
You need tomcat-dbcp-8.0.0-RC1.jar in your tomcat8 lib folder. The package structure for org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory in commons-dbcp.jar is different from other tomcat versions.

Could not obtain native oracle connection

Asked in gis.stackexchange: https://gis.stackexchange.com/questions/23412/could-not-obtain-native-oracle-connection
Anyone knows the the cause and how to resolve the "Could not obtain native oracle connection" error?
I'm using GeoTools 2.7.4, a oracle 11g DB, ojdbc14.jar, and a simple java code on a Tomcat 6 like this:
Map map = new HashMap();
map.put( "dbtype", "oracle");
map.put( "jndiReferenceName", "java:comp/env/jdbc/GisDS");
OracleNGJNDIDataStoreFactory factory = new OracleNGJNDIDataStoreFactory();
log.info("Can process? "+ factory.canProcess(map));
store = factory.createDataStore(map);
SimpleFeatureSource featureSource = store.getFeatureSource(viewName);
log.info(featureSource.getFeatures().getBounds().toString());
And my context.xml:
<Resource name="jdbc/GisDS" auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
accessToUnderlyingConnectionAllowed="true"
username="***" password="***"
url="***"
maxActive="25" maxIdle="8" maxWait="10000"
removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
poolPreparedStatements="true" maxOpenPreparedStatements="100"
validationQuery="SELECT SYSDATE FROM DUAL"/>
And I always get the "Could not obtain native oracle connection" error:
java.lang.RuntimeException: java.io.IOException: Error occured calculating bounds
at org.geotools.jdbc.JDBCFeatureSource.getBoundsInternal(JDBCFeatureSource.java:485)
at org.geotools.jdbc.JDBCFeatureStore.getBoundsInternal(JDBCFeatureStore.java:179)
at org.geotools.data.store.ContentFeatureSource.getBounds(ContentFeatureSource.java:370)
at org.geotools.data.store.ContentFeatureCollection.getBounds(ContentFeatureCollection.java:274)
at ***.GisServlet.doGet(GisServlet.java:82)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.IOException: Error occured calculating bounds
at org.geotools.jdbc.JDBCDataStore.getBounds(JDBCDataStore.java:1137)
at org.geotools.jdbc.JDBCFeatureSource.getBoundsInternal(JDBCFeatureSource.java:478)
... 19 more
Caused by: java.sql.SQLException: Could not obtain native oracle connection for class org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
at org.geotools.data.oracle.OracleDialect.unwrapConnection(OracleDialect.java:490)
at org.geotools.data.oracle.OracleDialect.readGeometry(OracleDialect.java:434)
at org.geotools.data.oracle.OracleDialect.readGeometry(OracleDialect.java:424)
at org.geotools.data.oracle.OracleDialect.decodeGeometryEnvelope(OracleDialect.java:371)
at org.geotools.jdbc.JDBCDataStore.getBounds(JDBCDataStore.java:1123)
... 20 more
I've tried to connect to a 10g DB, I've tried using the ojdbc6, and I always end with the same result.
The strange thing is, if I replace the getBounds() with size() it works.

Categories

Resources