我正在使用这段代码,它在本地服务器上运行良好,但在 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 的低版本。当前级别的 buildpack 现在提供 JRE 8.0:SR3 FP11。尝试使用最新的构建包,以便您可以获取新的 JRE 级别。
我是一名优秀的程序员,十分优秀!