0

I'm using the camel-sftp component to upload a file to an SFTP server. The code is simple:

File source = new File(path);
final String sftpUri = "sftp://" + userId  + "@" + serverAddress + "/" + remoteDirectory+"?password="+pwd;
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
     @Override
     public void configure() throws Exception {
        from("file:/" + path).to(sftpUri);
     }
});
context.start();
Thread.sleep(10000);
context.stop();

However, camel has problems finding the sftp component. Activating the debug logs in Camel it complains:

| 62 - org.apache.camel.camel-core - 2.13.2 | Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@29668a43 to resolve component with name: sftp
| 62 - org.apache.camel.camel-core - 2.13.2 | Found component: sftp in registry: null
| 62 - org.apache.camel.camel-core - 2.13.2 | Apache Camel 2.13.2 (CamelContext: camel-16) is shutting down

Any ideas why Camel is behaving this way? In fact, running this code in a standalone application (a Java class with a main method) works correctly. And I can see:

11:22:13.237 [main] DEBUG o.a.c.impl.DefaultComponentResolver - Found component: sftp in registry: null
11:22:13.239 [main] DEBUG o.a.c.impl.DefaultComponentResolver - Found component: sftp via type: org.apache.camel.component.file.remote.SftpComponent via: META-INF/services/org/apache/camel/component/sftp

Inside of Karaf, though, only the first line appears, for some reason or other it does not find META-INF/services/org/apache/camel/component/sftp and as a result the sftp component is not found.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
Pavitx
  • 81
  • 2
  • 17

1 Answers1

2

If you run Camel inside OSGi, you should use the OSGi CamelContext from camel-core-osgi. And then there is a few more steps to setup this for OSGi.

Though its often easier to use a OSGi blueprint application and bootstrap Camel in the blueprint xml file, which does this correctly.

But for Java code its some manual process. In the upcoming Camel 2.15 release there is a new camel-scr component for working with OSGi and SCR (Declarative Services) which makes it easier to do java code with Camel in OSGi using camel-scr.

I would suggest to check its current source code for inspiration how you can setup Camel in OSGi from Java code

https://github.com/apache/camel/tree/master/components/camel-scr

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • Using OsgiDefaultCamelContext in fact solves the problem and renders unnecessary to embed the camel-ftp bundle as dependency (which makes the bundle bigger, and which is ugly, because the camel-ftp bundle is already present in ServiceMix/Karaf). – Pavitx Feb 10 '15 at 14:36