Examples of ApnsService


Examples of com.notnoop.apns.ApnsService

    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
        ApnsService apnsService = apnsServiceFactory.getApnsService();

        ApnsComponent apnsComponent = new ApnsComponent(apnsService);
        camelContext.addComponent("apns", apnsComponent);

        return camelContext;
View Full Code Here

Examples of com.notnoop.apns.ApnsService

    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
        ApnsService apnsService = apnsServiceFactory.getApnsService();

        ApnsComponent apnsComponent = new ApnsComponent(apnsService);
        camelContext.addComponent("apns", apnsComponent);

        return camelContext;
View Full Code Here

Examples of com.notnoop.apns.ApnsService

            configureApnsCertificate(builder);
        } catch (IOException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }

        ApnsService apnsService = builder.build();
        return apnsService;
    }
View Full Code Here

Examples of com.notnoop.apns.ApnsService

    @Override
    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
        ApnsService apnsService = apnsServiceFactory.getApnsService();

        ApnsComponent apnsComponent = new ApnsComponent(apnsService);
        camelContext.addComponent("apns", apnsComponent);

        return camelContext;
View Full Code Here

Examples of com.notnoop.apns.ApnsService

    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ApnsServiceFactory apnsServiceFactory = ApnsUtils.createDefaultTestConfiguration(camelContext);
        ApnsService apnsService = apnsServiceFactory.getApnsService();

        ApnsComponent apnsComponent = new ApnsComponent(apnsService);

        camelContext.addComponent("apns", apnsComponent);
View Full Code Here

