Пример #1
0
  /**
   * This adds a special check for exceptions that occured because the session is down. In this
   * case, the error count will not be increased so that the message will be resent when the session
   * comes back up.
   *
   * @param e Exception
   * @param queueMessage QueueMessage
   * @param queue MessageQueue
   * @throws QueueException
   */
  public void handleError(Exception e, QueueMessage queueMessage, MessageQueue queue)
      throws QueueException {

    if (e instanceof ConnectivityDownException) {

      // The session is down. Set the error message, but do not
      // increment the error count.
      NPACMessageType message = (NPACMessageType) queueMessage;
      NPACQueueUtils.updateLastErrorMessage(message.getInvokeID().toString(), e.getMessage());

    } else {

      if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
        Debug.log(
            Debug.MSG_STATUS,
            "NPACConsumerPolicy, handleError(), Before removing REGION ID...queueMessage.getValues():-"
                + queueMessage.getValues());
      }

      Map queueMessageValues = queueMessage.getValues();

      if (queueMessageValues.containsKey("REGIONID")) {
        queueMessageValues.remove("REGIONID");
        queueMessage.setValues(queueMessageValues);
      }

      if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
        Debug.log(
            Debug.MSG_STATUS,
            "NPACConsumerPolicy, handleError(), After removing REGION ID...queueMessage.getValues():-"
                + queueMessage.getValues());
      }
      super.handleError(e, queueMessage, queue);
    }
  }
  /**
   * Stops all the running Poll Comm Servers.
   *
   * @throws ProcessingException
   */
  public void stopAll() throws ProcessingException {
    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "Stopping all poll comm servers : " + getType());

    Iterator iter = commServerConfMap.keySet().iterator();

    while (iter.hasNext()) {
      String id = (String) iter.next();
      Map map = Collections.singletonMap(ATTR_COMM_SERVER_ID, id);
      Notification notification = null;
      try {
        stop(map);
        notification = new Notification("Stopped poll comm server : " + id);
      } catch (Exception e) {
        Debug.log(
            Debug.MSG_WARNING,
            "Exception while stopping poll comm server " + id + " " + e.getMessage());
        Debug.log(Debug.MSG_WARNING, e.getMessage());
        notification =
            new Notification("Exception occured while stopping Poll Comm Server: " + id, e);
      }
      notificationHandler.handle(notification);
    }
    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "done stopping all services .. ");
  }
