Deployed Tomcat 6 webapp can't connect to Amazon RDS Oracle instance - java

We are building a Java Spring-based web application that accesses an Oracle backend via Hibernate.
Here is our stack/tools:
Tomcat 6
Maven 3
Spring (mvc, web, orm) 3.2.0
Hibernate 4.1.9
Oracle 11g Release 2
Intellij IDEA.
To access the RDS from our local machines, we are port forwarding localhost:2521 to our-rds-instance-name.wercytsdzeszx.us-east-1.rds.amazonaws.com:1521
We are running embedded Tomcat using the tomcat6-maven-plugin. Our Maven configuration for testing is clean package tomcat6:run-war-only. This will deploy the WAR file to http://app.local:8080/our-app-name/ and allow us to test the site through this link.
Using Hibernate, we can connect successfully to the RDS instance when we are running the web app from our local embedded Tomcat instances.
HOWEVER - this is where it gets stupid - when we deploy the WAR file to our EC2 instance (which is part of a security group that has access to the RDS instance), the application can no longer access the database. We receive this error:
org.hibernate.exception.GenericJDBCException: Could not open connection
This is boggling my mind. We have installed SQLPlus on our EC2 instance running Tomcat and we can connect to the RDS instance, so the EC2 instance does have access to connect to the RDS instance.
Our local connection string would look something like this:
*jdbc:oracle:thin:USER_NAME/password#localhost:2521/sid*
Our EC2 (staging) instance connection string would look like this:
*jdbc:oracle:thin:USER_NAME/password#our-rds-instance-name.wercytsdzeszx.us-east-1.rds.amazonaws.com:1521/sid*
I can provide more details, but I first wanted to get the main problem out there so I don't muddy the waters with useless information.
I appreciate all feedback.
Tony

I have solved this problem.
It turns out there was an Oracle timezone error (ORA-01882: timezone region not found) that was the culprit. The Ubuntu server we are using for our EC2 AMI had a default timezone set that I guess was not recognized by Java or Oracle. I had seen that error, but ignorantly thought it could not be related to a database connectivity error.
We used the dpkg-reconfigure tzdata command to set the timezone to the correct one and restarted Tomcat. This allowed us to connect successfully to the Oracle database.
Tony

Related

How to configure Glassfish on AWS Elastic Beanstalk, Connection Pool and Realm

I developed a Java EE 7 application, that uses Glassfish as the application server and MySQL as the database.
locally every thing is working correctly
now, I want to deploy the application to the cloud using AWS.
after reading some official documentations:
I created The database in the cloud 'AWS RDS', and conneted to it from MySQL Workbench and also The application in my workspace was able to connect to it and act on it.
Now for The application deployment I used Elastic Beanstalk with Glassfish 4.1 Java 8 (the docker one).
The probleme is that I need to configure Glassfish In AWS to
Create JDBC Connection Pool
Create JDBC Resource
Create A Security Realm
so that the apllication can work correctly.
How Can I do This?
I switch to Jelastic, I can access admin page usign their cloud, and I already deployed my appication

REST API AWS cloud using java

I am new to AWS , want to develop a cloud ready java application REST API.
The application will hit the MySQL database and produce output as JSON after querying the database.
IP:port/application?q=<query> response is JSON.
How to achieve it ? the data in MySQL is mostly static 100MB data but used very frequently.
It is very straight forward. if you already have same application running in your local system , then you can just move it to AWS , using below steps :-
spin up new ec2 instance, if you are using a free-tier then you can spin up lots of AWS resources for free , more information on https://aws.amazon.com/free/ .
install all the required s/w like Java, maven , tomcat and mysql and whatever your application is using on Ec2 instance . you can even have a free RDS (Database) instance in free tier which you can use for your application , instead of having the database installed locally on your application server.
while creating the ec2 server , configure instance security group properly for ex 8080 for http and 22 for SSH , 3306 for mysql etc. (This is important and try to be as restrtict as possible to make it safe from hackers).
build and deploy your application and access it using any REST client , by giving instance ip and application port number.
There are several resources online for AWS , you can refer https://www.youtube.com/watch?v=oS7VYX7LXUo which talks about deploying a java application to AWS.
Let me know if you need any other information.
Deploying Java apps (for example, a Spring BOOT APP) that interacts with the Amazon Relational Database Service (Amazon RDS) to the cloud is easy when using Elastic Beanstalk. An example of a Spring Boot database application that queries data from MySQL running on the cloud is documented here: https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/usecases/creating_secure_spring_app

how to publish my jsp project on internet using tomcat,mysql and jdbc driver

I have completed my semester project using jsp,tomcat server,mysql database and jdbc driver.I dont have any idea how to publish it on internet.It is working fine in localhost.Please help.
Basically you need to purchase a domain and a hosting place. Your hoster should support Tomcat and MySQL service. Then you need to build up your database, and deploy your application on the Tomcat server. And voila!
Note: The jdbc driver is not an issue since it can be included within your application...

Openshift: share MySQL cartrige between applications

I have Java EE web application on RedHat Openshift PaaS, which consists of JBoss EWS, MySQL and phpMyAdmin cartriges. My question is, whether it is possible to share the MySQL cartrige from application one (let's say app1-myname.rhcloud.com) with my second application running under the same OpenShift account (like app2-myname.rhcloud.com)?
Thanks.
From this KB: https://www.openshift.com/kb/kb-e1051-how-do-i-connect-multiple-applications-to-one-database#comment-form
OpenShift does not support direct connectivity to an embedded database on non-scalable applications. Having said that, there are 2 workarounds today:
Connecting to a scalable application's database using the
hardcoded values since you won't have $OPENSHIFT_DB_* env vars (for
scalable apps, see
https://openshift.redhat.com/community/kb/kb-e1049-how-does-scaling-work-in-openshift)
ssh port forwarding (see
https://openshift.redhat.com/community/forums/openshift/accessing-an-server-port-running-in-openshift-from-another-openshift-image)

Deploy pre-written SpringMVC + Hibernate to AWS

Basically, I've already written a webapp, it has hibernate with SpringMVC + Spring-security.
I have an EC2 account, my question is, when deploying it to the cloud rather than on a server locally like I do now (with RDS rather than having MySQL on localhost like I do now), should I just copy the war over onto the Tomcat installation of EC2, or do everything through Eclipse?
Is it relatively straight forward to set the new Hibernate.cfg.xml to point at a RDS rather than localhost?
At the moment I just copy the war onto the server and use iptables to map 80 to 8080, but I think I'm taking a very long route for deployment...I've not setup the db layer yet remotely...
Thanks,
I am used to deploying WAR files to EC2 instances (though using WebLogic instead of Tomcat), and I think it is much more straightforward just to FTP the files over to the EC2 instance rather than trying to deploy them through Eclipse.
For your other question, it is completely straightforward pointing Hibernate.cfg.xml to RDS. You will probably have no issues doing so, as long as you remember to give the correct permissions on RDS. Hope it helps.

Categories