I am trying to consume a single file using a fixed name. My code does work but it takes 20 or 30 seconds to obtain a PDF from a directory
I read from the camel documentation that it would be possible: link
They said something like using this:
from("ftp://admin@localhost:21/nolist/?password=admin&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true")
.to("activemq:queue:report");
I don't know how to achieve that in my code:
package ar.com.project.esb.route;
import ar.com.project.camel.common.route.RestRouteBuilder;
import ar.com.project.esb.Constants;
import org.apache.camel.LoggingLevel;
import org.apache.camel.model.rest.RestParamType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.ws.rs.core.MediaType;
@Component
public class GetReceiptsPDFRoute extends RestRouteBuilder {
@Value("${timeout.FTP}")
private Long timeoutFTP;
@Override
public void configure() {
super.configure();
rest(restApiPath)
.get("/receipts/pdf?companyNumber={companyNumber}&accountNumber={accountNumber}&documentType={documentType}&transactionNumber={transactionNumber}").id("receipts PDF")
.param().name("companyNumber").type(RestParamType.query).dataType("String").required(true).endParam()
.param().name("accountNumber").type(RestParamType.query).dataType("String").required(true).endParam()
.param().name("documentType").type(RestParamType.query).dataType("String").required(true).endParam()
.param().name("transactionNumber").type(RestParamType.query).dataType("String").required(true).endParam()
.consumes(MediaType.APPLICATION_JSON)
.produces("application/pdf")
.to("direct:receiptsPDF");
/**
* set name and location to find PDF documents in FTP directory
*/
from("direct:receiptsPDF").routeId("ReceiptsPDF")
.setProperty("currentOperation", constant("ReceiptsPDF"))
.log(LoggingLevel.INFO,"getClaimStatus", "[Inicia ${property.currentOperation}]")
.log(LoggingLevel.INFO, "company Number: ${header.companyNumber}")
.log(LoggingLevel.INFO, "account Number: ${header.accountNumber}")
.log(LoggingLevel.INFO, "document Type: ${header.documentType}")
.log(LoggingLevel.INFO, "transaction Type: ${header.transactionNumber}")
.doTry()
.choice()
.when(header("documentType").isEqualTo(Constants.RECEIPT))
.log(LoggingLevel.INFO, "[${property.currentOperation}] Find RECEIPT")
.setHeader("TARGET_DIR", constant("{{source.erp.RECEIPTs}}"))
.endChoice()
.otherwise()
.log(LoggingLevel.INFO, "[${property.currentOperation}] Find DOCUMENTS")
.setHeader("TARGET_DIR", constant("{{source.erp.DOCUMENTS}}"))
.end()
.setProperty("fileName", simple("${header.companyNumber}${header.accountNumber}${header.documentType}${header.transactionNumber}.pdf"))
.to("direct:findPdfInFTP")
.log(LoggingLevel.INFO,"getClaimStatus", "[Ending ${property.currentOperation}]")
.endDoTry()
.doCatch(Exception.class)
.log(LoggingLevel.ERROR, "getReceipts", "[ERROR: ${exception.message}")
.end();
/**
* Search in FTP directory
*/
from("direct:findPdfInFTP").routeId("find file in ftp")
.doTry()
.log(LoggingLevel.INFO, "Search: ${header.TARGET_DIR}/${property.fileName}")
.pollEnrich().simple("{{erp.sftp}}/${header.TARGET_DIR}?password={{erp.sftp.password}}&fileName=${property.fileName}&disconnect=true&noop=true&recursive=true&useUserKnownHostsFile=false&idempotent=false&include=.*.pdf").timeout(timeoutFTP)
.choice()
.when(simple("${body} == null"))
.log(LoggingLevel.ERROR, "getClaimStatus", "[ERROR: file does not exist...]")
.otherwise()
.log(LoggingLevel.INFO,"FILE OBTAINED: ${headers.CamelFileName}")
.endDoTry()
.doCatch(Exception.class)
.log(LoggingLevel.ERROR, "getReceipts", "[ERROR: ${exception.message}")
.end();
}
}
I tried something like this:
.pollEnrich().simple("{{erp.sftp}}/${header.TARGET_DIR}?password={{erp.sftp.password}}&fileName=${property.fileName}&disconnect=true&noop=true&idempotent=false&useList=false&ignoreFileNotFoundOrPermissionError=true&useUserKnownHostsFile=false").timeout(timeoutFTP)
By adding the useList=false&ignoreFileNotFoundOrPermissionError=true the recursion option in the internal subfolders is gone.
How can i make it work?