I'm new to using Java within a web environment. At the moment I have a Java application that we run on a local machine, we'll call it the server app. We want to add the ability to communicate with this application by means of a RESTful interface.
I've been playing around with Tomcat and Glassfish and I have something that sort of works, but I'm certain I'm doing things in a weird way. I have a listener in the web application that creates an instance of my server application every time Tomcat is started.
When a connection is created the servlet grabs the instance of this server application so I can interact with it and pass data to a jsp. I can't help but feel this isn't a conventional approach.
I'm leaning towards just running the server jar entirely separately and using sockets on the local machine for the servlets to interact, but I can't help but think this is overkill. I've looked around and it looks like RMI might be a solution, but I'm unfamiliar with it.
Here is what I need to be able to do:
- Tomcat needs to be running to accept REST requests
- I need a way for the web application to check to see if the server app is running
- I need the web app to be able to get an instance of the server app so that I can call it's methods or at least send it some JSON
Overall I think it's a fairly basic task, I'm just getting a bit lost trying to find a good way to organize my project.
Should I run the server app outside of the Tomcat environment and just use sockets and some JSON?
Should I run the server app outside of Tomcat and use RMI (will require some research, but that's no big deal)
Should I keep the server app within the Tomcat environment like I have it currently?