title: Communication between WARs within the same tomcat server - JNDI vs REST API
body: <p>I have a requirement, where a front-end application (written in spring MVC) needs to communicate with another backend application. Both the applications are going to be WAR running within the same tomcat instance. For understanding purpose, lets name it frontend.war and backend.war.</p>
  
  <p>I have gone through many posts across various forum, and found many different strategies, <strong>some of them are as below:</strong></p>
  
  <p>1) <strong>Using EJB</strong> - Ruled out, EJB's are maintenance overhead and we have no plan to create a dedicated EAR to accomplish this; because we have plan to add more different forntend wars (application modules) which will communicate to same backend.war.</p>
  
  <p>2) <strong>Using JNDI</strong> : Looks promising, but it needs to have one war to know about the 'interface' being exposed by 2nd war, its signature. So, it is making it tightly coupled with each other. Future change in the service contract can become nightmare.</p>
  
  <p>3) <strong>Using REST API</strong> : This looks an ideal approach, with only one caveat that the communication is over HTTP call, hence it could be slow.</p>
  
  <p>Other approaches like common parentContext (in Spring). ContextSwitching within application does have their own issues.</p>
  
  <p>I am getting inclined to use REST API approach for this solution; as it is cleaner and easy to maintain. Further the http protocol is mature and has lots of know-how available for future development.</p>
  
  <p><strong>My query:</strong>
  A) Is it possible to make a tomcat aware that a particular webservice call is indeed a call on the application running same JVM/Server (kind of 'internal'); rather than an 'external' webservice call?</p>
  
  <p>B) If I use url like '<a href="http://localhost:8080/rest/" rel="noreferrer">http://localhost:8080/rest/</a>...' (note that backend.war is not intended for external world, so a domain name is not needed) ; will it do the trick?</p>
  
  <p>I am looking for an approach, which gives me performance of JNDI (communication within same JVM) and flexibility of REST (You can change anything, anytime as long as public URLs are intact).</p>