Пример #3
0
  /**
   * This method loads properties in virtual machine.
   *
   * @param key - Ket value of persistentproperty.
   * @param type - Type value of persistentproperty.
   * @exception - ProcessingException - this exception is thrown by super class for any problem with
   *     initialization .
   */
  public void initialize(String key, String type) throws ProcessingException {
    Debug.log(this, Debug.DB_STATUS, "Loading properties for RTF generator.");
    super.initialize(key, type);

    nextProcessor = (String) adapterProperties.get(NEXT_PROCESSOR_NAME);
    startDelimiter = (String) adapterProperties.get(START_DELIMITER);
    endDelimiter = (String) adapterProperties.get(END_DELIMITER);
    rtfTemplate = (String) adapterProperties.get(RTF_TEMPLATE);

    if (nextProcessor == null
        || startDelimiter == null
        || endDelimiter == null
        || rtfTemplate == null
        || nextProcessor.equals("")
        || startDelimiter.equals("")
        || endDelimiter.equals("")
        || rtfTemplate.equals("")) {
      Debug.log(
          this,
          Debug.ALL_ERRORS,
          "ERROR: RTFGenerator: One or more RTF generator properties are missing.");
      throw new ProcessingException(
          "ERROR: RTFGenerator: One or more properties from persistentproperty"
              + " could not be loaded or are null");
    }
  }
  /**
   * Get all configuration for a specified server type placed in repository. This would search the
   * servicemgr category inside repository and apply XPath to figure out configuration files
   * belonging to a specific server type.
   *
   * @param type
   * @return List containing file names.
   * @throws ProcessingException
   */
  public static List<String> getConfigCategory(String type) throws ProcessingException {

    NVPair[] pairs = null;
    try {
      pairs =
          RepositoryManager.getInstance()
              .listMetaData(ServerManagerFactory.MGR_CONFIG_CATEGORY, false, XML_FILE_SUFFIX);

      if (pairs == null || pairs.length == 0) {
        Debug.log(
            Debug.NORMAL_STATUS,
            "No XML file found in repository folder ["
                + ServerManagerFactory.MGR_CONFIG_CATEGORY
                + "]");

        return null;
      }
    } catch (Exception e) {
      Debug.error(
          "An exception occured while listing xml files from repository folder ["
              + ServerManagerFactory.MGR_CONFIG_CATEGORY
              + "]");

      Debug.logStackTrace(e);

      throw new ProcessingException(
          "An exception occured while listing xml files from repository folder  ["
              + ServerManagerFactory.MGR_CONFIG_CATEGORY
              + "]");
    }

    List<String> cfgFileLst = new ArrayList<String>();
    String fileNm = null;
    try {
      for (int j = 0; j < pairs.length; j++) {
        fileNm = pairs[j].name;
        Document document = getDocument(fileNm);
        ParsedXPath parseXpath = new ParsedXPath(serverType2Xpath.get(type));

        if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
          Debug.log(Debug.NORMAL_STATUS, " --> Evaluating file :" + fileNm + " for type :" + type);

        if (parseXpath.getBooleanValue(document.getDocumentElement())) cfgFileLst.add(fileNm);
      }

      if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
        Debug.log(
            Debug.NORMAL_STATUS,
            " --> returning list of files for type[" + type + "] : " + cfgFileLst);

      return cfgFileLst;
    } catch (Exception e) {
      Debug.log(
          Debug.NORMAL_STATUS,
          "Failed to parse and evaluate XPath on file :" + fileNm + "\n" + Debug.getStackTrace(e));

      throw new ProcessingException(
          "Failed to parse and evaluate XPath on file :" + fileNm + "\n" + Debug.getStackTrace(e));
    }
  }
  /** Stops the Poll Comm Servers identified by parameters. */
  public void stop(Map params) {
    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "Stopping Poll Comm Server [" + getType() + "] " + params);

    String id = (String) params.get(ATTR_COMM_SERVER_ID);

    CommServerConf commServerConf = commServerConfMap.get(id);

    if (commServerConf == null) {
      Debug.log(Debug.MSG_WARNING, "No configured poll comm server found with ID[" + id + "]");
      return;
    }

    ComServerBase commServer = commServerConf.getCommServer();

    if (commServer == null) {
      return;
    } else {
      commServer.shutdown();
      commServerConf.setCommServer(null);
      commServerConf.setStarted(false);
    }

    /* update configuration with the latest status. */
    updateXML(ELEM_POLL_COMM_SERVER, ATTR_COMM_SERVER_ID, id, ATTR_COMM_SERVER_START, "false");

    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "done stopping poll comm server [" + getType() + "] " + id);
  }
  /**
   * Starts all the configured Poll Comm Servers
   *
   * @throws ProcessingException
   */
  public void startAll() throws ProcessingException {
    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "Starting All Comm Server of type = " + getType());

    Iterator iter = commServerConfMap.keySet().iterator();
    while (iter.hasNext()) {
      String id = (String) iter.next();
      CommServerConf conf = commServerConfMap.get(id);
      if (conf.isStarted()) {
        Notification notification = null;
        Map params = Collections.singletonMap(ATTR_COMM_SERVER_ID, id);
        try {
          start(params);
          notification =
              new Notification("Started Comm Server of type = " + getType() + " id : " + id);
        } catch (Exception e) {
          Debug.log(
              Debug.MSG_ERROR,
              "Could not start Comm Server of type = " + getType() + " id : " + id);
          Debug.error(Debug.getStackTrace(e));
          notification =
              new Notification(
                  "Error starting Comm Server of type = " + getType() + " id : " + id, e);
        }
        notificationHandler.handle(notification);
      }
    }
    if (Debug.isLevelEnabled(Debug.NORMAL_STATUS))
      Debug.log(Debug.NORMAL_STATUS, "done starting Comm Servers of type = " + getType());
  }
Пример #7
0
  /**
   * POSTs the given content to the given URL.
   *
   * @param String the url to post to
   * @param content the body of the post
   * @param contentType the content-type of the request
   * @exception IOException if post fails
   */
  public static String post(String urlString, String contentType, String content)
      throws IOException {

    Debug.log(
        Debug.MSG_LIFECYCLE,
        "HTTPUtils: Trying to post " + content + " to web server at [ " + urlString + "]");

    StringBuffer responseBuffer = new StringBuffer();

    URL url = new URL(urlString);

    ClientSocket cs = new ClientSocket();

    HTTPUtils.Response resp = post(cs, url, new Hashtable(), contentType, content);

    while (true) {
      String line = resp.content.readLine();
      if (line == null) break;

      responseBuffer.append(line);
    }

    Debug.log(
        Debug.MSG_LIFECYCLE,
        "HTTPUtils: Obtained response from web server : " + responseBuffer.toString());

    cleanUp(cs);

    return responseBuffer.toString();
  }
