4

我已经搜索过这个并且还没有找到这个问题。我正在创建一个骆驼路线,它监视 shapefile (.shp) 的文件夹。下面的代码是实现骆驼路线的代码。

final String filePath = settings.getSetting(GMTI_VOCAB.SHAPEFILE_PATH);
logger.debug("filePath={}", filePath);
final File file = new File(filePath);
if (file.mkdir())
{
  logger.warn("Shapefile path did not exist. Creating directory.");
}

logger.debug("Creating file route.");
context.addRoutes(new RouteBuilder()
{

    @Override
    public void configure() throws Exception
    {
        String path = String.format("file://%s?noop=true&include=.*shp$", file.getAbsolutePath());
        logger.debug("Route is: {}", path);
        from(path).bean(this, "process(${file:path})");
    }
 });
 logger.debug("Starting context");
 context.start();
 logger.info("Communicator started!");

目前返回的文件路径只是“shapefile”,导致 file.getAbsolutePath() 返回“C:\Users\medderssc\gmti_intestor\shapefiles”。返回的结果路径是

from("file://C:\Users\medderssc\gmti_intestor\shapefiles?noop=true&include=.*shp$").bean(this, "process(${file:path})");

context 是一个 DefaultCamelContext,camel 是通过 maven 导入的,在 POM 中有以下条目:

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.10.0</version>
    </dependency>

“通讯器启动”永远不会输出,程序在此之前崩溃,告诉我在 context.start() 期间发生错误。下面的堆栈跟踪显示了 StackOverflowException。请注意堆栈本身重复了几次,这意味着骆驼本身正在以某种方式进入某种无限递归循环。除了发布的代码之外,没有进一步的骆驼配置。任何人都可以帮忙吗?下面的异常堆栈:

2012 年 10 月 1 日上午 9:33:50 com.saic.ogc.client.BaseClient createMessageFactory 信息:默认为内置消息工厂... 2012 年 10 月 1 日上午 9:33:50 com.saic.ogc.client。 BaseClient initTemplate INFO:设置拦截器!线程“主”java.lang.StackOverflowError 中的异常

at org.apache.camel.model.RouteDefinition.toString(RouteDefinition.java:119)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RoutesDefinition.toString(RoutesDefinition.java:60)
at org.apache.camel.builder.RouteBuilder.toString(RouteBuilder.java:58)
at org.apache.camel.model.BeanDefinition.description(BeanDefinition.java:81)
at org.apache.camel.model.BeanDefinition.toString(BeanDefinition.java:70)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RouteDefinition.toString(RouteDefinition.java:119)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RoutesDefinition.toString(RoutesDefinition.java:60)
at org.apache.camel.builder.RouteBuilder.toString(RouteBuilder.java:58)
at org.apache.camel.model.BeanDefinition.description(BeanDefinition.java:81)
at org.apache.camel.model.BeanDefinition.toString(BeanDefinition.java:70)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RouteDefinition.toString(RouteDefinition.java:119)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RoutesDefinition.toString(RoutesDefinition.java:60)
at org.apache.camel.builder.RouteBuilder.toString(RouteBuilder.java:58)
at org.apache.camel.model.BeanDefinition.description(BeanDefinition.java:81)
at org.apache.camel.model.BeanDefinition.toString(BeanDefinition.java:70)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RouteDefinition.toString(RouteDefinition.java:119)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.apache.camel.model.RoutesDefinition.toString(RoutesDefinition.java:60)
at org.apache.camel.builder.RouteBuilder.toString(RouteBuilder.java:58)
at org.apache.camel.model.BeanDefinition.description(BeanDefinition.java:81)
at org.apache.camel.model.BeanDefinition.toString(BeanDefinition.java:70)
at java.lang.String.valueOf(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at java.util.AbstractCollection.toString(Unknown Source)
at java.lang.String.valueOf(Unknown Source)
4

2 回答 2

6

乍一看,问题似乎是您.bean(this,...)指的是匿名类(new RouteBuilder()),并将尝试运行configure()(因此递归/sfo)...尝试为您的 bean/process() 方法使用单独的类.. .

于 2012-10-02T06:03:47.827 回答
0

I had a similar problem. I had a RouteBuilder which implemented Processor (because I was being lazy). Turns out that this caused infinite recursion. The fix was to move the implementation of process(...) to it's own class.

于 2012-10-04T16:32:13.887 回答