For a Liferay 6.2 user portlet that accesses an Oracle database without liferay, we encounter a problem when the returned data source is null.
We configured the tomcat / conf / context.xml file
<Resource name="jdbc/NewPool" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dbservernameorip)(PORT = 9999)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbSIDorservicename)))" username="user" password="pwd" maxActive="35" maxIdle="10" maxWait="20000" removeAbandoned="true" logAbandoned="true" minEvictableIdleTimeMillis="3600000" timeBetweenEvictionRunsMillis="1800000" testOnBorrow="true" testOnReturn="false" />
The web.xml portlet contains:
<resource-ref> <description>Oracle Datasource example</description> <res-ref-name>jdbc/NewPool</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Search Code:
String JNDI = "jdbc/NewPool" _log.debug("JNDI Name is: " + JNDI); _log.debug("dataSource in dbConnect is :" + dataSource); Context context = new InitialContext(); Context envContext = (Context)context.lookup("java:/comp/env"); _log.debug("envContext in dbConnect is :" + envContext); try { DataSource ds = (DataSource)envContext.lookup(JNDI);
Liferay can successfully use the context.xml resource with a similar data source for the Oracle Liferay database.
Is any other wiring required for the Liferay portlet to establish a connection to another database?
The same portlet code works in weblogic without changing web.xml. A similar search and configuration code for the JNDI data source runs on vanilla tomcat (without liferay) and a simple war file (non liferay portlet).
Update:
I checked db connections on server with netstat -an | grep dbport. it does not show the established connection.
I also tried setting portal.security.manager.strategy = none in portal -ext.properties. That didn't work either.
Any insight is greatly appreciated as we are stuck here.
Thanks!
source share