What happens to grails project on start if database is not running? - java

I have a grails project with mysql for GORM support. When i start project without mysql running, it gives me series of exception message. This is fine and expected. But, what is problem is that there is no way to handle that so that i can catch them and report to user that there is issue with system and they need to wait till it gets fixed.
There are two cases for this problem.
First one is when a currently running project (deployed inside tomcat and running) get its mysql connection killed by say stopping mysql service. In this case, it keeps on throwing database exception without any grace. The error catching mechanism fails for me. I have mapped 500 to a error page but it also does not gets rendered. Nginx which acts as reverse proxy at last displays its own timeout page.
Second case is when project start loading (say tomcat container is started) and mysql service is already down. In this case, the project startup seems to be effected to a level that startup fails though tomcat reports in log that war is running but when accessed it just throws black page (saying 404) which still is mysterious because i have mapped 404 to a error page which is also not in work.
Thanks.

If there is no db at start up the war will not be loaded into tomcat at all. So you will get default 404 error pages at that point. There are errors thrown to the log in this case but not much else. So your users are hosting their own instances of their app it sounds like, what I like to do is expose a health page.
The health page can be at a known URL and in the case of no db you will get a 404 but you can document that any non 200 status code is an error and provide info on how to fix. Also if you are automating deployment this check is great for reporting status of the deployment.

Related

Timeout a long running SQL Server query in a java application running inside tomcat server

I have a java web app that is running inside tomcat and the application has a page (JSP) where users clicks (some buttons on that web page) which results in hitting a query behind the page and reloads it with new information and sometimes that query takes longer than expected and I want to kill the query automatically if it runs longer than x minutes. How can I achieve that at tomcat side, is that even possible with any tomcat server configurations like timeout or anything, if so could someone please guide me or show an example configuration or setting change I can try? Thanks
I think you are looking for Statement.setQueryTimeout which is a feature of JDBC, not of any specific application server, etc. You will want to call that method and set an appropriate timeout. Your queries will throw SQLTimeoutException if the timeout elapses and your application will have to decide what to do next.

Apache Tomcat HTTP Status 404 error after Java web app deployment

For the past 2 months, I've been working on a project for my final year in uni. I've developed a web app in Java (Eclipse) and I used to test it by benefiting the Tomcat servlet containers. However, at the final stage now I want to deploy it on the university servers, but I am experiencing a strange error. I am not sure what I've haven't configured correctly on the uni server-side, that's why I will be thankful if anyone can direct me to resolutions to the problem.
The problem is that in Eclipse when I launch the app I am given a login form, which when I type my credentials let me in my account. However, on the university server-side after I generated a war that I placed in the webapps folder I restarted the Tomcat server, but I am getting HTTP Status 404 - /auction/login error after I submit my credentials.
The conclusion is that in Eclipse everything runs smoothly, however, on the university server-side I get HTTP Status 404 - /auction/login after I type my credentials in the login form
I've checked many solutions discussed in here, but nothing seemed to be similar to what I'm experiencing. I have suspicions I've missed to configure something on the university side, but I am not sure what.

Hibernate transactions rolling back in tomcat server

I am encountering a very weird problem in production. I have deployed a new application in production which is run in Tomcat server(version 7) using Windows services. This application is basically a batch processing which processes around 100-200 records at a time and generates their output in a flat file. When we run this application in production, the record's status changes from pending to verified(which is correct) and generates the flat file without any exception. However, when the batch process completes, all transactions are rolled back like nothing happened. Means, the record's status changes to pending, flat file is empty etc. This same application when running in staging or QA environment, it is running fine.
Can someone help me with this problem or at least guide me where should I start looking into it?
Since I don't know where the problem is, I am not attaching any sources or any error logs. Please let me know what details should I share?
Thank you

Tomcat server won't start if my servlet references another project

I currently have 2 java projects that should be working together. The first project, Controllers, contains classes that should establish a connection to my database and communicate with it.
The second project is a dynamic web project with a servlet and 2 jsps(LoginPage and Welcomepage). The servlet uses the objects in the controller project to connect to the database, verify that a user's username and password are correct, and send them to a welcome screen.
Here's where it gets weird. As soon as I attempt to declare an object defined in my cotrollers project, my server refuses to start. It gives no error other than "Server Tomcat v9.0 Server at localhost failed to start." I have verified that my server works, I have checked that the build path is configured correctly, I have even commented out all the code in the controller object being defined. It's as if the mere act of declaring an object from another project causes the error, but I don't see how that would prevent the server from starting.
Any ideas what I could be missing?

Azure deployment hanging in Eclipse

I previously did not have any issues with this, as I have been deploying Azure web app from Eclipse with no issue. Usually it takes a few minutes, but currently it is taking forever with no real progress from what I can tell. I have tried restarting Eclipse as well as deleting the Azure app and recreating a new one. None of those work. Are there some settings I need to reset ?
EDIT: Yes it is a Web App created in Azure, and I previously had no trouble deploying at regular intervals. Last time however I wanted to abort the deployment and attempted to do so in Eclipse but it kept running and it seemed to be hanging so I shut down Eclipse and tried to deploy again but instead of taking just a few minutes, now it is stuck at the beginning with no progress.
I then decided to delete the web app, create a new one, and deploy to the new web app from Eclipse, but it is still the same with no progress.
EDIT: Adding Screenshots of the general environment and Azure configuration.
Just summarize for the above comments, the issue seems that Azure WebApp waits timeout to recover or reset for a failed deployment connection, so a suggestion is that trying to restart the Azure WebApp to recover or reset all status of the current instance fastly, or wait awhile then try to reconnect again.
But for some similar cases, if the above action failed, it's necessary for considering some metadata files in the current workspace, a valid way may be to create a new workspace to try to reconnect.

Categories