title: Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available in java(spring)
body: <p>i am trying to authenticate a server i am having server certificate and i have created key store and trust store. The exception is happening at rest template in the code i dont get what the error is i have searched in the net but i found no solution </p>
  
  <p>my java code:</p>
  
  <pre><code>org.json.JSONObject json = new org.json.JSONObject();
  
      org.json.JSONObject root = new org.json.JSONObject();
      root.put("Version", "1");
      json.put("key", "test");
      root.put("message", json);
      System.out.println(root);
  
      String url = "https://example.com";
  App obi = new App();
      obi.trustSelfSignedSSL();
  
      System.setProperty("javax.net.ssl.keyStore", "/Users/crohitk/Desktop/spring/keystore.jks");
  
     System.setProperty("javax.net.ssl.keyStorePassword", "password");
     System.setProperty("javax.net.ssl.trustStore","/Users/crohitk/Desktop/spring/ca-certs.jks");
  
     System.setProperty("javax.net.ssl.trustStorePassword","");
  
  
     KeyStore keyStore = null;
     KeyStore truststore = null;
  
          keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
  
          keyStore.load(new FileInputStream("/Users/crohitk/Desktop/spring/keystore.jks"),
                  "password".toCharArray());
  
  
      SSLConnectionSocketFactory socketFactory = null;
  
          socketFactory = new SSLConnectionSocketFactory(
                  new SSLContextBuilder()
  
                          .loadKeyMaterial(keyStore, "password".toCharArray()).build());
  
  
      HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
  
      ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
              httpClient);
  
      RestTemplate restTemplate = new RestTemplate(requestFactory);
  
  
  
  
  
    String result = restTemplate.postForObject(url, root , String.class);
      System.out.println(result);
      System.out.println( "Hello World!" );
  }
  
      public static void trustSelfSignedSSL() {
          try {
              SSLContext ctx = SSLContext.getInstance("TLS");
              X509TrustManager tm = new X509TrustManager() {
  
                  public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
                  }
  
                  public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
                  }
  
                  public X509Certificate[] getAcceptedIssuers() {
                      return null;
                  }
              };
              ctx.init(null, new TrustManager[]{tm}, null);
              SSLContext.setDefault(ctx);
          } catch (Exception ex) {
              ex.printStackTrace();
          }
          }
  </code></pre>
  
  <p>error trace:</p>
  
  <pre><code>Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://example.com":java.security.cert.CertificateException: No X509TrustManager implementation available; nested exception is javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:602)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:552)
      at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:352)
      at url.url1.App.main(App.java:258)
  </code></pre>
  
  <p>my pom.xml:</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- Spring dependencies --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
      &lt;groupId&gt;commons-codec&lt;/groupId&gt;
      &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
      &lt;version&gt;1.9&lt;/version&gt;
  &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
      &lt;version&gt;4.1.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.9&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  
          &lt;!-- Spring AOP dependency --&gt;
          &lt;dependency&gt;
                  &lt;groupId&gt;cglib&lt;/groupId&gt;
          &lt;artifactId&gt;cglib&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Hibernate framework --&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
      &lt;version&gt;3.2.3.ga&lt;/version&gt;
  &lt;/dependency&gt;
  
      &lt;!--&lt;dependency&gt;
          &lt;groupId&gt;hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate3&lt;/artifactId&gt;
          &lt;version&gt;3.2.3.GA&lt;/version&gt;
      &lt;/dependency&gt; --&gt;
  
  
      &lt;!-- Hibernate library dependecy start --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;dom4j&lt;/groupId&gt;
          &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
          &lt;version&gt;1.6.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-logging&lt;/groupId&gt;
          &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
          &lt;version&gt;1.1.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-collections&lt;/groupId&gt;
          &lt;artifactId&gt;commons-collections&lt;/artifactId&gt;
          &lt;version&gt;3.2.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;antlr&lt;/groupId&gt;
          &lt;artifactId&gt;antlr&lt;/artifactId&gt;
          &lt;version&gt;2.7.7&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- Hibernate library dependecy end --&gt;
  
   &lt;dependency&gt;
              &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
              &lt;artifactId&gt;jta&lt;/artifactId&gt;
              &lt;version&gt;1.1&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
      &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;type&gt;jar&lt;/type&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  
    &lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
      &lt;version&gt;3.6.0.Final&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
  
  
      &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
      &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
      &lt;version&gt;1.6.5&lt;/version&gt;
    &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;javassist&lt;/groupId&gt;
      &lt;artifactId&gt;javassist&lt;/artifactId&gt;
      &lt;version&gt;3.12.1.GA&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
  
      &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
      &lt;artifactId&gt;gson&lt;/artifactId&gt;
      &lt;version&gt;2.3.1&lt;/version&gt;
  &lt;/dependency&gt;
  
  
   &lt;dependency&gt;
      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
      &lt;artifactId&gt;poi&lt;/artifactId&gt;
      &lt;version&gt;3.11&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
      &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
      &lt;version&gt;3.9&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;commons-io&lt;/groupId&gt;
      &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
      &lt;version&gt;2.4&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.json&lt;/groupId&gt;
      &lt;artifactId&gt;json&lt;/artifactId&gt;
      &lt;version&gt;20141113&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
      &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
      &lt;version&gt;4.3.4&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;commons-httpclient&lt;/groupId&gt;
      &lt;artifactId&gt;commons-httpclient&lt;/artifactId&gt;
      &lt;version&gt;3.1&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;net.sf.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
      &lt;version&gt;2.1.8&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  
  &lt;dependency&gt;
     &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
     &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
     &lt;version&gt;5.2.1.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
      &lt;version&gt;2.3&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j&lt;/artifactId&gt;
      &lt;version&gt;1.2.17&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;commons-lang&lt;/groupId&gt;
      &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
      &lt;version&gt;2.3&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;!--  &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
      &lt;version&gt;3.0-alpha-1&lt;/version&gt;
  &lt;/dependency&gt;--&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.igniterealtime.smack&lt;/groupId&gt;
      &lt;artifactId&gt;smack-core&lt;/artifactId&gt;
      &lt;version&gt;4.2.0-alpha1&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
      &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
      &lt;version&gt;1.3.2&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;ca.juliusdavies&lt;/groupId&gt;
      &lt;artifactId&gt;not-yet-commons-ssl&lt;/artifactId&gt;
      &lt;version&gt;0.3.11&lt;/version&gt;
  &lt;/dependency&gt;
   &lt;dependency&gt;
         &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
         &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
         &lt;version&gt;2.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
         &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
         &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
         &lt;version&gt;2.8&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-common&lt;/artifactId&gt;
          &lt;version&gt;2.8&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
    &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
    &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
    &lt;version&gt;2.8&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  </code></pre>