title: How can I get root-context url with JAX-RS?
body: <p>With given Application</p>
  
  <pre><code>@ApplicationPath("/api")
  public class MyApplication {
  }
  </code></pre>
  
  <p><a href="http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriInfo.html#getBaseUri--" rel="nofollow noreferrer">UriInfo#getBaseUri</a> gives me an application path.</p>
  
  <pre><code>@Context
  private UriInfo uriInfo
  
  uriInfo.getBaseUri(); // http://address/&lt;context-path&gt;/api
  </code></pre>
  
  <p><s>How can I get context-path?</s>
  How can I get full URL to context-path?</p>
  
  <pre><code>http://address/&lt;context-path&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I currently using code from <a href="https://stackoverflow.com/a/27072513/330457">this answer</a>.</p>
  
  <pre><code>@Context
  private HttpServletRequest servletRequest;
  
  final URI contextUri
       = URI.create(servletRequest.getRequestURL().toString())
      .resolve(servletRequest.getContextPath());
  </code></pre>
  
  <p>Any other suggestions?</p>