title: Spring Rest Template : Host name 'localhost' does not match the certificate subject provided by the peer
body: <p>I use RestTemplate config like this :</p>
  
  <pre><code>private RestTemplate createRestTemplate() throws Exception {
          final String username = "admin";
          final String password = "admin";
          final String proxyUrl = "localhost";
          final int port = 443;
  
          CredentialsProvider credsProvider = new BasicCredentialsProvider();
          credsProvider.setCredentials(new AuthScope(proxyUrl, port),
                  new UsernamePasswordCredentials(username, password));
  
          HttpHost host = new HttpHost(proxyUrl, port, "https");
  
          HttpClientBuilder clientBuilder = HttpClientBuilder.create();
  
          clientBuilder.setProxy(host).setDefaultCredentialsProvider(credsProvider).disableCookieManagement();
  
          HttpClient httpClient = clientBuilder.build();
          HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
          factory.setHttpClient(httpClient);
  
          return new RestTemplate(factory);
      }
  </code></pre>
  
  <p>And the this is how my method work:</p>
  
  <pre><code>public String receiveMessage(String message) {
          try {
              restTemplate = createRestTemplate();
              ObjectMapper mapper = new ObjectMapper();
              Class1 class1 = null;
              String json2 = "";
  
              class1= mapper.readValue(message, Class1.class);
  
              Class1 class2 = restTemplate.getForObject(URL_SERVICE_1 + "/class1/findByName?name=" + class1.getName(),
                      Class1.class);
              System.out.println("Server 1 : " + message);
              json2 = mapper.writeValueAsString(class2);
  
              return "Error - " + json2;
          } catch (Exception e) {
              // TODO Auto-generated catch block
              return e.getMessage();
          }
  
      }
  </code></pre>
  
  <p>URL_SERVICE_1 contains <a href="https://localhost" rel="nofollow noreferrer">https://localhost</a></p>
  
  <p>When I tried to call function GET, I always get return like this :</p>
  
  <pre><code>I/O error on GET request for "https://localhost/class1/findByName?name=20-1P": Host name 'localhost' does not match the certificate subject provided by the peer (CN=*.webku-cool.com, OU=EssentialSSL Wildcard, OU=Domain Control Validated); nested exception is javax.net.ssl.SSLPeerUnverifiedException: Host name 'localhost' does not match the certificate subject provided by the peer (CN=*.webku-cool.com, OU=EssentialSSL Wildcard, OU=Domain Control Validated)
  </code></pre>
  
  <p>I don't know the correct setting for restTemplate with https. I already tried 23 references about SSL Settings and got same error.</p>
  
  <p><a href="https://stackoverflow.com/questions/34655031/javax-net-ssl-sslpeerunverifiedexception-host-name-does-not-match-the-certifica">1. Reference</a></p>
  
  <p><a href="http://blog.codeleak.pl/2016/02/skip-ssl-certificate-verification-in.html" rel="nofollow noreferrer">2. Reference</a></p>
  
  <p><a href="http://www.baeldung.com/httpclient-ssl" rel="nofollow noreferrer">3. Reference</a></p>