Search code examples
javaapache-camelcamel-ftp

No component found with scheme: sftp Apache Camel 2.14.1, ServiceMix 5.2.0


I’ve been having a lot of problems with the FTP component of Camel. I'm using Apache Camel 2.14.1 and Apache ServiceMix 5.2.0

The issue is that I’m getting this error whenever I try to do a FTP/SFTP transfer:

org.apache.camel.ResolveEndpointFailedException: 
Failed to resolve endpoint: sftp://user@sftp_url/test?binary=true&fileName=destinationFile.txt 
due to: No component found with scheme: sftp

I made sure that the required components are correctly installed in ServiceMix

karaf@pos-interfaces> list | grep camel-
[ 124] [Active     ] [            ] [       ] [   50] camel-core (2.14.1)
[ 125] [Active     ] [Created     ] [       ] [   50] camel-karaf-commands (2.14.1)
[ 126] [Active     ] [            ] [       ] [   50] camel-jms (2.14.1)
[ 132] [Active     ] [            ] [       ] [   50] camel-spring (2.14.1)
[ 133] [Active     ] [Created     ] [       ] [   50] camel-blueprint (2.14.1)
[ 213] [Active     ] [            ] [       ] [   50] camel-http (2.14.1)
[ 214] [Active     ] [            ] [       ] [   50] camel-jetty (2.14.1)
[ 271] [Active     ] [            ] [       ] [   50] camel-exec (2.14.1)
[ 285] [Active     ] [            ] [       ] [   50] camel-quartz2 (2.14.1)
[ 287] [Active     ] [            ] [       ] [   90] camel-jaxb (2.14.1)
[ 572] [Active     ] [            ] [       ] [   50] camel-ftp (2.14.1)
[ 573] [Active     ] [            ] [       ] [   50] camel-jsch (2.14.1)

And I even added some code to check if the “ftp/sftp” component was already in the context and it was started (I forcefully start it if not). This is what is printed in the log:

| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp component already there...
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp original status...Stopped
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp starting manually...
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | final sftp status...Started

But, I am still getting the error...

I found this article that has a similar issue than the one I have Camel not finding "sftp" component in registry and shutting down , and they say that using OsgiDefaultCamelContext fixed the problem, but I don’t think we can use that because we are using SpringCamelContext… or at least I haven't found any documentation/example to change the CamelContext class in spring-context.xml

Can you please advice? Thanks in advance.

[UPDATE] Finally made this work! The issue was that I declared the template like this:

producerTemplate = getContext().createProducerTemplate();

That way, the OSGI was not being setup and the error happened. But then, I updated my camel-context.xml with this:

<camelContext trace="false" id="camelContext"
    xmlns="http://camel.apache.org/schema/spring">
    <template id="producerTemplate"/>
    <routeBuilder ref="routeBuilder" />
</camelContext>

And my route builder with this:

@BeanInject("producerTemplate")
private transient ProducerTemplate producerTemplate;

And voilá! It worked!

Hope this helps someone!


Solution

  • Finally made this work! The issue was that I declared the template like this:

    producerTemplate = getContext().createProducerTemplate();
    

    That way, the OSGI was not being setup and the error happened. But then, I updated my camel-context.xml with this:

    <camelContext trace="false" id="camelContext"
        xmlns="http://camel.apache.org/schema/spring">
        <template id="producerTemplate"/>
        <routeBuilder ref="routeBuilder" />
    </camelContext>
    

    And my route builder with this:

    @BeanInject("producerTemplate")
    private transient ProducerTemplate producerTemplate;
    

    And voilá! It worked!

    Hope this helps someone!