title: Java | API to get protocol://domain.port from URL
body: <p>I have got URL as referrer and want to get protocol and domain from it.</p>
  
  <p>For example: If URL is <code>https://test.domain.com/a/b/c.html?test=hello</code> then output needs to be <code>https://test.domain.com</code>. I have gone through <code>http://docs.oracle.com/javase/7/docs/api/java/net/URI.html</code> and I can't seems to find any method that can directly do so.</p>
  
  <hr>
  
  <p>I am not using Spring, so can't use Sprint classes (if any).</p>
  
  <hr>
  
  <p>Guys I can write custom login to get port, domain and protocol from URL, but looking for API which already has this implemented and can minimize my time in testing various scenarios.</p>