use of com.adaptris.core.FileNameCreator in project interlok by adaptris.
the class FtpProducer method doProduce.
@Override
public void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
FileTransferConnection conn = retrieveConnection(FileTransferConnection.class);
FileTransferClient client = null;
FileNameCreator creator = filenameCreatorToUse();
try {
client = conn.connect(endpoint);
String dirRoot = conn.getDirectoryRoot(endpoint);
String fileName = creator.createName(msg);
String destFilename = dirRoot + destDirectory + SLASH + fileName;
String buildFilename = dirRoot + buildDirectory + SLASH + fileName;
if (conn.additionalDebug()) {
log.trace("buildFilename=[{}], destFilename=[{}]", buildFilename, destFilename);
} else {
log.debug("destFilename=[{}]", destFilename);
}
msg.addMetadata(CoreConstants.PRODUCED_NAME_KEY, fileName);
if (getEncoder() != null) {
byte[] bytesToWrite = encode(msg);
client.put(bytesToWrite, buildFilename);
} else {
try (InputStream in = msg.getInputStream()) {
client.put(in, buildFilename);
}
}
client.rename(buildFilename, destFilename);
} catch (Exception e) {
throw new ProduceException(e);
} finally {
conn.disconnect(client);
}
}
use of com.adaptris.core.FileNameCreator 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);
}
}
Aggregations