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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations