骆驼为什么无法行驶

时间:2020-01-27 16:18:59

标签: apache-camel

我有一段非常简单的骆驼代码。

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();

    }

}

该路线的“发件人”部分正常。我能够连接到FTP服务器并在“订单”目录中找到文件。日志消息表明这一点。

orders文件夹的内容是一个文件: enter image description here

但是,当我随后尝试使用路由的to部分将这些文件复制到文件夹时,我看到以下失败信息

enter image description here

我已经尝试了相对路径和绝对路径(/ home / dsargrad / order_processed)。我已经验证了两条路径的存在。相对路径是相对于我运行Java应用程序的位置定义的。

以下是有效的绝对路径。 enter image description here

以下是绝对路径失败。

enter image description here

下图显示了来自独立FTP客户端的orders文件夹的内容。这告诉我FTP服​​务和用户名/密码很好。

enter image description here

1 个答案:

答案 0 :(得分:2)

运行带有依赖项的“超级” jar时,这是常见错误。一些Maven插件(例如maven-assembly-plugin)不包含某些META-INF条目,这些条目是正确的类型转换功能所必需的。请参阅以下常见问题解答条目:How to create executable JAR for camel-main project

我建议在以下配置中使用maven-shade-plugin

<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>