Bundle 正在等待命名空间处理程序 [http://camel.apache.org/schema/blueprint]

Bundle is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]

我写了一个简单的 apache camel 项目,最终将部署在 FUSE 容器中。现在,我只是想让一个基本的单元测试正常工作。我使用示例 here 作为起点。

我已经编写了有效的单元测试,但是当我包含一个蓝图文件时,我在测试输出中得到以下条目:

Bundle TestMainRoute is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]

并且测试失败并显示以下堆栈跟踪:

java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:240)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:202)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createCamelContext(CamelBlueprintTestSupport.java:352)
at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:247)
at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:217)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:53)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

我的xml很简单:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
  <routeContext id="validationRoute"  xmlns="http://camel.apache.org/schema/blueprint" >

    <route id="validation">
        <from uri="direct:validation" />
        <log message="validating..." />
    </route>
</routeContext>

代码也是这样:

public class RouteTest extends CamelBlueprintTestSupport  {

  @Test
  public void testValidationRoute() throws Exception    {
    DefaultExchange r1 = new DefaultExchange(context);
    r1.getIn().setBody("");
    Exchange response1 = template.send("direct:validation", r1);
  }

  protected String getBlueprintDescriptor() {
    return "OSGI-INF/blueprint/blueprint.xml";
  1. 列表项

} }

注意,我的主要骆驼上下文引用了验证路线:

public class IntegrationFramework extends RouteBuilder {

public void configure() {

    from("netty-http:http://localhost:8457/broker/router.jsp").convertBodyTo(String.class)
    .log("http router "+simple("${body}").getText())
    .to("direct:validation");
}

我有其他单元测试和日志记录表明这部分工作正常。

原来routeContext只存在于xml dsl的上下文中,不能从Java DSL中引用。我认为这是一个错误,因为它限制了混合 xml 和 java 配置的灵活性。

通过将 routeContext 更改为 camelContext,这解决了问题。

另见这个问题:Camel: importing routeContext into an external camelContext

还相关:https://issues.apache.org/jira/browse/CAMEL-5717

我有同样的错误,但另一个设置然后@mdarwin,所以我也想与你分享我的解决方案。

我用 camel-archetype-blueprint 开始了一个项目,所以我的命名空间如下所示:

blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
   xsi:schemaLocation="
     http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
     http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
     http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">

一开始它是一个非常简单的蓝图,带有一个计时器和一个文件端点,所以这里的实现并不重要。我将我的包部署到 Karaf 并为此安装了 aries-blueprint 功能。

我错过了,我感到很惭愧,是安装 camel, too. For that I had to add the repo and than install it, as you can read here:

feature:repo-add camel
feature:install camel

现在命名空间处理程序就在那里。

我认为这很明显,但还是花了几分钟才弄明白。