Пример #8
0
  /**
   * Close all IO connections that were opened during post()
   *
   * @param cs Client socket items to populate.
   */
  private static void cleanUp(ClientSocket cs) throws IOException {

    Debug.log(Debug.MSG_LIFECYCLE, "HTTPUtils: closing IO socket connections");

    if (cs.in != null) {
      try {
        cs.in.close();

        cs.in = null;
      } catch (Exception e) {
        Debug.log(Debug.ALL_WARNINGS, e.toString());
      }
    }

    if (cs.out != null) {
      try {
        cs.out.close();

        cs.out = null;
      } catch (Exception e) {
        Debug.log(Debug.ALL_WARNINGS, e.toString());
      }
    }

    if (cs.s != null) {
      try {
        cs.s.close();

        cs.s = null;
      } catch (Exception e) {
        Debug.log(Debug.ALL_WARNINGS, e.toString());
      }
    }
  }
Пример #9
0
  /**
   * This method reads RTF template file.
   *
   * @return String - string of rtf template.
   * @exception - ProcessingException - thrown if FrameworkException is reported from FileUtil class
   */
  private String getRTFTemplate() throws ProcessingException {
    String template = "";
    Debug.log(this, Debug.BENCHMARK, "RTFGenerator: Reading template file.");
    try {
      template = FileUtils.readFile(rtfTemplate);
    } catch (FrameworkException exp) {
      Debug.log(this, Debug.ALL_ERRORS, "ERROR: RTFGenerator: Template file cannot be located.");
      throw new ProcessingException(rtfTemplate + " file cannot be located");
    }

    return template;
  }
Пример #10
0
  /**
   * This function returns the begin offset of the input string where the first matched pattern is
   * found.
   *
   * @param pattern pattern string to match
   * @param input input string
   * @return returns the offset of the beginning of the first matched pattern. if the match not
   *     found, it returns -1.
   * @exception throws a FrameworkException when either pattern/input is null.
   */
  public static int getBeginOffset(String pattern, String input) throws FrameworkException {
    if (input == null || pattern == null) {
      throw new FrameworkException(
          "RegexUtils: getBeginOffset(): input or pattern is null."
              + "input = "
              + input
              + ", "
              + "pattern = "
              + pattern);
    }

    Perl5Util util = new Perl5Util();
    int beginOffset = -1;
    String formatPattern = null;

    formatPattern = makePerl5MatchPattern(pattern);

    if (util.match(formatPattern, input)) {
      beginOffset = util.beginOffset(0);
    } else {
      Debug.log(Debug.MSG_STATUS, "RegexUtils: getBeginOffset(): No match found.");
    }

    return beginOffset;
  }
Пример #11
0
  public static HashMap<String, String> getNancValueMapping() {
    if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
      Debug.log(Debug.MSG_STATUS, className + " : Returning Hash map...");
    }

    return map;
  }
Пример #12
0
  /**
   * This function takes a perl5 regular expression as the pattern to perform pattern matching and
   * string substitution.
   *
   * <p>"s/pattern/replacement/[g][i][m][o][s][x]"
   *
   * <p>g - substitute globally (all occurence) i - case insensitive m - treat the input as
   * consisting of multiple lines o - interpolate once s - treat the input as consisting of a single
   * line x - enable extended expression syntax incorporating whitespace and comments
   *
   * <p>to perform string substitution. Unless the [g] option is specified, the dafault is to
   * replace only the first occurrence.
   *
   * @param perl5Pattern - Perl5 regular expression
   * @param input - input string
   * @return result - processed string. The original input is returned when there is no match
   * @exception - FrameworkException is thrown when either pattern or input is null
   */
  public static String substitute(String perl5Pattern, String input) throws FrameworkException {
    if ((perl5Pattern == null) || (input == null)) {
      throw new FrameworkException(
          "RegexUtil: replaceAll(): Either input or pattern is null."
              + "input = "
              + input
              + ", "
              + "pattern = "
              + perl5Pattern);
    }

    if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
      Debug.log(
          Debug.MSG_STATUS,
          "RegexUtils: replaceAll: perl5Pattern = " + perl5Pattern + " input = " + input);
    }

    Perl5Util util = new Perl5Util();
    String result = input;

    try {
      result = util.substitute(perl5Pattern, input);
    } catch (RuntimeException e) {
      throw new FrameworkException("RegexUtils: substitute: " + e.getMessage());
    }

    return result;
  }
