0

I am using this code and it working fine on local server, but not working on BlueMix server

 public void pushNotification(String notificationTitle, String notificationBody, String token, String notificationType, int applePort) {
     HTTP2Client lowLevelClient = null;
     HttpClient client = null;
     String hostname = null;
     try {

         lowLevelClient = new HTTP2Client(); // create a low-level Jetty HTTP/2 client
         lowLevelClient.start();

         // APNs requires the use of HPACK (header compression for HTTP/2), which prevents repeated header keys and values.
         KeyStore ks = KeyStore.getInstance("PKCS12");

         // Ensure that the password is the same as the one used later in setKeyStorePassword()
         ks.load(AppleServiceResource.class.getClassLoader().getResourceAsStream("/resources/appleCertificate/apns_all.p12"), "a1B23".toCharArray());

         SslContextFactory ssl = new SslContextFactory(true);
         ssl.setKeyStore(ks);
         ssl.setKeyStorePassword("a5B93");
         FuturePromise<Session> sessionPromise = new FuturePromise<>();

         if (notificationType.trim().equalsIgnoreCase("Development"))
             hostname = "api.development.push.apple.com";
         else if (notificationType.trim().equalsIgnoreCase("Producation"))
             hostname = "api.push.apple.com";
         lowLevelClient.connect(ssl, new InetSocketAddress(hostname, applePort), new ServerSessionListener.Adapter(), sessionPromise);

         // create a high-level Jetty client
         client = new HttpClient(new HttpClientTransportOverHTTP2(lowLevelClient), ssl);
         client.start();

         String payload = "{\"aps\":{\"alert\":{\"title\":\"" + notificationTitle + "\",\"body\":\"" + notificationBody + "\"}, \"sound\":\"default\"}}";

         Request request = client.POST("https://" + hostname).timeout(20, TimeUnit.SECONDS).path("/3/device/" + token).content(new StringContentProvider(payload, Charset.forName("UTF-8")));

         request = request.header("apns-topic", "Skios.TripBruCACT").header("User-Agent", client.getClass().getName() + "/" + Jetty.VERSION);
         logger.info("Sending notification to token: " + token );
         ContentResponse response = request.send();
         logger.info("Response Status: " + response.getStatus());
         logger.info("Sending notification to token: " + token + " is Done.");
     } catch (Exception e) {
         e.printStackTrace();
     } finally {
         try {
             if (lowLevelClient != null && !lowLevelClient.isStopped())
                 lowLevelClient.stop();
             if (client != null && !client.isStopped())
                 client.stop();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 }

When i use same code on BlueMix server it throws

org.eclipse.jetty.io.RuntimeIOException: javax.net.ssl.SSLHandshakeException: No negotiable cipher suite

and

javax.net.ssl.SSLHandshakeException: No negotiable cipher suite
Gas
  • 17,601
  • 4
  • 46
  • 93
mibrahim.iti
  • 1,928
  • 5
  • 22
  • 50
  • To start with, you'll need to identify which cipher suites (and ssl/tls protocol level) the apple APNS needs. Is that documented anywhere? – Joakim Erdfelt Sep 21 '16 at 18:17
  • From the exception, it appears SSL Handshake has failed. Since it worked locally, can you please let us know what Java version you are using locally, and if you are running this as a standalone Java program or in Application Server? – Vivin K Sep 26 '16 at 14:06
  • @VivinK Actually the problem is with IBM JDK, the one in official Liberty Profile docker distribution: java version "1.8.0" Java(TM) SE Runtime Environment (build pxa6480sr3-20160428_01(SR3)) IBM J9 VM (build 2.8, JRE 1.8.0 Linux amd64-64 Compressed References 20160427_301573 (JIT enabled, AOT enabled) J9VM - R28_Java8_SR3_20160427_1620_B301573 JIT - tr.r14.java.green_20160329_114288 GC - R28_Java8_SR3_20160427_1620_B301573_CMPRSS J9CL - 20160427_301573) JCL - 20160421_01 based on Oracle jdk8u91-b14 – icordoba Sep 27 '16 at 20:56
  • @Vivin K yes the problem really with IBM JDK as **icordoba** wrote in his comment – mibrahim.iti Sep 27 '16 at 21:08

1 Answers1

0

Based on a discussion with the Liberty for Java Team, we think that you are using a down-level version of the JDK. The current level of the buildpack now provides JRE 8.0: SR3 FP11. Try using the latest buildpack so that you can pick up the new JRE levels.