@Override public void start() throws Exception { byte[] pushKeyStore = initializeKeyStore(pushCertificate, pushKey); byte[] voipKeyStore = initializeKeyStore(voipCertificate, voipKey); this.pushApnService = APNS.newService() .withCert(new ByteArrayInputStream(pushKeyStore), "insecure") .asQueued() .withProductionDestination().build(); this.voipApnService = APNS.newService() .withCert(new ByteArrayInputStream(voipKeyStore), "insecure") .asQueued() .withProductionDestination().build(); if (feedbackEnabled) { this.executor.scheduleAtFixedRate(new FeedbackRunnable(), 0, 1, TimeUnit.HOURS); } }
/** * Constructs a pool of connections to the notification servers. * * Apple servers recommend using a pooled connection up to * 15 concurrent persistent connections to the gateways. * * Note: This option has no effect when using non-blocking * connections. */ public ApnsServiceBuilder asPool(int maxConnections) { return asPool(Executors.newFixedThreadPool(maxConnections), maxConnections); }
/** * Specify to use the Apple sandbox servers as iPhone gateway * and feedback servers. * * This is desired when in testing and pushing notifications * with a development provision. * * @return this */ public ApnsServiceBuilder withSandboxDestination() { return withGatewayDestination(SANDBOX_GATEWAY_HOST, SANDBOX_GATEWAY_PORT) .withFeedbackDestination(SANDBOX_FEEDBACK_HOST, SANDBOX_FEEDBACK_PORT); }
/** * Specify to use Apple servers as iPhone gateway and feedback servers. * * If the passed {@code isProduction} is true, then it connects to the * production servers, otherwise, it connects to the sandbox servers * * @param isProduction determines which Apple servers should be used: * production or sandbox * @return this */ public ApnsServiceBuilder withAppleDestination(boolean isProduction) { if (isProduction) { return withProductionDestination(); } else { return withSandboxDestination(); } }
private void configureApnsCertificate(ApnsServiceBuilder builder) throws IOException, GeneralSecurityException { if (getSslContextParameters() != null) { builder.withSSLContext(getSslContextParameters().createSSLContext(getCamelContext())); return; } ObjectHelper.notNull(getCamelContext(), "camelContext"); StringHelper.notEmpty(getCertificatePath(), "certificatePath"); StringHelper.notEmpty(getCertificatePassword(), "certificatePassword"); InputStream certificateInputStream = null; try { certificateInputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, getCertificatePath()); builder.withCert(certificateInputStream, getCertificatePassword()); } finally { ResourceUtils.close(certificateInputStream); } }
private void configureConnectionStrategy(ApnsServiceBuilder builder) { if (getConnectionStrategy() == ConnectionStrategy.POOL) { AssertUtils.isTrue(poolSize >= MIN_POOL_SIZE, "Pool size needs to be greater than: " + MIN_POOL_SIZE); AssertUtils.isTrue(poolSize <= MAX_POOL_SIZE, "Pool size needs to be lower than: " + MAX_POOL_SIZE); } if (getConnectionStrategy() == null) { return; } switch (getConnectionStrategy()) { case QUEUE: builder.asQueued(); break; case POOL: builder.asPool(getPoolSize()); break; default: break; } }
/** * Specify the certificate used to connect to Apple APNS * servers. This relies on a keystore (*.p12) * containing the certificate, along with the given password. * * This library does not support password-less p12 certificates, due to a * Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> * Bug 6415637</a>. There are three workarounds: use a password-protected * certificate, use a different boot Java SDK implementation, or constract * the `SSLContext` yourself! Needless to say, the password-protected * certificate is most recommended option. * * @param stream the keystore * @param password the password of the keystore * @return this * @throws InvalidSSLConfig if stream is invalid Keystore * or the password is invalid */ public ApnsServiceBuilder withCert(KeyStore keyStore, String password) throws InvalidSSLConfig { assertPasswordNotEmpty(password); return withSSLContext( newSSLContext(keyStore, password, KEY_ALGORITHM)); }
try { stream = new FileInputStream(fileName); return withCert(stream, password); } catch (FileNotFoundException e) { throw new RuntimeIOException(e);
public ApnsService getApnsService() { ApnsServiceBuilder builder = APNS.newService(); builder = configureServiceBuilder(builder); configureConnectionStrategy(builder); configureReconnectionPolicy(builder); configureApnsDelegate(builder); configureApnsDestinations(builder); try { configureApnsCertificate(builder); } catch (IOException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } catch (GeneralSecurityException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } ApnsService apnsService = builder.build(); return apnsService; }
/** * Returns a new APNS Service for sending iPhone notifications */ public static ApnsServiceBuilder newService() { return new ApnsServiceBuilder(); } }
/** * Specify the certificate used to connect to Apple APNS * servers. This relies on the stream of keystore (*.p12) * containing the certificate, along with the given password. * * The keystore needs to be of PKCS12 and the keystore * needs to be encrypted using the SunX509 algorithm. Both * of these settings are the default. * * This library does not support password-less p12 certificates, due to a * Oracle Java library <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6415637"> * Bug 6415637</a>. There are three workarounds: use a password-protected * certificate, use a different boot Java SDK implementation, or constract * the `SSLContext` yourself! Needless to say, the password-protected * certificate is most recommended option. * * @param stream the keystore represented as input stream * @param password the password of the keystore * @return this * @throws InvalidSSLConfig if stream is invalid Keystore * or the password is invalid */ public ApnsServiceBuilder withCert(InputStream stream, String password) throws InvalidSSLConfig { assertPasswordNotEmpty(password); return withSSLContext( newSSLContext(stream, password, KEYSTORE_TYPE, KEY_ALGORITHM)); }
/** * Specify to use the Apple Production servers as iPhone gateway * and feedback servers. * * This is desired when sending notifications to devices with * a production provision (whether through App Store or Ad hoc * distribution). * * @return this */ public ApnsServiceBuilder withProductionDestination() { return withGatewayDestination(PRODUCTION_GATEWAY_HOST, PRODUCTION_GATEWAY_PORT) .withFeedbackDestination(PRODUCTION_FEEDBACK_HOST, PRODUCTION_FEEDBACK_PORT); }
private void configureApnsDestinations(ApnsServiceBuilder builder) { ParamUtils.checkDestination(getGatewayHost(), getGatewayPort(), "gateway"); ParamUtils.checkDestination(getFeedbackHost(), getFeedbackPort(), "feedback"); if (ObjectHelper.isNotEmpty(getGatewayHost())) { builder.withGatewayDestination(getGatewayHost(), getGatewayPort()); } if (ObjectHelper.isNotEmpty(getFeedbackHost())) { builder.withFeedbackDestination(getFeedbackHost(), getFeedbackPort()); } }