title: java.security.cert.CertificateException: No subject alternative names present;
body: <p>I am using <code>WSO2 API Manager</code> version <code>1.9.1</code>. In this tool, I publish my sample project (i.e., <code>proxied</code>) and subscribe that project to get consumer key and secret. This tool also gives me CURL command which works fine. </p>
  
  <p>The below CURL command which runs fine.</p>
  
  <pre><code>curl -k -d "grant_type=password&amp;username=XXXXX&amp;password=XXXXX" -H "Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, Content-Type: application/x-www-form-urlencoded" https://XXXXXXXXXXX:XXXX/token
  </code></pre>
  
  <p>Now I'm trying to developed the <code>java</code> code using <code>RestTemplate</code> which will connect to <code>SSL protected site</code> without <code>cert verification</code> i.e., <code>insecure</code> way looking at above CURL command.
  So far I developed below code, but when I run I see following error coming. </p>
  
  <pre><code>public static void main(String[] args) {
          HttpHeaders headers = new HttpHeaders();
          headers.add("Accept", "application/json");
          headers.add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED.toString());
          headers.add("Authorization", "Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
  
          String url = "https://XXXXXXXXXXXXXX:XXXX/token";
  
          String data = "grant_type=password&amp;username=XXXXX&amp;password=XXXXX";
  
          RestTemplate restTemplate = new RestTemplate();
          HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(data,headers);
          HttpEntity&lt;String&gt; response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
          System.out.println("RESPONSE : "+response.getBody());
      }
  </code></pre>
  
  <p>The error I am facing. <strong>Please suggest how we can connect to SSL site insecure way, the same curl command does?</strong></p>
  
  <pre><code>Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://XXXXXXXXXXX:8243/token":java.security.cert.CertificateException: No subject alternative names present; nested exception is javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:580)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:530)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:448)
      at com.java.wso2.TokenDemo.main(TokenDemo.java:74)
  Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937)
      at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
      at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
      at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1478)
      at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212)
      at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
      at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1050)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375)
      at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
      at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:81)
      at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
      at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:569)
      ... 3 more
  </code></pre>
  
  <p>How we can solve this error? Off-course my issue is not similar to <a href="https://stackoverflow.com/questions/17167691/javax-net-ssl-sslhandshakeexception-java-security-cert-certificateexception-no">javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names present</a></p>