public void testSplitMessageWithHeader2() throws Exception {
    LineCountSplitter s = new LineCountSplitter();
    s.setKeepHeaderLines(2);
    s.setSplitOnLine(10);
    s.setIgnoreBlankLines(true);

    final String HEADER_LINE_1 = "HEADER LINE 1";
    final String HEADER_LINE_2 = "HEADER LINE 2";
    List<AdaptrisMessage> result =
        toList(
            s.splitMessage(
                createLineCountMessageInputWithHeader(
                    new String[] {HEADER_LINE_1, HEADER_LINE_2})));

    assertEquals("5 split messages", 5, result.size());

    for (AdaptrisMessage m : result) {
      try (Reader reader = m.getReader()) {
        List<String> lines = IOUtils.readLines(reader);
        assertEquals("12 lines per message", 12, lines.size());
        assertEquals("Must be header line 1", HEADER_LINE_1, lines.get(0));
        assertEquals("Must be header line 2", HEADER_LINE_2, lines.get(1));
        for (int i = 2; i < 12; i++) {
          assertEquals("Must be regular line", LINE, lines.get(i));
        }
      }
    }
  }
Exemplo n.º 2
0
 protected void assertMessages(List<AdaptrisMessage> list, int count) {
   assertEquals("All files consumed/produced", count, list.size());
   for (AdaptrisMessage m : list) {
     assertTrue(m.containsKey(CoreConstants.ORIGINAL_NAME_KEY));
     assertEquals(PAYLOAD, m.getStringPayload().trim());
   }
 }
 public void testSplitMessage() throws Exception {
   String obj = "ABCDEFG";
   msg.addObjectHeader(obj, obj);
   LineCountSplitter s = new LineCountSplitter();
   List<AdaptrisMessage> result = toList(s.splitMessage(msg));
   assertEquals("10 split messages", 10, result.size());
   for (AdaptrisMessage m : result) {
     assertFalse("Should not contain object metadata", m.getObjectHeaders().containsKey(obj));
   }
 }
  public void testSplitMessageWithHeader1() throws Exception {
    LineCountSplitter s = new LineCountSplitter();
    s.setKeepHeaderLines(1);
    s.setSplitOnLine(1);
    s.setIgnoreBlankLines(true);

    final String HEADER_TEXT = "HEADER LINE 1";
    List<AdaptrisMessage> result =
        toList(s.splitMessage(createLineCountMessageInputWithHeader(new String[] {HEADER_TEXT})));

    assertEquals("50 split messages", 50, result.size());

    for (AdaptrisMessage m : result) {
      List<String> lines = IOUtils.readLines(m.getReader());
      assertEquals("2 lines per message", 2, lines.size());
      assertEquals("Must be header line", HEADER_TEXT, lines.get(0));
      assertEquals("Must be regular line", LINE, lines.get(1));
    }
  }
  @Override
  public void handleHeaders(
      AdaptrisMessage message, HttpServletRequest request, String itemPrefix) {
    String prefix = defaultIfEmpty(itemPrefix, "");

    for (Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements(); ) {
      String key = (String) e.nextElement();
      String value = request.getHeader(key);
      String metadataKey = prefix + key;
      log.trace("Adding Object Metadata [{}: {}]", metadataKey, value);
      message.addObjectMetadata(metadataKey, value);
    }
  }
 public void processCorrelationId(Message src, AdaptrisMessage dest) throws JMSException {
   if (isEmpty(getMetadataKey())) {
     log.warn("Metadata key for correlation ID not configured");
   } else {
     String id = src.getJMSCorrelationID();
     if (isEmpty(id)) {
       log.warn("No Correlation Id available");
     } else {
       dest.addMetadata(getMetadataKey(), id);
       log.debug("Set metadata key [" + getMetadataKey() + "] to [" + id + "]");
     }
   }
 }
 /**
  * If no metadata key is configured or if no value is stored against the configured key a message
  * is logged to this effect and no Exception is thrown.
  *
  * @see com.adaptris.core.jms.CorrelationIdSource#processCorrelationId
  *     (com.adaptris.core.AdaptrisMessage, javax.jms.Message)
  */
 public void processCorrelationId(AdaptrisMessage src, Message dest) throws JMSException {
   if (isEmpty(getMetadataKey())) {
     log.warn("metadata key for correlation ID not configured");
   } else {
     String correlationId = src.getMetadataValue(getMetadataKey());
     if (isEmpty(correlationId)) {
       log.warn("no value for metadata key [" + getMetadataKey() + "]");
     } else {
       dest.setJMSCorrelationID(correlationId);
       log.debug("set correlation ID to [" + correlationId + "]");
     }
   }
 }
 /**
  * @see
  *     com.adaptris.core.services.splitter.MessageSplitterServiceImp#handleSplitMessage(com.adaptris.core.AdaptrisMessage)
  */
 @Override
 public void handleSplitMessage(AdaptrisMessage msg) throws ServiceException {
   try {
     service.doService(msg);
   } finally {
     if (eventHandler != null && sendEvents()) {
       try {
         eventHandler.send(msg.getMessageLifecycleEvent());
       } catch (CoreException e) {
         throw new ServiceException(e);
       }
     }
   }
 }
 public void testDoServiceWithLineCountSplitter() throws Exception {
   msg.addMetadata("key", "value");
   execute(service, msg);
   assertEquals("Number of messages", 10, producer.getMessages().size());
 }
 public void testDefaultSplit_WithCharEncoding() throws Exception {
   LineCountSplitter s = new LineCountSplitter();
   msg.setContentEncoding(System.getProperty("file.encoding"));
   List<AdaptrisMessage> msgs = toList(s.splitMessage(msg));
   assertEquals("10 split messages", 10, msgs.size());
 }
Exemplo n.º 11
0
 private void increment(AdaptrisMessage msg, MetadataStatistic stat) {
   String value = msg.getMetadataValue(getMetadataKey());
   if (!isEmpty(value)) {
     stat.increment(value);
   }
 }
  /**
   * Sets 'break-out' metadata for testing.
   *
   * @param msg the message to apply service to
   * @throws ServiceException wrapping any underlying <code>Exception</code>s
   */
  public void doService(AdaptrisMessage msg) throws ServiceException {

    msg.addMetadata(CoreConstants.STOP_PROCESSING_KEY, CoreConstants.STOP_PROCESSING_VALUE);
  }
 public void doService(AdaptrisMessage msg) throws ServiceException {
   msg.addMetadata(
       getComparator().compare(msg.getMetadata(getFirstKey()), msg.getMetadata(getSecondKey())));
 }