title: Spring RestTemplate: URI is not absolute
body: <p>I'm trying to connect to a <em>Spring RESTful service</em> on the same server where my webapp is running.</p>
  
  <p>I'd like to use a "relative" path because it could be installed on several environments (localhost, test, production) but I get the error message: <code>URI is not absolute</code>.</p>
  
  <p>How can I call a service running on another webapp on the same server?</p>
  
  <p>My code is like following:</p>
  
  <pre><code>final RestTemplate restTemplate = new RestTemplate();
  URI uri;
  try {
      String url = "app2/myservice?par=1";
      uri = new URI(url);
      String result = restTemplate.getForObject(uri, String.class);
      System.out.println(result);
  } catch (URISyntaxException e) {
      logger.error(e.getMessage());
  }
  </code></pre>
  
  <p>Thanks.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I solved it by getting the host, port, etc... from the <code>request</code>, could it be a right and elegant solution? This's my actual simplified code:</p>
  
  <pre><code>String scheme = request.getScheme();
  String userInfo = request.getRemoteUser();
  String host = request.getLocalAddr();
  int port = request.getLocalPort();
  String path = "/app2/myservice";
  String query = "par=1";
  URI uri = new URI(scheme, userInfo, host, port, path, query, null);
  boolean isOK = restTemplate.getForObject(uri, Boolean.class);
  if (isOK) {
      System.out.println("Is OK");
  }
  </code></pre>