APNSConnectionFactory { @Nonnull private SSLSocket createConnection(@Nonnull final String host, @Nonnull final Integer port) throws APNSGatewayConnectionException { assert host != null; assert port != null; final KeyStore keyStore = getKeyStore(p12KeyStorePath, p12KeyStorePassword); final SSLContext sslcontext = getSSLContext(keyStore, p12KeyStorePassword); try { final SSLSocketFactory factory = sslcontext.getSocketFactory(); LOG.debug("createConnection: returning connection from SSLSocketFactory, host={}, port={}", host, port); return (SSLSocket) factory.createSocket(host, port); } catch (final IOException e) { LOG.warn("createConnection: could not connect, host={}, port={}", host, port); throw new APNSGatewayConnectionException("Could not connect to: " + host + ':' + port, e); } } APNSConnectionFactory(@Nonnull final String gatewayHost,
                                 @Nonnull final Integer gatewayPort,
                                 @Nonnull final String feedbackHost,
                                 @Nonnull final Integer feedbackPort,
                                 @Nonnull final String p12KeyStorePath,
                                 @Nonnull final String p12KeyStorePassword); @Nonnull APNSGatewayConnection createPushConnection(); @Nonnull APNSGatewayConnection createFeedbackConnection();  }
@Ignore @Test public void testCreateConnection() throws APNSGatewayConnectionException { LOG.info("testCreateConnection"); apnsConnectionFactory = new APNSConnectionFactory("gateway.sandbox.push.apple.com", 2195, "feedback.sandbox.push.apple.com", 2196, "/com/tomtom/speedtools/push/implementation/apns/place-your-certificate-here-for-apns-sandbox.p12", "<password>"); final APNSGatewayConnection connection = apnsConnectionFactory.createPushConnection(); Assert.assertNotNull(connection); connection.close(); }