use of org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult in project camel by apache.
the class DropboxScheduledPollGetConsumer method poll.
/**
* Poll from a dropbox remote path and put the result in the message exchange
* @return number of messages polled
* @throws Exception
*/
@Override
protected int poll() throws Exception {
Exchange exchange = endpoint.createExchange();
DropboxFileDownloadResult result = new DropboxAPIFacade(configuration.getClient(), exchange).get(configuration.getRemotePath());
Map<String, Object> map = result.getEntries();
if (map.size() == 1) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILE.name(), entry.getKey());
exchange.getIn().setBody(entry.getValue());
}
} else {
StringBuilder pathsExtracted = new StringBuilder();
for (Map.Entry<String, Object> entry : map.entrySet()) {
pathsExtracted.append(entry.getKey()).append("\n");
}
exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILES.name(), pathsExtracted.toString());
exchange.getIn().setBody(map);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Downloaded: {}", result.toString());
}
try {
// send message to next processor in the route
getProcessor().process(exchange);
// number of messages polled
return 1;
} finally {
// log exception if an exception occurred and was not handled
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
}
}
use of org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult in project camel by apache.
the class DropboxGetProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
DropboxFileDownloadResult result = new DropboxAPIFacade(configuration.getClient(), exchange).get(configuration.getRemotePath());
Map<String, Object> map = result.getEntries();
if (map.size() == 1) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILE.name(), entry.getKey());
exchange.getIn().setBody(entry.getValue());
}
} else {
StringBuilder pathsExtracted = new StringBuilder();
for (Map.Entry<String, Object> entry : map.entrySet()) {
pathsExtracted.append(entry.getKey()).append("\n");
}
exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILES.name(), pathsExtracted.toString());
exchange.getIn().setBody(map);
}
LOG.debug("Downloaded: {}", result.toString());
}
Aggregations