在DefaultCamelContext.start()上引起的StackOverflowException似乎是由camel goint引入无限循环引起的

时间:2012-10-01 17:26:27

标签: apache-camel stack-overflow

我搜索了这个并且还没有找到问题。我正在创建一个骆驼路线,它可以监视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!");

目前返回的filePath只是“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,并且正在通过maven导入camel,并在POM中输入以下条目:

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

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

  

2012年10月1日上午9:33:50 com.saic.ogc.client.BaseClient createMessageFactory   信息:默认为内置消息工厂......   2012年10月1日上午9:33:50 com.saic.ogc.client.BaseClient initTemplate   信息:设置拦截器!   线程“main”中的异常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)
  

2 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:0)

我有类似的问题。我有一个实现处理器的RouteBuilder(因为我很懒)。事实证明,这导致无限递归。修复是将进程(...)的实现移动到它自己的类。