From 7f6bc74796f1d885c1f21c5109cf655d3d472107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=B0=E5=B9=B3=E7=BA=BF?= <22250530@qq.com> Date: Sun, 6 Sep 2015 14:40:22 +0800 Subject: [PATCH] --- .../wentch/redkale/service/apns/ApnsService.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java index c02733094..b0546ee22 100644 --- a/src-plugin/com/wentch/redkale/service/apns/ApnsService.java +++ b/src-plugin/com/wentch/redkale/service/apns/ApnsService.java @@ -71,15 +71,18 @@ public class ApnsService implements Service { final String path = "/" + this.getClass().getPackage().getName().replace('.', '/') + "/" + apnscertpath; KeyStore ks = KeyStore.getInstance("PKCS12"); InputStream in = ApnsService.class.getResourceAsStream(path); - ks.load(in, apnscertpwd.toCharArray()); - in.close(); - KeyManagerFactory kf = KeyManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - kf.init(ks, apnscertpwd.toCharArray()); + KeyManagerFactory kf = null; + if (in != null) { + ks.load(in, apnscertpwd.toCharArray()); + in.close(); + kf = KeyManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + kf.init(ks, apnscertpwd.toCharArray()); + } TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init((KeyStore) null); SSLContext context = SSLContext.getInstance("TLS"); - context.init(kf.getKeyManagers(), tmf.getTrustManagers(), null); + context.init(kf == null ? new KeyManager[0] : kf.getKeyManagers(), tmf.getTrustManagers(), null); ApnsService.this.sslFactory = context.getSocketFactory(); } catch (Exception e) { logger.log(Level.SEVERE, this.getClass().getSimpleName() + " init SSLContext error", e);