Ad
Camel Sftp Producer. How To Put Multiple Files To Different Sftp Folders From Single Processor
I use DSL configuration and spring.
My route looks like this:
@Component
public class UploadRoutesDefinition extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.process(new Processor() {
@Override
public void process(Exchange exchange) {
...
String sftPathForAdditionalFile = ....
String AdditionalFileContent = ...
...
}
).to(String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath(),
systemSettingsService.getSystemSettings().getSftpPassword()))
It allows me to read file from seda:rest_upload
and then move it to the sftp folder.
I want to move one more file additionally. I know path and content inside process
method.
How can I achieve it?
UPDATE
my current code;
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelFilename", "ololo.txt");
exchange.getIn().setBody(exchange.getProperty(PUSH_ERROR_MESSAGE, String.class).getBytes());
exchange.getIn().setHeader("destFilePath", sftpErrorFileTextPath);
}
})
.to(String.format(SFTP_BASE_URL + "&fileExist=Append",
systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword()))
.end();
Ad
Answer
Here is one way to do it,
@Override
public void configure() throws Exception {
from("seda:rest_upload")
.multicast()
.to("direct::sendMainFile")
.to("direct:sendAnotherFile") // You could also use seda:
.end();
from("direct:sendMainFile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
String filepath = <calculate filepath>;
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
exchange.getIn().setHeader("CamelFileName", fileNameforMainFile);
}
}.toD(sftpRoute()) // It is toD not to
from("direct:sendAnotherfile")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// Here you have the same body which was sent from rest_upload
// extract the info from exchange.getIn().getBody()
// Read the file and set it as exchange body
String fileContent = <Your logic to read file>
exchange.getIn().setBody(fileContent);
exchange.getIn().setHeader("CamelFileName", fileNameforYourAdditionalFile)
String completeFilePath = systemSettingsService.getSystemSettings().getSftpAttachmentsPushFailedPath() + filepath
exchange.getIn().setHeader("destFilePath", completeFilePath);
}
})
.toD(sftpRoute()); // It is toD not to
}
private String sftpRoute() {
return String.format(SFTP_BASE_URL,systemSettingsService.getSystemSettings().getSftpUserName(),
systemSettingsService.getSystemSettings().getSftpHost(),
systemSettingsService.getSystemSettings().getSftpPort(),
"${header.destFilePath}",
systemSettingsService.getSystemSettings().getSftpPassword())
}
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad