views:

113

answers:

1

For my web application, I am thinking about using the Spring framework. Initially, I was thinking of having different actions like create user or login, but now I have to expose some functionality to other applications. Should I create a web service that I call from my application and others do as well, or create an action from Spring and then just have others call the web service? It seems like I should minimize the different ways to call something, but does it make sense to call a web service that is running on the same application server as my main app? Would this be a bad idea from a performance stand point?

Update

I was concerned that Tomcat wouldn't be able to serve both the static or dynamic pages on port 80 (so users could go to www.example.com/welcome.jsp instead of www.example.com:8080/welcome.jsp), as well as a web service but I guess it doesn't matter as both are just served as requests from Tomcat. I'm guessing this means I'll have to change Tomcat to run on port 80 and other applications will have access the web service via this port. Or I could leave Tomcat running on port 8080 and put Apache in front on Tomcat on port 80 and Apache will serve the requests to Tomcat. Is that correct?

+1  A: 

I'd put the common business logic in a "business service" and :

  1. call it from an action in your web app
  2. expose it as a web service for other applications

To me, there is nothing bad with this approach and it's pretty easy and clean to implement it with Spring. Actually, I would find ugly to expose this business service as web service only and to call it from the web app (and I'm pretty sure that this will be more complicated to implement on the web app side). You have different "usage contexts", just expose the adequate interface for them.

(EDIT: I'm answering a question of the OP posted as comment below)

You can deploy the web application and the web service in the same WAR (but this is just a deployment choice, you could package the business logic in a JAR and use it in several WARs). Regarding the port, I'm not sure to understand your question. Traditionally, you'll use a web server (e.g. apache) in front of your application server. If you don't, you can always choose to run you app server on port 80. Actually, in both case you are free to use whatever port you want. Using port 80 is just convenient.

Yes, your update is correct.

Pascal Thivent
Can I deploy the web app and web service in the same war file? It seems like I would have to as the web app needs access to the business logic. Does this mean the web service has to serve requests on port 80 so the web app can get the regular pages and the web service is available as well?
David Buckley
Ok, so I can deploy them in the same WAR and have the web service server at <host>:8080/webservice..., and the rest of the web app at <host>/welcome.jsp? I thought the WAR would be served on the same port. It also sounds like I should have Apache in front of tomcat so requests for either the web app (normal jsp pages) or the web service (SOAP requests) will go through there?
David Buckley
I think you misunderstood me. Tomcat will be listening on a port that will be the **same** for all applications served by Tomcat, for all webapps, for all WARs. Then using Apache in front of Tomcat is indeed a good practice, especially if you have lots of static content to serve (Apache does this better than Tomcat) but you might choose to not use it (I mentioned it initially because you were talking about port 80). Actually, I didn't get the issue with the port.
Pascal Thivent
Thanks for the info - I tried to update the question to better reflect what I was asking.
David Buckley