Examples of com.notnoop.apns.ApnsService

    if (Logger.isDebugEnabled()) Logger.debug("APN Push message: "+message+" to the device "+deviceid);
    if (!isInit) {
      return true;
    }

    ApnsService service = null;
    String payload = null;
    try{
      service=getService();
    } catch (com.notnoop.exceptions.InvalidSSLConfig e) {
      Logger.error("Error sending push notification");
      throw new PushNotInitializedException("Error decrypting certificate.Verify your password for given certificate");
      //icallbackPush.onError(e.getMessage());
    }


    JsonNode contentAvailableNode=bodyJson.findValue("content-available");
    Integer contentAvailable = null;
    if(!(contentAvailableNode == null)) {
      if(!(contentAvailableNode.isInt())) throw new PushContentAvailableFormatException("Content-available MUST be an Integer (1 for silent notification)");
      contentAvailable=contentAvailableNode.asInt();
    }
    if(contentAvailable!=1) {

      JsonNode categoryNode=bodyJson.findValue("category");
      String category = null;
      if(!(categoryNode == null)) {
        if(!(categoryNode.isTextual())) throw new PushCategoryFormatException("Category MUST be a String");
        category=categoryNode.asText();
      }

      JsonNode soundNode=bodyJson.findValue("sound");
      String sound =null;
      if (!(soundNode==null)) {
        if(!(soundNode.isTextual())) throw new PushSoundKeyFormatException("Sound value MUST be a String");
        sound=soundNode.asText();
      }

      JsonNode actionLocKeyNode=bodyJson.findValue("actionLocalizedKey");
      String actionLocKey=null;

      if (!(actionLocKeyNode==null)) {
        if(!(actionLocKeyNode.isTextual())) throw new PushActionLocalizedKeyFormatException("ActionLocalizedKey MUST be a String");
        actionLocKey=actionLocKeyNode.asText();
      }

      JsonNode locKeyNode=bodyJson.findValue("localizedKey");
      String locKey=null;

      if (!(locKeyNode==null)) {
        if(!(locKeyNode.isTextual())) throw new PushLocalizedKeyFormatException("LocalizedKey MUST be a String");
        locKey=locKeyNode.asText();
      }

      JsonNode locArgsNode=bodyJson.get("localizedArguments");

      List<String> locArgs = new ArrayList<String>();
      if(!(locArgsNode==null)){
        if(!(locArgsNode.isArray())) throw new PushLocalizedArgumentsFormatException("LocalizedArguments MUST be an Array of String");   
        for(JsonNode locArgNode : locArgsNode) {
          if(locArgNode.isNumber()) throw new PushLocalizedArgumentsFormatException("LocalizedArguments MUST be an Array of String");
          locArgs.add(locArgNode.toString());
       
      }

      JsonNode customDataNodes=bodyJson.get("custom");

      Map<String,JsonNode> customData = new HashMap<String,JsonNode>();

      if(!(customDataNodes==null)){
        if(customDataNodes.isTextual()) {
          customData.put("custom",customDataNodes);
        }
        else {
          for(JsonNode customDataNode : customDataNodes) {
            customData.put("custom", customDataNodes);
          }
        }
      }

      JsonNode badgeNode=bodyJson.findValue("badge");
      int badge=0;
      if(!(badgeNode==null)) {
        if(!(badgeNode.isNumber())) throw new PushBadgeFormatException("Badge value MUST be a number");
        else badge=badgeNode.asInt();
      }

      if (Logger.isDebugEnabled()) Logger.debug("APN Push message: "+message+" to the device "+deviceid +" with sound: " + sound + " with badge: " + badge + " with Action-Localized-Key: " + actionLocKey + " with Localized-Key: "+locKey);
      if (Logger.isDebugEnabled()) Logger.debug("Localized arguments: " + locArgs.toString());
      if (Logger.isDebugEnabled()) Logger.debug("Custom Data: " + customData.toString());


      payload = APNS.newPayload()
          .alertBody(message)
          .sound(sound)
          .actionKey(actionLocKey)
          .localizedKey(locKey)
          .localizedArguments(locArgs)
          .badge(badge)
          .customFields(customData)
          .category(category)
          .build();
    }

    else {
      payload=APNS.newPayload()
          .instantDeliveryOrSilentNotification()
          .build();

    }

    if(timeout<=0){
      try
        service.push(deviceid, payload)
      } catch (NetworkIOException e) {
        Logger.error("Error sending push notification");
        Logger.error(ExceptionUtils.getStackTrace(e));
        throw new PushNotInitializedException("Error processing certificate, maybe it's revoked");
        //icallbackPush.onError(e.getMessage());
      }
    } else {
      try {
        Date expiry = new Date(Long.MAX_VALUE);
        service.push(deviceid,payload,expiry);
      } catch (NetworkIOException e) {
        Logger.error("Error sending enhanced push notification");
        Logger.error(ExceptionUtils.getStackTrace(e));
        throw new PushNotInitializedException("Error processing certificate, maybe it's revoked");
        //icallbackPush.onError(e.getMessage());
View Full Code Here

Examples of com.notnoop.apns.ApnsService




  private  ApnsService getService() {
    ApnsService service;
    if (!sandbox) service=APNS.newService()
        .withCert(certificate, password).withProductionDestination().build();
    else  service=APNS.newService()
        .withCert(certificate, password)
        .withSandboxDestination()
View Full Code Here

Examples of com.notnoop.apns.ApnsService

            configureApnsCertificate(builder);
        } catch (IOException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }

        ApnsService apnsService = builder.build();
        return apnsService;
    }
View Full Code Here

Examples of com.notnoop.apns.ApnsService

    private static final long serialVersionUID = -1913999384798892563L;

    private final ConcurrentHashMap<String, ApnsService> apnsCache = new ConcurrentHashMap<String, ApnsService>();

    public ApnsService getApnsServiceForVariant(iOSVariant iOSVariant) {
        ApnsService variantService = null;
        synchronized (apnsCache) {
            String variantId = iOSVariant.getVariantID();
            variantService = apnsCache.get(variantId);

            if (variantService == null) {
View Full Code Here

Examples of com.notnoop.apns.ApnsService

        }

        // all good, let's build the JSON payload for APNs
        final String apnsMessage  =  builder.build();

        ApnsService service = buildApnsService(iOSVariant, callback);

        if (service != null) {
            try {
                logger.log(Level.FINE, "Sending transformed APNs payload: " + apnsMessage);
                // send:
                service.start();

                Date expireDate = createFutureDateBasedOnTTL(pushMessage.getTimeToLive());
                service.push(tokens, apnsMessage, expireDate);
                logger.log(Level.INFO, "Message to APNs has been submitted");

                // after sending, let's ask for the inactive tokens:
                final Set<String> inactiveTokens = service.getInactiveDevices().keySet();
                // transform the tokens to be all lower-case:
                final Set<String> transformedTokens = lowerCaseAllTokens(inactiveTokens);

                // trigger asynchronous deletion:
                if (! transformedTokens.isEmpty()) {
                    logger.log(Level.INFO, "Deleting '" + inactiveTokens.size() + "' invalid iOS installations");
                    clientInstallationService.removeInstallationsForVariantByDeviceTokens(iOSVariant.getVariantID(), transformedTokens);
                }
            } catch (RuntimeException e) {
                logger.log(Level.SEVERE, "Error sending messages to APN server", e);
            } finally {
                // tear down and release resources:
                service.stop();
            }
        } else {
            logger.log(Level.SEVERE, "No certificate was found. Could not send messages to APNs");
            callback.onError();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.