Search in sources :

Example 1 with DropboxSearchResult

use of org.apache.camel.component.dropbox.dto.DropboxSearchResult in project camel by apache.

the class DropboxScheduledPollSearchConsumer 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();
    DropboxSearchResult result = new DropboxAPIFacade(configuration.getClient(), exchange).search(configuration.getRemotePath(), configuration.getQuery());
    StringBuilder fileExtracted = new StringBuilder();
    for (DbxEntry entry : result.getFound()) {
        fileExtracted.append(entry.name).append("-").append(entry.path).append("\n");
    }
    exchange.getIn().setHeader(DropboxResultHeader.FOUND_FILES.name(), fileExtracted.toString());
    exchange.getIn().setBody(result.getFound());
    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());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) DbxEntry(com.dropbox.core.DbxEntry) DropboxSearchResult(org.apache.camel.component.dropbox.dto.DropboxSearchResult) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Example 2 with DropboxSearchResult

use of org.apache.camel.component.dropbox.dto.DropboxSearchResult in project camel by apache.

the class DropboxSearchProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    DropboxSearchResult result = new DropboxAPIFacade(configuration.getClient(), exchange).search(configuration.getRemotePath(), configuration.getQuery());
    StringBuilder fileExtracted = new StringBuilder();
    for (DbxEntry entry : result.getFound()) {
        fileExtracted.append(entry.name).append("-").append(entry.path).append("\n");
    }
    exchange.getIn().setHeader(DropboxResultHeader.FOUND_FILES.name(), fileExtracted.toString());
    exchange.getIn().setBody(result.getFound());
}
Also used : DbxEntry(com.dropbox.core.DbxEntry) DropboxSearchResult(org.apache.camel.component.dropbox.dto.DropboxSearchResult) DropboxAPIFacade(org.apache.camel.component.dropbox.core.DropboxAPIFacade)

Aggregations

DbxEntry (com.dropbox.core.DbxEntry)2 DropboxAPIFacade (org.apache.camel.component.dropbox.core.DropboxAPIFacade)2 DropboxSearchResult (org.apache.camel.component.dropbox.dto.DropboxSearchResult)2 Exchange (org.apache.camel.Exchange)1