为什么骆驼路由失败 [英] Why does the camel to route fail

查看:22
本文介绍了为什么骆驼路由失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

    }

}

路线的来自"部分工作正常.我能够连接到 FTP 服务器并在订单"目录中找到文件.日志消息表明了这一点.

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.

orders 文件夹的内容是单个文件:

The content of the orders folder is a single file:

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

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

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

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.

以下是使用绝对路径失败.

The following is the failure with the absolute path.

下图显示了一个独立的FTP客户端的orders文件夹的内容.这告诉我 FTP 服务和用户名/密码没问题.

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.

推荐答案

这是运行带有依赖项的uber"jar 时的常见错误.一些 Maven 插件(例如 maven-assembly-plugin)排除了一些 META-INF 条目,这是正确的类型转换功能所必需的.请参阅此常见问题解答条目:如何为camel-main 项目创建可执行JAR.

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.

我建议使用具有以下配置的 maven-shade-plugin:

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>

这篇关于为什么骆驼路由失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