Search in sources :

Example 6 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class DecodingServiceTest method testSetMessageFactory.

@Test
public void testSetMessageFactory() throws Exception {
    DecodingService s = new DecodingService();
    assertNull(s.getMessageFactory());
    s = new DecodingService(new MockEncoder());
    assertNull(s.getMessageFactory());
    assertTrue(s.getEncoder().currentMessageFactory() instanceof DefaultMessageFactory);
    s = new DecodingService(new MockEncoder());
    AdaptrisMessageFactory amf = new StubMessageFactory();
    s.setMessageFactory(amf);
    try {
        LifecycleHelper.init(s);
        assertEquals(amf, s.getMessageFactory());
        assertTrue(s.getEncoder().currentMessageFactory() instanceof StubMessageFactory);
        assertEquals(amf, s.getEncoder().currentMessageFactory());
    } finally {
        LifecycleHelper.close(s);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) MockEncoder(com.adaptris.core.stubs.MockEncoder) StubMessageFactory(com.adaptris.core.stubs.StubMessageFactory) Test(org.junit.Test)

Example 7 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class EncodingServiceTest method testSetMessageFactory.

@Test
public void testSetMessageFactory() throws Exception {
    EncodingService s = new EncodingService();
    assertNull(s.getMessageFactory());
    s = new EncodingService(new MockEncoder());
    assertNull(s.getMessageFactory());
    assertTrue(s.getEncoder().currentMessageFactory() instanceof DefaultMessageFactory);
    s = new EncodingService(new MockEncoder());
    AdaptrisMessageFactory amf = new StubMessageFactory();
    s.setMessageFactory(amf);
    try {
        LifecycleHelper.init(s);
        assertEquals(amf, s.getMessageFactory());
        assertTrue(s.getEncoder().currentMessageFactory() instanceof StubMessageFactory);
        assertEquals(amf, s.getEncoder().currentMessageFactory());
    } finally {
        LifecycleHelper.close(s);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) MockEncoder(com.adaptris.core.stubs.MockEncoder) StubMessageFactory(com.adaptris.core.stubs.StubMessageFactory) Test(org.junit.Test)

Example 8 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class SplittingXmlPayloadTranslator method newMessage.

private AdaptrisMessage newMessage(AdaptrisMessage original) {
    AdaptrisMessageFactory factory = ObjectUtils.defaultIfNull(getMessageFactory(), original.getFactory());
    AdaptrisMessage result = factory.newMessage();
    if (copyMetadata()) {
        result.setMetadata(original.getMetadata());
    }
    result.addMetadata(CoreConstants.PARENT_UNIQUE_ID_KEY, original.getUniqueId());
    return result;
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage)

Example 9 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class MimePartSplitter method splitMessage.

/**
 * @see MessageSplitter#splitMessage(AdaptrisMessage)
 */
@Override
public List<AdaptrisMessage> splitMessage(AdaptrisMessage msg) throws CoreException {
    List<AdaptrisMessage> result = new ArrayList<AdaptrisMessage>();
    AdaptrisMessageFactory fac = selectFactory(msg);
    try (BodyPartIterator mp = MimeHelper.createBodyPartIterator(msg)) {
        while (mp.hasNext()) {
            AdaptrisMessage splitMsg = fac.newMessage();
            MimeBodyPart part = mp.next();
            copy(part, splitMsg);
            copyMetadata(msg, splitMsg);
            result.add(splitMsg);
        }
    } catch (Exception e) {
        throw new CoreException(e);
    }
    logR.trace("Split gave " + result.size() + " messages");
    return result;
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException)

Example 10 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class StringPayloadSplitter method splitMessage.

/**
 * @see MessageSplitter#splitMessage(AdaptrisMessage)
 */
@Override
public List<AdaptrisMessage> splitMessage(AdaptrisMessage msg) throws CoreException {
    List<AdaptrisMessage> result = new ArrayList<AdaptrisMessage>();
    try {
        AdaptrisMessageFactory factory = selectFactory(msg);
        List<String> payloads = split(msg.getContent());
        for (String payload : payloads) {
            AdaptrisMessage splitMsg = factory.newMessage(payload, msg.getContentEncoding());
            copyMetadata(msg, splitMsg);
            result.add(splitMsg);
        }
        logR.trace("Split gave " + result.size() + " messages");
    } catch (Exception e) {
        throw new CoreException(e);
    }
    return result;
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) CoreException(com.adaptris.core.CoreException)

Aggregations

AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)14 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 Test (org.junit.Test)10 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 CoreException (com.adaptris.core.CoreException)2 EvenOddCondition (com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition)2 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)2 MockEncoder (com.adaptris.core.stubs.MockEncoder)2 StubMessageFactory (com.adaptris.core.stubs.StubMessageFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 ZipInputStream (java.util.zip.ZipInputStream)2 XmlUtils (com.adaptris.util.XmlUtils)1 BodyPartIterator (com.adaptris.util.text.mime.BodyPartIterator)1 InsertNode (com.adaptris.util.text.xml.InsertNode)1 XPath (com.adaptris.util.text.xml.XPath)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 Notification (javax.management.Notification)1