0
votes

I am using Apache Camel to pull a file from a server using sftp. My code is receiving from

sftp://example.com:22/DEV139/Uploads/Alamo?username=admin&password=admin&binary=true&disconnect=true&delete=true

It can successfully grab files from this directory as I can see the file contents in my logs, but it then throws the following exception.

2017-11-06 16:18:42,498 | ERROR | || FromAlamoSFTP => [ msgtyp:AlamoCSV msgdst:CDX ] || java.lang.IllegalStateException: Invalid BundleContext. at org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514) at org.apache.felix.framework.BundleContextImpl.getBundle(BundleContextImpl.java:112) at org.apache.camel.core.osgi.OsgiClassResolver.resolveClass(OsgiClassResolver.java:58) at org.apache.camel.component.bean.BeanHelper.isAssignableToExpectedType(BeanHelper.java:121) at org.apache.camel.component.bean.BeanInfo.matchMethod(BeanInfo.java:1074) at org.apache.camel.component.bean.BeanInfo.removeNonMatchingMethods(BeanInfo.java:999) at org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java:566) at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:254) at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:185) at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:159) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196) at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) at org.apache.camel.processor.Pipeline.process(Pipeline.java:63) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:171) at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454) at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226) at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190) at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

My Code is as follows.

public class FromAlamoRouteBuilder extends RouteBuilder implements
    InitializingBean, DisposableBean {

@EnforceInitialization
private String DEAD_LETTER_MQ = "";

@EnforceInitialization
private String ALAMO_SFTP_SOURCE;   

@EnforceInitialization
private String DESTINATION_QUEUE;  


@EnforceInitialization(preventZero = false)
private int exceptionMaximumRedeliveries;

@EnforceInitialization(preventZero = false)
private int exceptionMaximumRedeliveriesDelay;  



public void configure() throws Exception {

    onException(Exception.class)
        .handled(true)
        .retriesExhaustedLogLevel(LoggingLevel.ERROR)
        .retryAttemptedLogLevel(LoggingLevel.WARN)
        .maximumRedeliveries((int) exceptionMaximumRedeliveries)
        .redeliveryDelay((int) exceptionMaximumRedeliveriesDelay)
        .bean("logging", "error(*, '${exception.stacktrace}')")
        .to(DEAD_LETTER_MQ)
        .stop();

    /*
     * The exchange body is expected to be an Alamo CSV file
     */ 
    from(ALAMO_SFTP_SOURCE)
        .routeId("FromAlamoSFTP")
        .setExchangePattern(ExchangePattern.InOnly)
        .bean("logging", "info(*, 'Received message " + ALAMO_SFTP_SOURCE  + "[${body}]')")
        .setHeader(MsgHdr.MESSAGE_TYPE, constant("AlamoCSV"))
        .setHeader(MsgHdr.MESSAGE_DESTINATION, constant("CDX"))
        .bean("logging", "info(*, 'Attempting to place Alamo msg on DESTINATION QUEUE " + DESTINATION_QUEUE + "')")
        .to(DESTINATION_QUEUE)      
        .bean("logging", "info(*, 'Successfully placed Alamo msg on " + DESTINATION_QUEUE + "')");

}

public void setDeadLetterQueue(String dEAD_LETTER_MQ) {
    DEAD_LETTER_MQ = dEAD_LETTER_MQ;
}

public void setExceptionMaximumRedeliveries(int exceptionMaximumRedeliveries) {
    this.exceptionMaximumRedeliveries = exceptionMaximumRedeliveries;
}

public void setExceptionMaximumRedeliveriesDelay(
        int exceptionMaximumRedeliveriesDelay) {
    this.exceptionMaximumRedeliveriesDelay = exceptionMaximumRedeliveriesDelay;
}

public void setDestinationQueue(String queue){
    this.DESTINATION_QUEUE = queue;  
}

public void setAlamoSftpSource(String bcRelease){
    this.ALAMO_SFTP_SOURCE = bcRelease;
}

public void afterPropertiesSet() throws Exception {
    System.out.println("FromAlamoRouteBuilder is starting up");
    FieldInitialization.checkAllFields(this);
} 


public void destroy() throws Exception {
    System.out.println("FromAlmoRouteBuilder is shutting down");
}
}
1
Are you sure it's SFTP you need to use? SFTP is part of SSH which runs on port 22 and not 21. 21 is the standard port for FTP, so it might actually be FTPS (explicit) you should use.Lothar
I changed port to 21 to hide server information on stack overflow as I dont want to give away server credentials. But I do use 22 in my code.Connor Blair
The weird thing is that I am able to grab the file successfully and then I get this error.Connor Blair
For the future. Use www.example.com as server name. This domain is reserved for documentation and other use cases (includnig yours). So you can keep the relevant stuff (like the port you're using) intact.Lothar
Is that the complete stacktrace or have you omitted "Caused by"-blocks?Lothar

1 Answers

0
votes

I found the solution to this problem. It was an error within server configuration not an error related to my code. Thanks everyone for their help