Пример #13
0
  /**
   * This function composes the perl regular expression to perform pattern matching with negative
   * look ahead. This becomes handy when a replacement string includes some string that is also a
   * pattern.
   *
   * <p>i.e.) pattern - & replacement - &quot, &amp
   *
   * @param pattern - pattern string to match
   * @param replacements - an array of replacement strings
   * @return returns the format pattern for perl5 negative look-ahead
   * @exception throws a FrameworkException when the pattern/replacement is null.
   */
  private static String makePerl5MatchPatternNegativeLookAhead(
      String pattern, String replacements[]) throws FrameworkException {
    if (pattern == null || replacements.length < 0) {
      throw new FrameworkException(
          "RegexUtils: makePerl5MatchPatternNegativeLookAhead: pattern or replacement is null."
              + "\npattern = "
              + pattern
              + "\nreplacements.length = "
              + replacements.length);
    }

    String result = null;
    StringBuffer patternBuffer = new StringBuffer();

    Perl5Util util = new Perl5Util();
    String formatPattern = makePerl5MatchPattern(pattern);

    for (int i = 0; i < replacements.length; i++) {
      if (util.match(formatPattern, replacements[i])) {
        if (replacements[i].startsWith(pattern)) {
          result = util.postMatch();

          // very first one
          if (i == 0) {
            patternBuffer.append(pattern);
            patternBuffer.append("(?!");
          }
          patternBuffer.append(result);

          // the last one
          if (i == (replacements.length - 1)) {
            patternBuffer.append(")");
          } else // not the last one, cat the perl5 separater
          {
            patternBuffer.append("|");
          }

        } else {
          throw new FrameworkException(
              "ERROR: RegexUtils: makePerl5MatchPatternNegativeLookAhead: The pattern in the "
                  + "replacement string should be at the beginning.");
        }
      } else // no match found meaning invalid use of this function
      {
        throw new FrameworkException(
            "ERROR: RegexUtils: makePerl5MatchPatternNegativeLookAhead: "
                + "Invalid use of the function.");
      }
    }

    if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
      Debug.log(
          Debug.MSG_STATUS,
          "RegexUtils: makePerl5MatchPatternNegativeLookAhead: patternBuffer.toString() = "
              + patternBuffer.toString());
    }

    return patternBuffer.toString();
  }
Пример #14
0
  /**
   * Initializes the Splitter.
   *
   * @param key Property-key to use for locating initialization properties.
   * @param type Property-type to use for locating initialization properties.
   * @exception ProcessingException when initialization fails
   */
  public void initialize(String key, String type) throws ProcessingException {

    // Call the abstract super class's initialize method. This initializes
    // the adapterProperties hashtable defined in the super class and
    // retrieves the name and toProcessorNames values from the properties.
    super.initialize(key, type);

    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE))
      Debug.log(Debug.OBJECT_LIFECYCLE, "Splitter: Initializing.....");

    StringBuffer errorBuffer = new StringBuffer();
    truncHeaderFooter = getRequiredPropertyValue(TRUNCATE_HEADER_FOOTER_PROP, errorBuffer);

    if (Debug.isLevelEnabled(Debug.MSG_DATA))
      Debug.log(Debug.MSG_DATA, "Splitter: truncHeaderFooter? ---->" + truncHeaderFooter);

    String temp = getPropertyValue(FILE_SEPARATOR_PROP);
    if (StringUtils.hasValue(temp)) {
      fileSeparator = StringUtils.replaceSubstrings(temp, "\\r", "\r");
      fileSeparator = StringUtils.replaceSubstrings(fileSeparator, "\\n", "\n");
      if (Debug.isLevelEnabled(Debug.MSG_DATA))
        Debug.log(Debug.MSG_DATA, "Splitter: fileSeparator---->" + fileSeparator);
    }

    try {
      splitLength = Integer.parseInt(getRequiredPropertyValue(SPLIT_LENGTH_PROP, errorBuffer));

      if (Debug.isLevelEnabled(Debug.MSG_DATA))
        Debug.log(Debug.MSG_DATA, "Splitter: splitLength---->" + splitLength);
    } catch (NumberFormatException nx) {
      throw new ProcessingException("ERROR: Splitter: The SPLIT_LENGTH " + "must be a number.");
    }

    if (splitLength <= 0) {
      throw new ProcessingException(
          "ERROR: Splitter: The SPLIT_LENGTH " + "must be greater than zero.");
    }

    if (errorBuffer.length() > 0) {
      String errMsg = errorBuffer.toString();

      Debug.log(Debug.ALL_ERRORS, errMsg);

      throw new ProcessingException(errMsg);
    }
  }
