title: Disabling hostname verification
body: <p>Our web application calls several web services internally using Jersey client API. Few services are secure and we use certificates to authenticate.</p>
  
  <p>Due to some reasons we want to disable hostname verification on few services.</p>
  
  <p>So I searched for some examples and found the below links and the service started working as expected after disabling the verification.</p>
  
  <p><a href="https://stackoverflow.com/questions/6047996/ignore-self-signed-ssl-cert-using-jersey-client">Link1</a>, <a href="https://stackoverflow.com/questions/2145431/https-using-jersey-client">link2</a>, <a href="https://stackoverflow.com/questions/19540289/how-to-fix-the-java-security-cert-certificateexception-no-subject-alternative">link3</a></p>
  
  <p>While going through the third link I noticed a call to HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);</p>
  
  <p>I am assuming that, because of the above call, hostname verification will be disabled on all subsequent web service calls.</p>
  
  <p>If my assumption is right, how do I disable verification only on a particular service?</p>
  
  <pre><code>HostnameVerifier allHostsValid = new HostnameVerifier() { 
      public boolean verify(String hostname, SSLSession session) {
       if(hostname.equals("xyz")) {
           return true; 
       } else {
           // How do I implement this section?
           // if I return false will the server perform the verification? If not how do I implement this?
       }
      } 
  };
  </code></pre>