use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class FsMessageProducerTest method testProduceFileAlreadyExists_NioWorker.
@Test
public void testProduceFileAlreadyExists_NioWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new NioWorker());
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
start(fs);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
dir.mkdirs();
File targetFile = new File(dir, msg.getMetadataValue("targetFilename"));
targetFile.createNewFile();
fs.produce(msg);
fail();
} catch (ProduceException expected) {
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class FsProducer method doProduce.
@Override
@SuppressWarnings({ "lgtm[java/path-injection]" })
protected void doProduce(AdaptrisMessage msg, String baseUrl) throws ProduceException {
FileNameCreator creator = filenameCreatorToUse();
try {
URL url = FsHelper.createUrlFromString(baseUrl, true);
validateDir(url);
File filetoWrite = new File(FsHelper.createFileReference(url), creator.createName(msg));
addProducerMetadata(msg, filetoWrite);
write(msg, filetoWrite);
log.debug("msg produced to destination [{}]", url);
} catch (Exception e) {
throw new ProduceException(e);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class RelaxedFtpProducer method doProduce.
/**
* @see com.adaptris.core.AdaptrisMessageProducerImp#produce(AdaptrisMessage)
*/
@Override
public void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
FileTransferConnection conn = retrieveConnection(FileTransferConnection.class);
FileTransferClient client = null;
try {
client = conn.connect(endpoint);
String dirRoot = conn.getDirectoryRoot(endpoint);
String fileName = filenameCreator().createName(msg);
String destFilename = dirRoot + SLASH + fileName;
if (dirRoot.endsWith(SLASH)) {
destFilename = dirRoot + fileName;
}
log.debug("destFilename=[{}]", destFilename);
msg.addMetadata(CoreConstants.PRODUCED_NAME_KEY, fileName);
if (getEncoder() != null) {
byte[] bytesToWrite = encode(msg);
client.put(bytesToWrite, destFilename);
} else {
try (InputStream in = msg.getInputStream()) {
client.put(in, destFilename);
}
}
} catch (Exception e) {
throw new ProduceException(e);
} finally {
conn.disconnect(client);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testRuntimeException.
@Test
public void testRuntimeException() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, true, "testRuntimeException", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setProducer(new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new RuntimeException();
}
});
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
} finally {
channel.requestClose();
}
assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testProduceException.
@Test
public void testProduceException() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, true, "testProduceException", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setProducer(new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
});
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
} finally {
channel.requestClose();
}
assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
Aggregations