Пример #15
0
  /** Constructor. */
  public DatabaseEventQueue() {
    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE))
      Debug.log(
          Debug.OBJECT_LIFECYCLE,
          "QUEUE OPERATION: Creating event queue of type ["
              + StringUtils.getClassName(this)
              + "] ...");

    queue = Collections.synchronizedList(new LinkedList());
  }
Пример #16
0
  /**
   * This method is called from driver. It does all processing to generate RTF document.
   *
   * @param context - MessageProcessorContext.
   * @param type - input - this contains XML message that needs to e converted to RTF document.
   * @return NVPair[] - this array contains only one instance of NVPair. name - value of
   *     NEXT_PROCESSOR_NAME; value - generated RTF document.
   * @exception - MessageException, ProcessingException - messageException is thrown if parsing of
   *     XML fails ProcessingException is thrown for any other significant error.
   */
  public NVPair[] execute(MessageProcessorContext context, Object input)
      throws MessageException, ProcessingException {

    Debug.log(this, Debug.BENCHMARK, "RTFGenerator: Starting conversion of XML to RTF document");
    if (input == null) {
      return null;
    }

    String xmlMessage = Converter.getString(input);

    TokenDataSource tds = new XMLTokenDataSourceAdapter(xmlMessage);

    String template = getRTFTemplate();
    com.nightfire.framework.util.TokenReplacer tr =
        new com.nightfire.framework.util.TokenReplacer(template);
    tr.setTokenStartIndicator(startDelimiter);
    tr.setTokenEndIndicator(endDelimiter);
    tr.setAllDataOptional(true);
    String result = "";
    try {
      result = tr.generate(tds);
    } catch (FrameworkException exp) {
      throw new ProcessingException(
          "ERROR: RTFGenerator: Error in translating XML to RTF document");
    }

    Debug.log(this, Debug.BENCHMARK, "RTFGenerator: Done conversion of XML to RTF document");
    // Generate NVPair to return

    NVPair nvpair = new NVPair(nextProcessor, result);
    NVPair array[] = new NVPair[] {nvpair};

    // for testing only
    if (testing) {
      try {
        FileUtils.writeFile("e:\\OP.rtf", result);
      } catch (Exception exp) {
        exp.printStackTrace();
      }
    }

    return array;
  }
Пример #17
0
  /*
   * This boolen method is used to check whether Hash map is cached or not.
   */
  public static boolean isNancMapCached() {
    if (map.size() > 0) {

      if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

        Debug.log(Debug.MSG_STATUS, className + " : Hash map for NANC mapping is in cache");
      }

      return true;

    } else {

      if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

        Debug.log(Debug.MSG_STATUS, className + " : Hash map for NANC mapping is NOT in cache");
      }

      return false;
    }
  }
Пример #18
0
  public void flushCache() throws FrameworkException {

    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE)) {

      Debug.log(Debug.OBJECT_LIFECYCLE, className + " : Flushing disabled-rules cache ...");
    }

    synchronized (map) {
      map.clear();
    }
  }
Пример #19
0
  /*
   * A single private instance of this class will be created to assist in cache flushing.
   */
  private NancValueMapping() {

    if (Debug.isLevelEnabled(Debug.SYSTEM_CONFIG))
      Debug.log(Debug.SYSTEM_CONFIG, className + " : Initializing...");

    try {
      CacheManager.getRegistrar().register(this);

    } catch (Exception e) {
      Debug.warning(e.toString());
    }
  }
