After deploy mi javaweb (war) app, not maven, in heroku i get the next error:
https://imgur.com/a/KThbLxa
Obviusly it´s because is not making the connection to the JNDI
context.xml
<Resource name="jdbc/conexion" auth="Container" type="javax.sql.DataSource" maxActive="30"
maxIdle="10" maxWait="15000" username="XXXXXXXXX" password="XXXXXXXXXXX" driverClassName="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://XXXXXXXXXX/XXXXXXXXXXXXXX"/>
So, somebody knows how includes a context.xml file in the deployed project?
Related
A Java Servlet-jsp app running on on-premise hardware is to be migrated to pivotal cloud PaaS.
Currently, the app takes DB credentials from server.xml of Tomcat and the resource is added in the context.xml.
This is the context.xml
<ResourceLink name="jdbc/db"
global="jdbc/db"
auth="Container"
type="javax.sql.DataSource" />
This is server.xml
<Resource name="jdbc/db"
global="jdbc/db"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://HOST:3306/db"
username="..."
password="..."
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
How can I pass the Credentials to the server? Is there any standard way to pass DB credentials for PaaS applications?
Your Spring Boot application will be packaged as an executable JAR. It'll have an application.yml file inside it that contains your database connection credentials.
You can also configure your data source as a Pivotal Cloud Foundry service. That way the credentials are added to the cloud. Your app simply refers to them.
I'm very confused why this isn't working. The environment is a Liferay 6.1 instance with Tomcat 7 and the database is NOT the default database from Liferay. It's a secondary server that is used for data. So I'm not sure if that matters with Liferay or not.
web.xml (located in webapps/conf in Tomcat)
<web-app>...
<resource-ref>
<description>My database</description>
<res-ref-name>jdbc/xxx</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
server.xml (located in webapps/conf in Tomcat)
<GlobalNamingResources>
<Resource name="jdbc/xxx" auth="Container" type="javax.sql.DataSource" username="a" password="y" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/xxx"
maxActive="200" maxIdle="25" />
</GlobalNamingResources>
context.xml (located in webapps/conf in Tomcat)
<context>
<ResourceLink global="jdbc/xxx" name="jdbc/xxx" type="javax.sql.DataSource" />
</context>
Code:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/xxx");
Connection conn = ds.getConnection();
Error:
2016-12-21 19:13:04 FATAL asdasdsd:128 - Exception thrown in (removed):
javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/xxx] is not bound in this Context. Unable to find [java:comp].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
What am I missing?
Edit:
Also confirmed the following:
mysql connector is in the path
same jar is in the classpath of the portlet
Second Edit:
I created a brand new, fresh dynamic web application project with the same configuration and DAO layer and it worked 100%. I have a feeling it's related to Liferay now. Unfortunately..
Third Edit:
Tried everything, including this article: http://www.journaldev.com/2513/tomcat-datasource-jndi-example-java
This didn't work either. Same exception. The lack of information about this issue on the Liferay website is amazing to me. Documentation appears to be very much lacking.
For anyone that this helps in the future, because boy was this a pain and not well documented.
I had to add this to the portlet-ext.properties of the Liferay application:
portal.security.manager.strategy=none
Once I found this link: Liferay/Tomcat "hot-deploy" closes JNDI connection, how can I keep it open?
It ended up solving my problem.
The other solution would be (It works for me), Remove the resource-ref from web.xml, remove the Resource from server. xml and remove ResourceLink from context.xml.
Add the resource alone to context.xml,
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/xxx" password="" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/xxx" username=""/>
Code (java:comp/env/ is required in this case):
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/xxx");
Connection conn = ds.getConnection();
I am working on a tomcat 7 webapp that I recently inherited. We are working on migrating from Tomcat 5.5.
The webapp uses a tomcat realm to handle a combination of ldap/sql authentication.
When I define my context.xml as follows
<Context docBase="*******" reloadable="false">
<Realm className="com.******.tomcat.auth.LdapSqlRealm"
****
/>
<Resource name="jdbc/*****"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="60000"
maxActive="15"
maxIdle="15"
maxWait="30000"
initialSize="10"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="60000"
numTestsPerEvictionRun="2"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="*****"
password="*****"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="*****"
/></Context>
I can see my realm initializing in the logs, but when I go to authenticate (using basic) it doesn't use my realm.
If I define the realm in the server.xml file it works just fine.
Any thoughts on why I can't define it in the context.xml.
Our context.xml file is actually located in cont/Catalina/localhost/*****.xml
I have tried starting from scratch with simple realms, or extensions of RealmBase and they all do the same thing.
Thanks,
Travis
Turns out that I had an extra <Context /> tag in my <Host /> tag in my server.xml which was messing up my context.xml file.
Little Santi tipped me off by suggesting a vanilla build of tomcat, which I didn't end up doing, but I did a compare of server.xml from the two and spotted the issue right away. Wish I had thought of it sooner.
I add to pom.xml tomcat embedded and his created in the target folder. I don't know how to configure jndi in tomcat, in target/tomcat/conf i don't have contex.xml when i manually created it and add
<Resource name="jdbc/MyDB"
global="jdbc/MyDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:orcl"
username="hr"
password="oracle"
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
and clean maven project everything disappear. Where to put configuration file in maven project and how to properly configure it.
On one developer workstation running Eclipse Helios SR2, Windows 7 and Tomcat 6.0.32 we have a very strange case of duplicate JNDI connection pools
Running tomcat from Eclipse
server.xml
>
<Context docBase="path to web app" path="/ds-web" reloadable="true">
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
</Context>
When start server, on the console we see the following 3 times in a row
AbandonedObjectPool is used
(org.apache.commons.dbcp.AbandonedObjectPool#11aa58b)
LogAbandoned: true
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
Application then fails to find the JNDI resource
If we remove the <Resource> in server.xml, then the console shows no connection pool is created at all
On another developer machine with the same hardware and OS we do not have this problem
Any ideas?
Thanks
Marc
My suggestion, Copy the whole <Context> from server.xml and create a blank context.xml inside your web application META-INF folder and paste the <Context> copied from server.xml there.
Restart your application and see if this works.
We re-installed postgresql on the machine and the problem got solved somehow.
We're thinking something in the original postgresql config had been messed up and tomcat was failing to connect to the BD somehow. I guess tomcat was simply "trying 3 times", thus the triple output.
Another unsolved mystery...
move
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
to server.xml namely the
<GlobalNamingResources>
element
in your conf/context.xml file you would instead specify
<ContextLink name="jdbc/ds" global="jdbc/ds"/>
and this way, the three contexts will share the same pool.