Dave Sargrad
Dave Sargrad

Reputation: 45

Why does the camel to route fail

I have a very simple piece of camel code.

public class MainApp2 {

    /**
     * A main() so we can easily run these routing rules in our IDE
     */
    public static void main(String... args) throws Exception {
        CamelContext context = new DefaultCamelContext();

        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("sftp://ghana.corp.sensis.com:22/orders/?username=dsargrad&password=xxx")
                        .log("Received order: ${header.CamelFileName}")
                        //.to("file:///home/dsargrad/order_processed")
                        .to("file:data/outbox")
                        ;
            }
        });

        context.start();
        Thread.sleep(1000000);

        context.stop();

    }

}

The "from" portion of the route works ok. I am able to connect to the FTP server and find files in the "orders" directory. The log message indicates that.

The content of the orders folder is a single file: enter image description here

However when I then try to copy those files to a folder, using the to portion of the route, I see the following failure

enter image description here

I've tried this both with a relative path and an absolute path (/home/dsargrad/order_processed). I've verified the existence of both paths. The relative path is defined relative to the location that I run the java application.

The following is the valid absolute path. enter image description here

The following is the failure with the absolute path.

enter image description here

The following picture shows the content of the orders folder from an independent FTP client. This tells me that the FTP service and the username/password is fine.

enter image description here

Upvotes: 1

Views: 296

Answers (1)

Bedla
Bedla

Reputation: 4929

This is common error when running "uber" jar with dependencies. Some Maven plugins (e.g. maven-assembly-plugin) excludes some META-INF entries, which are required for correct function of type conversion. See this FAQ entry: How to create executable JAR for camel-main project.

I suggest to use maven-shade-plugin with following configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>executable-jar</shadedClassifierName>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>my.package.MainClass</mainClass> <!-- Change main class here -->
                    </transformer>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/services/org/apache/camel/TypeConverterLoader</resource>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

Upvotes: 2

Related Questions