Package com.baasbox.service.push

Examples of com.baasbox.service.push.PushNotInitializedException


    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());
      }

    }
    //icallbackPush.onSuccess();
View Full Code Here

TOP

Related Classes of com.baasbox.service.push.PushNotInitializedException

Copyright © 2018 www.massapicom. 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.