use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.
the class MultiPayloadXmlTransformServiceTest method testObtainUrlWithEmptyMetadataValueInMessage.
@Test
public void testObtainUrlWithEmptyMetadataValueInMessage() throws Exception {
MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService();
MultiPayloadAdaptrisMessage msg = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
msg.addMetadata("key", "");
try {
service.setUrl(URL);
service.setMetadataKey("key");
LifecycleHelper.init(service);
assertEquals(URL, service.obtainUrlToUse(msg));
} finally {
LifecycleHelper.close(service);
}
}
use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.
the class ForEach method doService.
/**
* {@inheritDoc}.
*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
ThreadPoolExecutor executor = null;
try {
log.info("Starting for-each");
if (!(msg instanceof MultiPayloadAdaptrisMessage)) {
log.warn("Message [{}] is not a multi-payload message!", msg.getUniqueId());
iterate(msg);
} else {
MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) msg;
int threads = threadCount;
if (threads == 0) {
// use as many threads as necessary
threads = message.getPayloadCount();
}
log.trace("Using {} thread{}", threads, threads > 1 ? "s" : "");
executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threads);
for (String id : message.getPayloadIDs()) {
try {
message.switchPayload(id);
AdaptrisMessage each = DefaultMessageFactory.getDefaultInstance().newMessage(message, null);
each.setPayload(message.getPayload());
executor.execute(() -> iterate(each));
} catch (CloneNotSupportedException e) {
log.error("Could not clone message [{}]", id, e);
}
}
}
} finally {
if (executor != null) {
executor.shutdown();
try {
while (!executor.awaitTermination(1, TimeUnit.MILLISECONDS)) {
/* wait for all threads to complete */
}
} catch (InterruptedException e) {
log.warn("Interrupted while waiting for tasks to finish!", e);
}
}
log.info("Finished for-each");
}
}
use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.
the class MultiPayloadStreamInputParameterTest method testExtract.
@Test
public void testExtract() throws Exception {
MultiPayloadStreamInputParameter parameter = new MultiPayloadStreamInputParameter();
parameter.setPayloadId(ID);
MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage(ID, PAYLOAD);
try (InputStream stream = parameter.extract(message)) {
for (byte b : PAYLOAD) {
assertEquals(b, stream.read());
}
}
try (InputStream stream = parameter.extract(ID, message)) {
for (byte b : PAYLOAD) {
assertEquals(b, stream.read());
}
}
try (InputStream stream = parameter.extract(null, message)) {
for (byte b : PAYLOAD) {
assertEquals(b, stream.read());
}
}
}
use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.
the class MultiPayloadStreamOutputParameterTest method testInsertNullStream.
@Test
public void testInsertNullStream() throws Exception {
MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory();
MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) messageFactory.newMessage();
try {
InputStreamWithEncoding stream = new InputStreamWithEncoding(null, ENCODING);
MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
parameter.insert(stream, ID, message);
} catch (Exception e) {
// expected
}
}
use of com.adaptris.core.MultiPayloadAdaptrisMessage in project interlok by adaptris.
the class MultiPayloadStreamOutputParameterTest method testInsert.
@Test
public void testInsert() throws Exception {
MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) {
InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING);
MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
parameter.insert(stream, ID, message);
}
assertEquals(PAYLOAD, message.getContent(ID));
}
Aggregations