Package com.comcast.cmb.common.util

Examples of com.comcast.cmb.common.util.CMBException


  }
 
  public void checkIsValid() throws CMBException {

    if (arn == null) {
      throw new CMBException(CMBErrorCodes.InternalError, "Must set arn for subscription");
    }
   
    if (!com.comcast.cns.util.Util.isValidTopicArn(arn)) {
      throw new CMBException(CMBErrorCodes.InternalError, "Invalid topic arn");
    }

    if (name == null) {
      throw new CMBException(CMBErrorCodes.InternalError, "Must set name for subscription");
    }
   
    if (userId == null) {
      throw new CMBException(CMBErrorCodes.InternalError, "Must set user id for subscription");
    }
  }
View Full Code Here


        } catch (TopicNotFoundException e) {
            logger.error("event=parse_publish_job error_code=topic_not_found topic_arn=" + topicArn, e);
            throw e;
        } catch (Exception e) {
            logger.error("event=parse_publish_job", e);
            throw new CMBException(CMBErrorCodes.InternalError, e.getMessage());
        }

        idx += numSubInfos;
       
        StringBuffer sb = new StringBuffer();
        for (int j = idx; j < arr.length; j++) {
            if (j != idx) {
                sb.append("\n");
            }
            sb.append(arr[j]);
        }
       
        CNSMessage message = null;

        try {
            message = CNSMessage.parseInstance(sb.toString());
        } catch(Exception e) {
            logger.error("event=parse_publish_job cnsmessage_serialized=" + sb.toString(), e);
            throw new CMBException(CMBErrorCodes.InternalError, e.getMessage());
        }
       
        return new CNSCachedEndpointPublishJob(message, subInfos);
    }
View Full Code Here

    String errorMessage = "";
    boolean error = false;
    if (!json.has("http")) {
      errorMessage = "Topic Delivery Policy missing policy for http";
      logger.error("event=construct_cns_topic_delivery_policy message=" + errorMessage);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, errorMessage);
    }
    try
      JSONObject json2 = json.getJSONObject("http");
      if (json2.length() == 0) {
          throw new Exception("Empty http protocol");
      }
     
      for (Iterator<String> keys = json2.keys(); keys.hasNext();) {
          String key = keys.next();
        if (!(key.equals("defaultHealthyRetryPolicy") || key.equals("defaultSicklyRetryPolicy"|| key.equals("disableSubscriptionOverrides") ||
            key.equals("defaultThrottlePolicy"))) {
          throw new Exception("Empty http delivery policy does not have key:" + key);
        }
      }
      if (json2.has("defaultHealthyRetryPolicy") && (json2.get("defaultHealthyRetryPolicy") != JSONObject.NULL)) {
        try {
          defaultHealthyRetryPolicy = new CNSRetryPolicy(json2.getJSONObject("defaultHealthyRetryPolicy"));
        } catch (Exception e) {
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            errorMessage = "DeliveryPolicy: defaultHealthyRetryPolicy." + message;
            error = true;
          }
        }         
      } else {
        defaultHealthyRetryPolicy = new CNSRetryPolicy();
      }
      if ((json2.has("defaultSicklyRetryPolicy"))) {
        if (json2.get("defaultSicklyRetryPolicy") == JSONObject.NULL) defaultSicklyRetryPolicy = null;
        else {
          try {
            defaultSicklyRetryPolicy = new CNSRetryPolicy(json2.getJSONObject("defaultSicklyRetryPolicy"));
          } catch (Exception e) {
            if (e instanceof CNSModelConstructionException) {
              String message = ((CNSModelConstructionException) e).getErrormessage();
              errorMessage = "DeliveryPolicy: defaultSicklyRetryPolicy." + message;
              error = true;
            }
          } 
        }
      }
     
      if ((json2.has("disableSubscriptionOverrides"))) {
        disableSubscriptionOverrides = json2.getBoolean("disableSubscriptionOverrides");
      } else {
        disableSubscriptionOverrides = false;
      }
     
      if ((json2.has("defaultThrottlePolicy")) && (json2.get("defaultThrottlePolicy") != JSONObject.NULL)) {
        try {
          defaultThrottlePolicy = new CNSThrottlePolicy(json2.getJSONObject("defaultThrottlePolicy"));
        } catch (Exception e) {
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            errorMessage = "DeliveryPolicy: defaultThrottlePolicy." + message;
            error = true;
          }
        } 
      } else {
        defaultThrottlePolicy = new CNSThrottlePolicy();
      }
       
     
    } catch (Exception e) {
      logger.error("event=construct_cns_topic_delivery_policy", e);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,e.getMessage());
    }
    if (error) {
      logger.error("event=update_cns_topic_delivery_policy message=" + errorMessage);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, errorMessage);
    }
  }
View Full Code Here

     */
  public void update(JSONObject json) throws CNSModelConstructionException, CMBException {
    if (!json.has("http")) {
      String errorMessage = "Topic Delivery Policy missing policy for http";
      logger.error("event=update_cns_topic_delivery_policy message=" + errorMessage);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, errorMessage);
    }
    String errorMessage = "";
    boolean error = false;
    try
      CNSRetryPolicy ldefaultHealthyRetryPolicy = null;
      CNSRetryPolicy ldefaultSicklyRetryPolicy = null;
      CNSThrottlePolicy ldefaultThrottlePolicy = null;
      boolean ldisableSubscriptionOverrides = false;
     
     
      JSONObject json2 = json.getJSONObject("http");
   
      if (json2.has("defaultHealthyRetryPolicy") && (json2.get("defaultHealthyRetryPolicy") != JSONObject.NULL)) {
        try {
          ldefaultHealthyRetryPolicy = new CNSRetryPolicy(json2.getJSONObject("defaultHealthyRetryPolicy"));
        } catch (Exception e) {
          if(e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            errorMessage = "DeliveryPolicy: defaultHealthyRetryPolicy." + message;
            error = true;
          }
        } 
      } else {
        ldefaultHealthyRetryPolicy = new CNSRetryPolicy();
      }
      if ((json2.has("defaultSicklyRetryPolicy")) &&(json2.get("defaultSicklyRetryPolicy") != JSONObject.NULL)) {
        try {
          ldefaultSicklyRetryPolicy = new CNSRetryPolicy(json2.getJSONObject("defaultSicklyRetryPolicy"));
        } catch (Exception e) {
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            errorMessage = "DeliveryPolicy: defaultSicklyRetryPolicy." + message;
            error = true;
          }
        } 
      } else {
        ldefaultSicklyRetryPolicy = null;
      }
     
      if ((json2.has("disableSubscriptionOverrides"))) {
        try {
          ldisableSubscriptionOverrides = json2.getBoolean("disableSubscriptionOverrides");
        } catch (Exception e) {
          errorMessage = "DeliveryPolicy: disableSubscriptionOverrides must be a boolean";
          error = true;
       
      } else {
        ldisableSubscriptionOverrides = false;
      }
     
      if ((json2.has("defaultThrottlePolicy")) && (json2.get("defaultThrottlePolicy") != JSONObject.NULL)) {
        try {
          ldefaultThrottlePolicy = new CNSThrottlePolicy(json2.getJSONObject("defaultThrottlePolicy"));
        } catch (Exception e) {
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            errorMessage = "DeliveryPolicy: defaultThrottlePolicy." + message;
            error = true;
          }
        } 
      } else {
        ldefaultThrottlePolicy = new CNSThrottlePolicy();
      }
      if (!error) {
        defaultHealthyRetryPolicy = ldefaultHealthyRetryPolicy;
        defaultSicklyRetryPolicy = ldefaultSicklyRetryPolicy;
        disableSubscriptionOverrides = ldisableSubscriptionOverrides;
        defaultThrottlePolicy = ldefaultThrottlePolicy;
      }
     
    } catch (Exception e) {
      logger.error("event=update_cns_topic_delivery_policy", e);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: JSON exception");
    }
    if (error) {
      logger.error("event=update_cns_topic_delivery_policy message=" + errorMessage);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter, errorMessage);
    }
  }
