コード例 #1
0
  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));
        }
      }
    }
  }
コード例 #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());
   }
 }
コード例 #3
0
 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));
   }
 }
コード例 #4
0
  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));
    }
  }
コード例 #5
0
  @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);
    }
  }
コード例 #6
0
 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 + "]");
     }
   }
 }
コード例 #7
0
 /**
  * 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 + "]");
     }
   }
 }
コード例 #8
0
 /**
  * @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);
       }
     }
   }
 }
コード例 #9
0
 public void testDoServiceWithLineCountSplitter() throws Exception {
   msg.addMetadata("key", "value");
   execute(service, msg);
   assertEquals("Number of messages", 10, producer.getMessages().size());
 }
コード例 #10
0
 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());
 }
コード例 #11
0
 private void increment(AdaptrisMessage msg, MetadataStatistic stat) {
   String value = msg.getMetadataValue(getMetadataKey());
   if (!isEmpty(value)) {
     stat.increment(value);
   }
 }
コード例 #12
0
  /**
   * 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);
  }
コード例 #13
0
 public void doService(AdaptrisMessage msg) throws ServiceException {
   msg.addMetadata(
       getComparator().compare(msg.getMetadata(getFirstKey()), msg.getMetadata(getSecondKey())));
 }