javax.net.ssl.SSLHandshakeException:使用jetty库实现的HTTP2调用Apple



我正在使用这个代码,它在本地服务器上工作良好,但不能在BlueMix服务器上工作

 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();
         }
     }
 }

当我在BlueMix服务器上使用相同的代码时,它会抛出

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

javax.net.ssl.SSLHandshakeException: No negotiable cipher suite

根据与Liberty for Java团队的讨论,我们认为您正在使用JDK的底层版本。当前级别的构建包现在提供JRE 8.0: SR3 FP11。尝试使用最新的构建包,以便您可以选择新的JRE级别。

最新更新