Failure to connect to Backendless through JAVA API

Hi,

A Java servlet process that posted push notifications and email message to Backendless stopped functioning on 3/11. It worked prior to that time after having in production for 1.5 years.

Here is the exception thrown by the process:

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
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1904)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:279)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:273)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1446)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.Handshaker.processLoop(Handshaker.java:913)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.Handshaker.process_record(Handshaker.java:849)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1023)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
INFO | jvm 1 | 2019/03/11 10:12:56 | at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
INFO | jvm 1 | 2019/03/11 10:12:56 | at MySQLdbConnect.sendNotificationToBackendless(MySQLdbConnect.java:914)
INFO | jvm 1 | 2019/03/11 10:12:56 | at MySQLdbConnect.balanceDueNotification(MySQLdbConnect.java:876)
INFO | jvm 1 | 2019/03/11 10:12:56 | at MySQLdbConnect.balanceDueMessagingTrigger(MySQLdbConnect.java:821)
INFO | jvm 1 | 2019/03/11 10:12:56 | at MySQLdbConnect$4.run(MySQLdbConnect.java:788)
INFO | jvm 1 | 2019/03/11 10:12:56 | at java.lang.Thread.run(Thread.java:745)

The server that runs this process utilizes Java 7. The code fragment is as follows:

private void sendNotificationToBackendless(String type, JsonObject jsonParams){
try {
String url = “https://api.backendless.com/” + applicationID + “/” + appKey + “/messaging/” + type;
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
//add request header
con.setRequestMethod(“POST”);
con.setRequestProperty(“Content-Type”, contentType);
con.setDoOutput(true);

  	DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  	wr.writeBytes(jsonParams.toString());
  	wr.flush();
  	wr.close();

  	int responseCode = con.getResponseCode();
  	System.out.println("\nSending 'POST' request to URL : " + url);
  	System.out.println("Post parameters : " + jsonParams.toString());
  	System.out.println("Response Code : " + responseCode);

  	BufferedReader in = new BufferedReader(
  	        new InputStreamReader(con.getInputStream()));
  	String inputLine;
  	StringBuffer response = new StringBuffer();

  	while ((inputLine = in.readLine()) != null) {
  		response.append(inputLine);
  	}
  	in.close();
  	
  	//print result
  	System.out.println(response.toString());
  } catch (IOException e) {
  	// TODO Auto-generated catch block
  	e.printStackTrace();
  }
}

The exception is thrown on the following line:

  	DataOutputStream wr = new DataOutputStream(con.getOutputStream());

Here are the last known log entries from a successful attempt to execute this process on 3/10:

INFO | jvm 1 | 2019/03/10 10:12:56 | Sending ‘POST’ request to URL : https://api.backendless.com/XXXXX-XXXX-XXXX-XXX-XXXXX/XXXX-XXX-XX-XXX-XXXXXXXXX/messaging/email
INFO | jvm 1 | 2019/03/10 10:12:56 | Post parameters : {“subject”:“Important Reminder from your TrafficTix App!”,“to”:[“boukantier1978@gmail.com”],“bodyparts”:{“textmessage”:“AN IMPORTANT REMINDER FROM GANNES & MUSICO: your traffic ticket hearing date/time is set for 2019-03-18 08:30:00.0”}}
INFO | jvm 1 | 2019/03/10 10:12:56 | Response Code : 200
INFO | jvm 1 | 2019/03/10 10:12:56 | {“messageId”:“mail:DAD1564C-379C-B426-FF1B-DB3105E35E00”,“errorMessage”:null,“status”:“SCHEDULED”}

Hi Kam,

What version of the JDK/JRE do you use? The problem you are experiencing may happen with older versions of Java.

Regards,
Mark

Hi Mark,

It is Java SE 7.

Thanks,
Kam

Hi Kam,

If you upgrade to Java 8, specifically Java 8u101 or newer, the problem will go away. Please see the following for more information: https://stackoverflow.com/a/34111150/544904

Regards,
Mark

Thanks Mark. I will try and let you know.

Kam

Problem resolved with Java 8 upgrade. Thank you.