View Full Code Here

          if(operation.equals("startWorker")){
            operationString = "start";
          } else {
            operationString = "stop";
          }
          throw new CMBException(CMBErrorCodes.InternalError, "Cannot " + operationString + " CNS workers");
        } finally {

          if (jmxConnector != null) {
            jmxConnector.close();
          }
View Full Code Here

        } catch (Exception e) {
         
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            logger.error("event=construct_cns_subscription_delivery_policy", e);
            throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: healthyRetryPolicy." + message);
          }
        }
       
      } else {
        healthyRetryPolicy = new CNSRetryPolicy();
      }
     
      if (json.has("sicklyRetryPolicy") && (json.get("sicklyRetryPolicy") != JSONObject.NULL)) {
       
        try {
         
          sicklyRetryPolicy = new CNSRetryPolicy(json.getJSONObject("sicklyRetryPolicy"));
         
        } catch (Exception e) {
         
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: sicklyRetryPolicy." + message);
          }
        }
       
      } else {
        sicklyRetryPolicy = null;
      }
     
      if (json.has("throttlePolicy") && (json.get("throttlePolicy") != JSONObject.NULL)) {
       
        try {
         
          throttlePolicy = new CNSThrottlePolicy(json.getJSONObject("throttlePolicy"));
         
        } catch (Exception e) {
         
          if (e instanceof CNSModelConstructionException) {
            String message = ((CNSModelConstructionException) e).getErrormessage();
            throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: throttlePolicy." + message);
          }
        }
       
      } else {
        throttlePolicy = new CNSThrottlePolicy();
      }
     
    } catch (Exception e) {
     
      if (e instanceof CMBException) {
        throw e;
      } else {
        throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: JSON exception");
      }
    }
   
  }
View Full Code Here

        throttlePolicy = lthrottlePolicy;
      }
     
    } catch (Exception e) {
      logger.error("event=cns_update_subscription_delivery_policy", e);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,"DeliveryPolicy: JSON exception");
    }
   
    if (error) {
      logger.error("event=cns_update_subscription_delivery_policy message=" + errorMessage);
      throw new CMBException(CNSErrorCodes.CNS_InvalidParameter,errorMessage);
    }
  }
View Full Code Here

    if (protocol.equals(CnsSubscriptionProtocol.cqs)) {
     
      CQSQueue queue = PersistenceFactory.getQueuePersistence().getQueue(com.comcast.cqs.util.Util.getRelativeQueueUrlForArn(endpoint));
     
      if (queue == null) {
        throw new CMBException(CMBErrorCodes.NotFound, "Queue with arn " + endpoint + " does not exist.");
      }
    }
   
    subscription.setArn(Util.generateCnsTopicSubscriptionArn(topicArn, protocol, endpoint));
 
View Full Code Here

   
      //get Sub-arn given token
      CmbColumnSlice<String, String> slice = cassandraHandler.readColumnSlice(AbstractDurablePersistence.CNS_KEYSPACE, columnFamilySubscriptionsTokenIndex, token, null, null, 1, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
     
      if (slice == null) {
          throw new CMBException(CMBErrorCodes.NotFound, "Resource not found.");
      }
     
      //get Column from main table
      String subArn = slice.getColumns().get(0).getName();
     
View Full Code Here

     * @throws CMBException if message constraints are not met.
     */
    public void checkIsValid() throws CMBException {
     
        if (message == null) {
          throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Message is null");
        }
       
        if (topicArn == null) {
          throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "TopicArn is null");
        }
       
        if (userId == null) {
          throw new CMBException(CMBErrorCodes.InternalError, "Must set userId of CNSMessage");
        }
       
        if (messageId == null) {
          throw new CMBException(CMBErrorCodes.InternalError, "Must set messageId of CNSMessage");
        }
       
        if (timestamp == null) {
          throw new CMBException(CMBErrorCodes.InternalError, "Must set timestamp of CNSMessage");
        }

        if (!Util.isValidUnicode(message)) {
            throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Message not UTF-8 characters");
        }
       
        if (message.getBytes().length > CMBProperties.getInstance().getCNSMaxMessageSize()) {
            throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Message greater than " + CMBProperties.getInstance().getCNSMaxMessageSize() + " bytes");
        }
       
        if (messageStructure == CNSMessageStructure.json) {
         
            JSONObject json = null;
           
            try {
                json = new JSONObject(message);
            } catch (JSONException e) {
                throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "messageStructure set to json but Message is not a valid JSON string:" + e.getMessage());
            }
           
            //validate json-keys as either 'default' or valid protocols.
           
            if (!json.has("default")) {
                throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Must provide 'default' key in JSON Object");
            }
           
            for (Iterator<?> it = json.keys(); it.hasNext(); ) {
             
                String key = (String) it.next();
               
                if (key.equals("default")) {
                  continue;
                }
               
                if (key.equals("email-json")) {
                  continue;
                }
               
                try {
                    CnsSubscriptionProtocol.valueOf(key);
                } catch (Exception e) {
                    throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "messageStructure keys must either be 'default' or a valid protocol name: " + e.getMessage());
                }
            }
        }       
       
        //subject validation
       
        if (subject != null) {
            if (subject.toCharArray().length >= 100) {
                throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Subject cannot be longer than 100 characters");
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.comcast.cmb.common.util.CMBException

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.