private String extractConnectionKey(final iOSVariant iOSVariant) { final StringBuilder sb = new StringBuilder() .append(iOSVariant.getVariantID()) .append(iOSVariant.isProduction() ? "-prod" : "-dev"); return sb.toString(); }
iOSVariant.setName(updatediOSVariant.getName()); iOSVariant.setDescription(updatediOSVariant.getDescription()); iOSVariant.setProduction(updatediOSVariant.isProduction()); logger.trace("Updating text details on iOS Variant '{}'", iOSID);
iOSVariant.setName(updatedForm.getName()); iOSVariant.setDescription(updatedForm.getDescription()); iOSVariant.setPassphrase(updatedForm.getPassphrase()); iOSVariant.setCertificate(updatedForm.getCertificate()); iOSVariant.setProduction(updatedForm.getProduction()); validateModelClass(iOSVariant); } catch (ConstraintViolationException cve) { logger.info("Unable to update iOS Variant '{}'", iOSVariant.getVariantID()); logger.debug("Details: {}", cve); logger.trace("Updating iOS Variant '{}'", iOSVariant.getVariantID()); variantUpdateEventEvent.fire(new iOSVariantUpdateEvent(iOSVariant)); variantService.updateVariant(iOSVariant);
if (!ApnsUtil.checkValidity(iOSVariant.getCertificate(), iOSVariant.getPassphrase().toCharArray())) { senderCallback.onError("The provided certificate is invalid or expired for variant " + iOSVariant.getId()); return; final String defaultApnsTopic = ApnsUtil.readDefaultTopic(iOSVariant.getCertificate(), iOSVariant.getPassphrase().toCharArray()); logger.debug("sending payload for all tokens for {} to APNs ({})", iOSVariant.getVariantID(), defaultApnsTopic);
/** * Receives iOS variant change event to remove client from the cache and also tear down the connection. * @param iOSVariantUpdateEvent event fired when updating the variant */ public void disconnectOnChange(@Observes final iOSVariantUpdateEvent iOSVariantUpdateEvent) { final iOSVariant variant = iOSVariantUpdateEvent.getiOSVariant(); final String connectionKey = extractConnectionKey(variant); final ApnsClient client = apnsClientExpiringMap.remove(connectionKey); logger.debug("Removed client from cache for {}", variant.getVariantID()); if (client != null) { tearDownApnsHttp2Connection(client); } }
if (iOSVariant.isProduction()) { apnsHost = ApnsClient.PRODUCTION_APNS_HOST; } else {
private ApnsClient buildApnsClient(final iOSVariant iOSVariant) { // this check should not be needed, but you never know: if (iOSVariant.getCertificate() != null && iOSVariant.getPassphrase() != null) { // add the certificate: try(final ByteArrayInputStream stream = new ByteArrayInputStream(iOSVariant.getCertificate())) { final ApnsClientBuilder builder = new ApnsClientBuilder(); builder.setClientCredentials(stream, iOSVariant.getPassphrase()); if (ProxyConfiguration.hasHttpProxyConfig()) { if (ProxyConfiguration.hasBasicAuth()) { String user = ProxyConfiguration.getProxyUser(); String pass = ProxyConfiguration.getProxyPass(); builder.setProxyHandlerFactory(new HttpProxyHandlerFactory(ProxyConfiguration.proxyAddress(), user, pass)); } else { builder.setProxyHandlerFactory(new HttpProxyHandlerFactory(ProxyConfiguration.proxyAddress())); } } else if (ProxyConfiguration.hasSocksProxyConfig()) { builder.setProxyHandlerFactory(new Socks5ProxyHandlerFactory(ProxyConfiguration.socks())); } final ApnsClient apnsClient = builder.build(); return apnsClient; } catch (Exception e) { logger.error("Error reading certificate", e); // will be thrown below } } // indicating an incomplete service throw new IllegalArgumentException("Not able to construct APNS client"); }
iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setName(form.getName()); iOSVariant.setDescription(form.getDescription()); iOSVariant.setPassphrase(form.getPassphrase()); iOSVariant.setCertificate(form.getCertificate()); iOSVariant.setProduction(form.getProduction()); return Response.created(uriInfo.getAbsolutePathBuilder().path(String.valueOf(iOSVariant.getVariantID())).build()).entity(iOSVariant).build();
if (!ApnsUtil.checkValidity(iOSVariant.getCertificate(), iOSVariant.getPassphrase().toCharArray())) { senderCallback.onError("The provided certificate is invalid or expired for variant " + iOSVariant.getId()); return; final String defaultApnsTopic = ApnsUtil.readDefaultTopic(iOSVariant.getCertificate(), iOSVariant.getPassphrase().toCharArray()); logger.debug("sending payload for all tokens for {} to APNs ({})", iOSVariant.getVariantID(), defaultApnsTopic);
/** * Receives iOS variant change event to remove client from the cache and also tear down the connection. * @param iOSVariantUpdateEvent event fired when updating the variant */ public void disconnectOnChange(@Observes final iOSVariantUpdateEvent iOSVariantUpdateEvent) { final iOSVariant variant = iOSVariantUpdateEvent.getiOSVariant(); final String connectionKey = extractConnectionKey(variant); final ApnsClient client = apnsClientExpiringMap.remove(connectionKey); logger.debug("Removed client from cache for {}", variant.getVariantID()); if (client != null) { tearDownApnsHttp2Connection(client); } }
if (iOSVariant.isProduction()) { apnsHost = ApnsClient.PRODUCTION_APNS_HOST; } else {
private ApnsClient buildApnsClient(final iOSVariant iOSVariant) { // this check should not be needed, but you never know: if (iOSVariant.getCertificate() != null && iOSVariant.getPassphrase() != null) { // add the certificate: try(final ByteArrayInputStream stream = new ByteArrayInputStream(iOSVariant.getCertificate())) { final ApnsClientBuilder builder = new ApnsClientBuilder(); builder.setClientCredentials(stream, iOSVariant.getPassphrase()); if (ProxyConfiguration.hasHttpProxyConfig()) { if (ProxyConfiguration.hasBasicAuth()) { String user = ProxyConfiguration.getProxyUser(); String pass = ProxyConfiguration.getProxyPass(); builder.setProxyHandlerFactory(new HttpProxyHandlerFactory(ProxyConfiguration.proxyAddress(), user, pass)); } else { builder.setProxyHandlerFactory(new HttpProxyHandlerFactory(ProxyConfiguration.proxyAddress())); } } else if (ProxyConfiguration.hasSocksProxyConfig()) { builder.setProxyHandlerFactory(new Socks5ProxyHandlerFactory(ProxyConfiguration.socks())); } final ApnsClient apnsClient = builder.build(); return apnsClient; } catch (Exception e) { logger.error("Error reading certificate", e); // will be thrown below } } // indicating an incomplete service throw new IllegalArgumentException("Not able to construct APNS client"); }
private String extractConnectionKey(final iOSVariant iOSVariant) { final StringBuilder sb = new StringBuilder() .append(iOSVariant.getVariantID()) .append(iOSVariant.isProduction() ? "-prod" : "-dev"); return sb.toString(); }
private ApnsClient receiveApnsConnection(final iOSVariant iOSVariant) { return simpleApnsClientCache.getApnsClientForVariant(iOSVariant, () -> { final ApnsClient apnsClient = buildApnsClient(iOSVariant); if (apnsClient != null) { // connect and wait, ONLY when we have a valid client logger.debug("establishing the connection for {}", iOSVariant.getVariantID()); connectToDestinations(iOSVariant, apnsClient); // APNS client has auto-reconnect, but let's log when that happens apnsClient.getReconnectionFuture().addListener(future -> logger.trace("Reconnecting to APNs")); return apnsClient; } return null; }); }
private ApnsClient receiveApnsConnection(final iOSVariant iOSVariant) { return simpleApnsClientCache.getApnsClientForVariant(iOSVariant, () -> { final ApnsClient apnsClient = buildApnsClient(iOSVariant); if (apnsClient != null) { // connect and wait, ONLY when we have a valid client logger.debug("establishing the connection for {}", iOSVariant.getVariantID()); connectToDestinations(iOSVariant, apnsClient); // APNS client has auto-reconnect, but let's log when that happens apnsClient.getReconnectionFuture().addListener(future -> logger.trace("Reconnecting to APNs")); return apnsClient; } return null; }); }