Change REST URL depending on called URL
<p>I currently have a problem with a REST service: The basic construction is the following: On my Tomcat there are running 2 applications (my new REST service (S1) and another application (S2) which also offers REST calls). The Applications should work together so that S1 can send requests to S2. It works fine if I use hard coded URLs in S1 to call S2. But the problem is that the path of the applications are changing due to different ports or configurations. The changes apply to both applications since they are both on the same Tomcat server.<br>
Basically the 2 Paths look similar, starting e.g. with <code>http://localhost:8080/</code> or <code>http://sys-example:8034/</code>. So if I call S1 on an specific Path, the application should fetch the URL and build its own basePath to reach S2 on the same Server. How can I create a method which gets me the path where my service is called. IS there a way to use <code>ServletContext</code> or is there a better way?</p>

<p>Currently this is my code in S1 to reach the service in S2</p>

<pre><code>String path = configMap.get("basePath").toString(); 
//configMap is a HashMap which contains Data from an config file
//the result of get("basePath") looks like this: http://localhost:8080
path = path.concat("/otherService/rest/action/login");
</code></pre>