title: SunCertPathBuilderException: unable to find valid certification path to requested target in CN1 app
body: <p>Please can you help.
  I have a Codenameone app that issues a GET request to a cloud Tomcat 8 server, and expects back some response JSON. Importantly this is a HTTPS call.</p>
  
  <p>When i run the request in Postman it works fine:</p>
  
  <p><a href="https://www.mydomain.co.uk:8443/MyProject/v1/generate_token" rel="noreferrer">https://www.mydomain.co.uk:8443/MyProject/v1/generate_token</a></p>
  
  <p>The same URL through my browser works and shows as 'Secure' and i can see my certificate details.
  I have bought a certificate for my SSL/TLS configuration, and seems to function fine in the logs on startup.</p>
  
  <p>In the simulator i get back the following error at the point of reading the response back from the URL call - which i guess must be encrypted:</p>
  
  <pre><code>Exception: javax.net.ssl.SSLHandshakeException - sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
      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:1514)
      at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
      at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
      at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
      at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
      at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:7591)
      at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:702)
      at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
      at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
  </code></pre>
  
  <p>Why should the app be any different to Postman making the call (the Network Monitor window confirms the same URL call) ?</p>
  
  <p>None of the logs are being updated after my call, so nothing to check there. I haven't made any changes to my app (which was working) since moving from http to https.</p>
  
  <p>Here is the CN1 code making the call:</p>
  
  <pre><code>public String fetchTokenIntoStorage(String userName, String password) {
          ConnectionRequest r = new ConnectionRequest();
          r.setUrl(Constants.URL_HOST_PORT + "/MyProject" + Constants.LIVE_OR_TEST
                  + "/v1/generate_token");
          r.addRequestHeader("Content-Type", "application/json");
          r.addRequestHeader("userName", userName);
          r.addRequestHeader("password", password);
          r.setHttpMethod("GET");
          r.setFailSilently(false);
          r.setPost(false);
          // show spinning dialog while connecting
          InfiniteProgress prog = new InfiniteProgress();
          Dialog dlg = prog.showInifiniteBlocking();
          r.setDisposeOnCompletion(dlg);
          NetworkManager.getInstance().setTimeout(10000);
          // NetworkManager.getInstance().addErrorListener(new ActionListener() {
          //
          // @Override
          // public void actionPerformed(ActionEvent evt) {
          // MessageBox.showDialogMessage("Unable to connect to server. Please
          // retry later.");
          // }
          // });
          // NetworkManager.getInstance().updateThreadCount(2);
          NetworkManager.getInstance().addToQueueAndWait(r);
  
          if (r.getResponseData() != null) {
              JSONParser parser = new JSONParser();
              Map&lt;String, Object&gt; json = null;
              try {
                  json = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(r.getResponseData())));
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              if (json.get("error") != null) {
                  return String.valueOf(json.get("error"));
              }
              JwtRecord record = new JwtRecord();
              record.userId = Integer.parseInt(String.valueOf(json.get("userId")));
              record.jsonWebToken = (String) json.get("jwt");
              record.theme = "LIGHT";
              Storage.getInstance().writeObject("MyToken", record);
              return "";
          }
          if (!r.getResponseErrorMessage().equalsIgnoreCase("")) {
              return r.getResponseErrorMessage();
          } else {
              return "Unable to connect to server. Please check connection.";
          }
      }
  </code></pre>
  
  <p>Stepping through the code it seems to error just after</p>
  
  <pre><code>NetworkManager.getInstance().addToQueueAndWait(r);
  </code></pre>
  
  <p>The r.getResponseData() and r.getResponseErrorMessage() are null.</p>
  
  <p>Many thanks</p>