Currently, I have an existing web application (JSP-Servlet). I am planning to create a web service based on that web application. Since the web service will be patterned to the existing web application, I think it will be best if I can reuse the existing classes. So I am thinking of putting the web service under the web application. With this, both of them will be under one project.
However, according to one of the posters at http://www.coderanch.com/t/528564/patterns/Web-Application-Web-Service-inside, combining the two under one project is considered to be a bad design. But he did not give any direct reason as to why he said that it is considered to be a bad design. Can anyone enlighten me regarding this matter? Why is it considered to be a bad design? What are the advantages and disadvantages of separating the two? Why is it better to separate the web service from the web application?
The one reason given there -loose coupling- is a valid concern. You may wish to be able to develop and deploy the web app UI independently of the WS, and both independently of the underlying logic that powers them. But it depends on how the three parts will evolve; if they evolve together, then there's nothing particularly wrong with keeping them as part of the the same web app. In that case you won't be able to take down and restart just one part of it, though; this may or may not be a concern in your case.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Oct 29, 2010
@Ulf Dittmer: Thanks! So having the web service inside a web application is not universally a bad design? But separating the two could be a better choice since it provides more benefits? But having them loosely coupled will also make them more difficult to manage right? Since if I have to update a certain class from the web application, I also have to update its corresponding class in the web service?
Also, after studying the framework of my web application, I realize that I could only reuse one class since the other classes are bounded by Struts, so separating the 2 might really be a better choice for me.
Joined: Mar 22, 2005
So having the web service inside a web application is not universally a bad design?
I would say so, although what constitutes a good or bad design in any given situation can be a matter of opinion - so people are bound to disagree.
But separating the two could be a better choice since it provides more benefits?
It could, but isn't necessarily. Also, I wouldn't say it provides *more* benefits - it provides *different* benefits and different drawbacks; as is so often the case, it's a trade-off.
But having them loosely coupled will also make them more difficult to manage right? Since if I have to update a certain class from the web application, I also have to update its corresponding class in the web service?
If achieving this kind of loose coupling is important, then you should separate out the common classes into a middle layer, or app server. So there'd be two web apps left - one for the web UI and one for the WS, and both would access the same business layer. If there's only a single class that both share, that suggests to me that the WS is quite small in scope so that it probably doesn't pay off to implement any of this separation.
But ask yourself if it might be desirable to update the web UI independently of the WS, and either of them independently of the business layer; that's what should drive the decision.
Considering your case I think it should be developed as below
And of course Struts UI webapp and Webservices application are two different webapplications using same Business Services Jar as mentioned above.
Now if your requirements for UI and Webservices starts differening from each other then you will need to branch out Business services development and use some kind of versioning.
Joined: Oct 29, 2010
@Ulf Dittmer: Yes, the web service is quite small in scope. As of now, it only has 1 accessible method. Based on what you said, then it is most probable that I would just stick to my current design (combining the web service and web application UI under one project). But I am still considering of separating the two. Thank you very much for your explanation! I really appreciate it.
@amit punekar: Thanks! Yes, the design of my web service and web application is similar to your design. They share some JARs under the WEB-INF/lib directory. I am glad that it seems that I am in the right direction.