Пример #20
0
  /**
   * Initialize the event queue.
   *
   * @param props A container of configuration properties.
   * @exception FrameworkException Thrown if configuration is invalid.
   */
  public void initialize(Map props) throws FrameworkException {
    String temp = (String) props.get(LOAD_EVENT_BATCH_SIZE_PROP);

    if (StringUtils.hasValue(temp)) {
      maxDatabaseEventLoadSize = StringUtils.getInteger(temp);

      if (Debug.isLevelEnabled(Debug.SYSTEM_CONFIG))
        Debug.log(
            Debug.SYSTEM_CONFIG,
            "QUEUE OPERATION: Initializing: Maximum-database-event-batch-load-size is ["
                + maxDatabaseEventLoadSize
                + "] rows.");
    }
  }
Пример #21
0
  public static void main(String[] args) {

    Debug.enable(Debug.UNIT_TEST);
    Debug.enable(Debug.BENCHMARK);
    Debug.showLevels();
    if (args.length != 3) {
      Debug.log(
          Debug.ALL_ERRORS,
          "UnBatcher: USAGE:  " + " jdbc:oracle:thin:@192.168.164.238:1521:e911 e911 e911 ");
      return;
    }
    try {

      DBInterface.initialize(args[0], args[1], args[2]);
    } catch (DatabaseException e) {
      Debug.log(
          Debug.MAPPING_ERROR,
          "UnBatcher: " + "Database initialization failure: " + e.getMessage());
    }

    Splitter spl = new Splitter();

    try {
      MessageProcessorContext mpx = new MessageProcessorContext();
      mpx.set("FileName", "MANS9999");

      String s = FileUtils.readFile("D:\\Response\\DECCCORR.txt");
      System.out.println("length----------->>>>>" + s.length());
      MessageObject msob = new MessageObject();
      msob.set(s);
      spl.initialize("E911BATCHER", "FAX_MESSAGE_SPLITTER");
      spl.process(mpx, msob);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
Пример #22
0
  /**
   * Get the next queued item. Must be called after hasNext().
   *
   * @return The next item in the queue to process.
   * @exception FrameworkException Thrown on errors.
   */
  public Event next() throws FrameworkException {
    if (queue.size() == 0) {
      throw new FrameworkException("ERROR: Attempt was made to retrieve event from empty queue.");
    }

    Event event = (Event) queue.get(0);

    if (Debug.isLevelEnabled(Debug.MSG_STATUS))
      Debug.log(
          Debug.MSG_STATUS,
          "QUEUE OPERATION: Retrieving the following event from the database queue:\n"
              + event.describe());

    return event;
  }
  @Override
  public NVPair[] process(MessageProcessorContext mpContext, MessageObject inputObject)
      throws MessageException, ProcessingException {
    if (inputObject == null) return null;
    /*
     * Load the value of configured properties
     */
    for (PPDataHolder holder : ppData) {
      String propertyValue = null;
      try {
        boolean useCustomerId = StringUtils.getBoolean(holder.getUseCustomerId());

        if (useCustomerId)
          propertyValue =
              PersistentProperty.get(
                  holder.getKey(), holder.getPropertyType(), holder.getPropertyName());
        else {
          String customerId = CustomerContext.getInstance().getCustomerID();
          CustomerContext.getInstance().setCustomerID(CustomerContext.DEFAULT_CUSTOMER_ID);
          propertyValue =
              PersistentProperty.get(
                  holder.getKey(), holder.getPropertyType(), holder.getPropertyName());
          CustomerContext.getInstance().setCustomerID(customerId);
        }

      } catch (Exception ex) {
        Debug.warning(
            "Unable to get configured property from persistent property :" + holder.toString());
      }

      /*
       * set the value into message processor context
       */
      if (StringUtils.hasValue(propertyValue)) {
        if (Debug.isLevelEnabled(Debug.DB_DATA))
          Debug.log(
              Debug.DB_DATA,
              " setting value :" + propertyValue + " on location :" + holder.getOutputLoc());

        mpContext.set(holder.getOutputLoc(), propertyValue);
      }
    }

    /* Always return input value to provide pass-through semantics. */
    return (formatNVPair(inputObject));
  }
Пример #24
0
  /**
   * Returns 'true' if the queue has more items to process.
   *
   * @param criteria An event containing the event-selection criteria.
   * @return 'true' if queue has more items to process, otherwise 'false'.
   * @exception FrameworkException Thrown on errors.
   */
  public boolean hasNext(Event criteria) throws FrameworkException {
    boolean available = (queue.size() > 0);

    // If no events are available in memory, attempt to get more from the database.
    if (!available) {
      loadFromDatabase(criteria);

      available = (queue.size() > 0);
    }

    if (Debug.isLevelEnabled(Debug.MSG_STATUS))
      Debug.log(
          Debug.MSG_STATUS,
          "QUEUE OPERATION: Events available in database queue? [" + available + "].");

    return available;
  }
Пример #25
0
  /**
   * This function substitues ALL occurence of the pattern in the input passed in. This function can
   * take a single input, a perl5 match pattern, an array of replacement strings, begin token, and
   * end token.
   *
   * @param perl5Regex perl5 regular expression for pattern match i.e.) &(?!amp) - this regular
   *     expression matches every occurence of '&' which is not followed by "amp". For example, it
   *     will match '&' or "&anystring" but "&amp".
   * @param input input string
   * @param replacement array of replacement strings
   * @param beginToken begin boundary token
   * @param endToken end boundary token
   * @return result returns processed string
   * @exception throws FrameworkException when either pattern/input/replacement is null.
   */
  public static String replaceAll(
      String perl5Regex, String input, String replacement[], String beginToken, String endToken)
      throws FrameworkException {
    if (input == null) {
      throw new FrameworkException("RegexUtil: replaceAll(): input is null.");
    }

    if ((perl5Regex == null) && (replacement.length <= 0)) {
      Debug.log(Debug.ALL_ERRORS, "RegexUtils.replaceAll()): No patterns and tokens specified.");
      throw new FrameworkException("RegexUtils: replaceAll(): No patterns and tokens specified.");
    }

    for (int i = 0; i < replacement.length; i++) {
      input = replaceAll(perl5Regex, input, replacement[i], beginToken, endToken);
    }

    return input;
  }
Пример #26
0
  /**
   * This function checks in the input if there is other tokens in the begingTokens array than
   * begin. This utility function is used on a string which is between a valid begin token and all
   * possible other begin tokens. If there is another begin token of different kind is found, the
   * substitution shouldn't occur. Consider this situation:
   *
   * <p>i.e.) <beginToken_0> "some string <beginToken_1> here to do the substitution on"
   * <endToken_0> <beginToken_0> "another some string" <endToken_1>
   *
   * <p>In this case, the replaceAll() function finds the matched pair <beginToken_0> and
   * <endToken_0> and attempt to perform the substitution. However, since there is another boundary
   * _1 is overlapped with _0 boundary, we do not want to perform a string substitution.
   *
   * @param replacement replacement string to replace with
   * @param beginToken begin boundary token
   * @param endToken end boundary token
   * @return true if any of other beginTokens in the beginToken[] than begin is found in the input
   *     string, false otherwise
   */
  private static final boolean isOtherBeginTokenThere(
      String begin, String input, String beginTokens[]) throws FrameworkException {
    Perl5Util util = new Perl5Util();

    for (int i = 0; i < beginTokens.length; i++) {
      // look for the other token
      if (!beginTokens[i].equals(begin)) {
        String perl5Pattern = makePerl5MatchPattern(beginTokens[i]);
        // if the input contains at least one beginToken which differs from the begin
        if (util.match(perl5Pattern, input)) {
          Debug.log(
              Debug.MSG_STATUS, "RegexUtils: isOtherBeginTokenThere: token = " + perl5Pattern);
          return true;
        }
      }
    }

    return false;
  }
Пример #27
0
  /**
   * This function substitues ALL occurence of the pattern in the input with the replacement passed
   * in. This function can handle such situation as when some characters in the replacement is also
   * used in the pattern.
   *
   * <p>i.e.) pattern - & or &/[option] replacement - &amp or &amp/[option]
   *
   * @param pattern pattern string to match
   * @param input input string
   * @param replacement replacement string to be replaced with
   * @return returns processed string. Default return value is the original input string.
   * @exception throws FrameworkException when either pattern/input/replacement is null.
   */
  public static String replaceAll(String pattern, String input, String replacement)
      throws FrameworkException {
    if ((pattern == null) || (replacement == null) || (input == null)) {
      Debug.log(
          Debug.ALL_ERRORS,
          "RegexUtils.replaceAll(): pattern or replacement or input" + "is null.");

      throw new FrameworkException(
          "ERROR: RegexUtils: replaceAll(): pattern or replacement or input is null.");
    }

    Perl5Util util = new Perl5Util();

    String negativeLookAheadPattern = makePerl5MatchPatternNegativeLookAhead(pattern, replacement);
    String substitutionPattern =
        makePerl5SubstitutionPattern(negativeLookAheadPattern, replacement);

    String result = util.substitute(substitutionPattern, input);

    return result;
  }
  @Override
  public void initialize(String key, String type) throws ProcessingException {

    super.initialize(key, type);

    for (int Ix = 0; true; Ix++) {
      String propKey = getPropertyValue(PersistentProperty.getPropNameIteration(KEY_PROP, Ix));

      if (!StringUtils.hasValue(propKey)) break;

      PPDataHolder holder =
          new PPDataHolder(
              propKey,
              getPropertyValue(PersistentProperty.getPropNameIteration(PROPERTY_TYPE_PROP, Ix)),
              getPropertyValue(PersistentProperty.getPropNameIteration(PROPERTY_NAME_PROP, Ix)),
              getPropertyValue(PersistentProperty.getPropNameIteration(OUTPUT_LOCATION_PROP, Ix)),
              getPropertyValue(PersistentProperty.getPropNameIteration(USE_CUSTOMER_ID_PROP, Ix)));

      ppData.add(holder);

      if (Debug.isLevelEnabled(Debug.SYSTEM_CONFIG))
        Debug.log(Debug.SYSTEM_CONFIG, " Found configured property :" + holder);
    }
  }
Пример #29
0
  /*
   * This method will load the Hash map by reading the
   * contents from the configuration property file
   */
  public static HashMap<String, String> loadAndGetMappingToHashMap(File path) {

    synchronized (map) {
      String line = null;
      BufferedReader input = null;

      try {
        input = new BufferedReader(new FileReader(path));

        if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

          Debug.log(
              Debug.MSG_STATUS,
              className
                  + " : Starts loading Hash map from configuration property "
                  + "file - ["
                  + path.getAbsolutePath()
                  + "]");
        }

        while ((line = input.readLine()) != null) {

          if (line.startsWith("#") || line.equals("")) {

            continue;

          } else {
            /*
             * Check for '=' operand is present in mapping string.
             * If '=' is present then,
             * Check for mapping value, and it must be present.
             *
             * Throws exception if mapping file is wrong.
             */
            if (line.contains("=")) {

              if (line.charAt(line.length() - 1) != '=') {
                String[] lineArray = line.split("=");

                if (!((lineArray[0].equals("") || lineArray[0] == null)
                    && (lineArray[1].equals("") || lineArray[1] == null))) {
                  map.put(lineArray[0].trim(), lineArray[1].trim());
                }
              } else {
                if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

                  Debug.log(
                      Debug.MSG_STATUS,
                      className
                          + " : Mapping string "
                          + line.toString()
                          + " does not contain any mapping value after '=' operand");
                }
              }
            } else {
              if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

                Debug.log(
                    Debug.MSG_STATUS,
                    className
                        + " : Mapping string "
                        + line.toString()
                        + " does not contain '=' operand, Invalid Mapping line in mapping configuration file.");
              }
            }
          }
        }
        Debug.log(Debug.MSG_STATUS, className + " : Hash map loading is done...");

      } catch (FileNotFoundException fnf) {

        if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

          Debug.log(
              Debug.MSG_STATUS,
              className
                  + " : Could not find the file on given path ["
                  + path.getAbsolutePath()
                  + "]");
          Debug.log(Debug.MSG_STATUS, className + " : Hash map is NOT loaded...");
          Debug.log(Debug.MSG_STATUS, className + " : " + fnf.getMessage());
        }

      } catch (IOException ioe) {
        if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {

          Debug.log(
              Debug.MSG_STATUS,
              className + " : Could not read the property file contents to load the Hash map");
          Debug.log(Debug.MSG_STATUS, className + " : Hash map is NOT loaded...");
          Debug.log(Debug.MSG_STATUS, className + " : " + ioe.getMessage());
        }

      } finally {
        if (input != null) {
          try {
            input.close();
          } catch (IOException e) {

            if (Debug.isLevelEnabled(Debug.ALL_ERRORS)) {
              Debug.log(
                  Debug.ALL_ERRORS,
                  className
                      + " : Exception occures at the time to close the "
                      + "stream..."
                      + e.getMessage());
            }
          }
        }
      }
    }

    return map;
  }
Пример #30
0
  /** Constructor */
  public AsyncTimerServer(String key, String type) throws ProcessingException {
    super(key, type);

    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE))
      Debug.log(Debug.OBJECT_LIFECYCLE, "Done initializing AsyncTimerServer .");
  }