예제 #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);
    }
  }
예제 #2
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());
      }
    }
  }
예제 #3
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();
  }
  /**
   * 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));
    }
  }
예제 #5
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;
  }
예제 #6
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");
    }
  }
  /** 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);
  }
예제 #8
0
  public static HashMap<String, String> getNancValueMapping() {
    if (Debug.isLevelEnabled(Debug.MSG_STATUS)) {
      Debug.log(Debug.MSG_STATUS, className + " : Returning Hash map...");
    }

    return map;
  }
예제 #9
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();
  }
예제 #10
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());
  }
예제 #11
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();
    }
  }
예제 #12
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;
  }
예제 #13
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());
    }
  }
예제 #14
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.");
    }
  }
예제 #15
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;
  }
  /**
   * @param serverType
   * @param classNm
   * @param fileFilterXpath
   * @throws FrameworkException
   */
  public static void addServerMapping(String serverType, String classNm, String fileFilterXpath)
      throws FrameworkException {

    try {
      Class.forName(classNm);
    } catch (Exception exp) {
      Debug.warning("Unable to load class :" + classNm);
      Debug.logStackTrace(exp);

      throw new FrameworkException("Unable to load class :" + classNm);
    }

    serverType2ClassNm.put(serverType, classNm);

    serverType2Xpath.put(serverType, fileFilterXpath);
  }
예제 #17
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;
  }
  @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));
  }
예제 #19
0
  // Release the given database resources, if non-null.
  private static void releaseDatabaseResources(Connection dbConn, PreparedStatement ps) {
    if (ps != null) {
      try {
        ps.close();
      } catch (Exception e) {
        Debug.warning("Failed to close the prepared statement:\n" + e.toString());
      }
    }

    if (dbConn != null) {
      try {
        DBConnectionPool.getInstance().releaseConnection(dbConn);
      } catch (Exception e) {
        Debug.warning("Failed to release database connection back to the pool:\n" + e.toString());
      }
    }
  }
예제 #20
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;
  }
  /**
   * 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());
  }
예제 #22
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;
  }
예제 #23
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;
    }
  }
예제 #24
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);
    }
  }
  /**
   * 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 .. ");
  }
  public java.lang.String processSync(java.lang.String header, java.lang.String request)
      throws java.rmi.RemoteException {
    try {
      WSRequestHandler rh = new WSRequestHandler();
      rh.setInstanceId((String) (ServiceInitializer.getInitParameters().get(GWS_SERVER_NAME)));

      return (rh.processSync(header, request));
    } catch (Throwable t) {
      Debug.error(t.toString());

      throw new RemoteException("WSRequest-handler processSync() call failed", t);
    }
  }
예제 #27
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());
    }
  }
  @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
  public static void main(String args[]) {
    Debug.enableAll();

    String input;
    String pattern;
    String result = null;
    String replacement;

    Perl5Util util = new Perl5Util();

    System.out.println("\nThis example performs ampersand replacement: & -> &amp");
    input =
        "<ILEC value=\"I have &0.>and &2<ILEC value=\"I have &1.\"/><ILEC value=\"I have &3.\"/>";

    String beginToken = "value=\"";
    String endToken = "\"/>";
    pattern = "&";
    replacement = "&amp";
    System.out.println("input = " + input);
    System.out.println("pattern = " + pattern);
    System.out.println("replacement = " + replacement);
    System.out.println("beginToken = " + beginToken);
    System.out.println("endToken = " + endToken);
    try {
      result = replaceAll(pattern, input, replacement, beginToken, endToken);
    } catch (FrameworkException e) {
    }
    System.out.println("main: result = " + result);

    System.out.println("\nThis example performs the bound replacement.");
    String patterns[] = {"\"", "'", "<", ">", "&"};
    String replacements[] = {"&quot", "&apos", "&lt", "&gt", "&amp"};
    beginToken = "name=\"";
    endToken = "/test_2>";
    input =
        "<Test0 value=\"I am \"string\" and I got <'>.\"/><Test1 value=\"I am another with &.\"/>";

    System.out.println("input = " + input);
    System.out.println("beginToken = " + beginToken);
    System.out.println("endToken = " + endToken);
    try {
      result = replaceAll(patterns, input, replacements, beginToken, endToken);
    } catch (FrameworkException e) {
    }
    System.out.println("\n\n\ndriver main: final result = " + result);

    return;
  } // main
예제 #30
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;
  }