Camel 错误:无法启动蓝图捆绑包null/0.0.0的容器,原因是应用程序在开始执行之前关闭/超时

bbmckpt7  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(96)

JAVA语言

正如您所看到的,我已经从Blueprint JUnit测试用例类BlueprintRouteTest.java中添加了以下代码片段,通过该代码片段,我可以通过blueprint-bean.xml从camel组件类中检索消息,但在作为JUnit执行此代码时,由于蓝图捆绑包的容器无法启动,因此该代码将关闭。

package com.sap.dropbox;

import java.util.concurrent.TimeUnit;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.junit.Test;

public class BlueprintRouteTest extends CamelBlueprintTestSupport 

  {

    @Produce(uri = "camel-dropbox")
    protected ProducerTemplate inputEndpoint;

    @Override
    protected String getBlueprintDescriptor()
    {
        return "/OSGI-INF/blueprint/blueprint-bean.xml";
    }

    @Override
    protected String getBundleFilter()
    {
        return "(!(Bundle-SymbolicName=camel-dropbox.camelDropbox))";
    }

    @Test
    public void testRoute() throws Exception 
    {
      context.getRouteDefinition("timerToLog").adviceWith(context, new 
      AdviceWithRouteBuilder() 
    {
        @Override
        public void configure() throws Exception
         {
            mockEndpointsAndSkip("camel-dropbox");
            context.getShutdownStrategy().setTimeout(5000);
            context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);

         }
 });

        String request = "Login Hello";
        Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
        senderExchange.getIn().setBody(request);
        Exchange exchange = inputEndpoint.send(senderExchange);
        Message input = exchange.getIn();
        String output = input.getBody(String.class);
        System.out.println("SAP Test cases  " + output);

    }

}

蓝图Bean.xml

正如您在下面看到的,我已经添加了blueprint-bean.xml内容,该内容显示了我如何通过blueprint-bean.xml导航到camel组件类。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:cxf="http://cxf.apache.org/blueprint/core"
    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">

    <!-- <cm:property-placeholder persistent-id="HelloBean" update-strategy="reload"> 
        <cm:default-properties> <cm:property name="greeting" value="Hi from Camel" 
        /> </cm:default-properties> </cm:property-placeholder> 

        <bean id="helloBean" 
        class="com.sap.dropbox.HelloBean"> <property name="say" value="${​​​greeting}​​​" 
        /> </bean> -->

    <camelContext id="blueprint-bean-context" 
     xmlns="http://camel.apache.org/schema/blueprint">

    <endpoint id="sender" uri="camel-dropbox">
        <property key="message" value="login successfully" />
    </endpoint>

    <route id="timerToLog" >
            <!-- <reference id="timerToLog" interface="org.apache.camel.spi.ComponentResolver" 
     timeout="30000"/> -->
            <!--  <from uri="timer:foo?period=5000"/>-->
            <!-- <setBody> <method ref="helloBean" method="hello" /> </setBody> -->
            <from uri="timer:foo?period=6000s&amp;delay=50s" />
            <to uri="ref:sender" />
    </route>

    </camelContext>
</blueprint>

来自Eclipse控制台的错误

这是我在执行BlueprintRouteTest.java类作为JUnit测试时遇到的问题,因为它无法启动蓝图捆绑包的容器,原因是应用程序在执行开始前关闭,并引发IndexOutOfBoundsException & NullPointer Exception

[                          main] CamelBlueprintHelper           INFO  Using Blueprint XML file: /C:/Users/rashid.khan/OneDrive%20-%20HCL%20Technologies%20Ltd/Documents/eclipse/camelDropbox/target/classes/OSGI-INF/blueprint/blueprint-bean.xml
Sep 27, 2021 5:45:18 PM org.ops4j.pax.swissbox.tinybundles.core.metadata.RawBuilder run
INFO: Copy thread finished.
Sep 27, 2021 5:45:18 PM org.ops4j.pax.swissbox.tinybundles.core.metadata.RawBuilder run
INFO: Copy thread finished.
[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Blueprint bundle BlueprintRouteTest/1.0.0 is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]
[         Blueprint Extender: 1] BlueprintContainerImpl         ERROR Unable to start container for blueprint bundle null/0.0.0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:659) ~[?:1.8.0_291]
    at java.util.ArrayList.get(ArrayList.java:435) ~[?:1.8.0_291]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.readDirectives(BlueprintContainerImpl.java:218) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:304) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:278) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_291]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_291]
    at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:45) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_291]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_291]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_291]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_291]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_291]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_291]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_291]
[                          main] Activator                      INFO  Camel activator starting
[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Blueprint bundle org.apache.aries.blueprint.cm/1.3.0 has been started
[         Blueprint Extender: 3] BlueprintContainerImpl         INFO  Blueprint bundle org.apache.aries.blueprint.core/1.10.0 has been started
[         Blueprint Extender: 2] BlueprintContainerImpl         INFO  Blueprint bundle org.apache.camel.camel-blueprint/2.24.2 has been started
[                          main] Activator                      INFO  Camel activator started
[                          main] BlueprintEventDispatcher       WARN  Listener caused an exception, will be ignored
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_291]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_291]
    at java.util.concurrent.AbstractExecutorService.doInvokeAny(AbstractExecutorService.java:193) ~[?:1.8.0_291]
    at java.util.concurrent.AbstractExecutorService.invokeAny(AbstractExecutorService.java:225) ~[?:1.8.0_291]
    at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper$4.call(ScheduledExecutorServiceWrapper.java:185) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper$15.call(ScheduledExecutorServiceWrapper.java:446) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.utils.threading.RWLock.runReadOperation(RWLock.java:33) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.runUnlessShutdown(ScheduledExecutorServiceWrapper.java:443) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.invokeAny(ScheduledExecutorServiceWrapper.java:180) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher.callListener(BlueprintEventDispatcher.java:188) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher.sendInitialEvents(BlueprintEventDispatcher.java:119) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher.access$100(BlueprintEventDispatcher.java:62) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher$2.addingService(BlueprintEventDispatcher.java:98) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher$2.addingService(BlueprintEventDispatcher.java:93) [org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941) [org.apache.felix.connect-0.2.0.jar:?]
    at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870) [org.apache.felix.connect-0.2.0.jar:?]
    at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) [org.apache.felix.connect-0.2.0.jar:?]
    at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229) [org.apache.felix.connect-0.2.0.jar:?]
    at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:852) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:775) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:594) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.PojoSR$1.serviceChanged(PojoSR.java:78) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.felix.framework.ServiceRegistry.registerService(ServiceRegistry.java:130) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.PojoSRBundleContext.registerService(PojoSRBundleContext.java:97) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.felix.connect.PojoSRBundleContext.registerService(PojoSRBundleContext.java:384) [org.apache.felix.connect-0.2.0.jar:?]
    at org.apache.camel.test.blueprint.CamelBlueprintHelper.waitForBlueprintContainer(CamelBlueprintHelper.java:338) [camel-test-blueprint-2.24.2.jar:2.24.2]
    at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createBundleContext(CamelBlueprintTestSupport.java:174) [camel-test-blueprint-2.24.2.jar:2.24.2]
    at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:248) [camel-test-blueprint-2.24.2.jar:2.24.2]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_291]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_291]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_291]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_291]
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) [junit-4.12.jar:4.12]
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) [junit-4.12.jar:4.12]
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) [junit-4.12.jar:4.12]
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) [junit-4.12.jar:4.12]
    at org.junit.rules.RunRules.evaluate(RunRules.java:20) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) [junit-4.12.jar:4.12]
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) [.cp/:?]
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:?]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) [.cp/:?]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) [.cp/:?]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) [.cp/:?]
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) [.cp/:?]
Caused by: java.lang.NullPointerException
    at org.apache.camel.test.blueprint.CamelBlueprintHelper$2.blueprintEvent(CamelBlueprintHelper.java:341) ~[camel-test-blueprint-2.24.2.jar:2.24.2]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188) ~[org.apache.aries.blueprint.core-1.10.0.jar:1.10.0]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_291]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_291]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_291]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_291]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_291]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:1.8.0_291]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:1.8.0_291]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_291]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_291]
    at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_291]
[         Blueprint Extender: 1] BlueprintCamelStateService     INFO  Karaf BundleStateService not accessible. Bundle state won't reflect Camel context state
[         Blueprint Extender: 1] BlueprintContainerImpl         INFO  Blueprint bundle BlueprintRouteTest/1.0.0 has been started
[                          main] BlueprintRouteTest             INFO********************************************************************************
[ Blueprint Event Dispatcher: 1] BlueprintCamelContext          INFO  Attempting to start CamelContext: blueprint-bean-context
[                          main] BlueprintRouteTest             INFO  Testing: testRoute(com.sap.dropbox.BlueprintRouteTest)
[                          main] BlueprintRouteTest             INFO********************************************************************************
[                          main] BlueprintRouteTest             INFO  Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.
[                          main] BlueprintCamelContext          INFO  Apache Camel 2.24.2 (CamelContext: blueprint-bean-context) is starting
[                          main] ManagedManagementStrategy      INFO  JMX is enabled
[                          main] BlueprintCamelContext          INFO  StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[                          main] BlueprintCamelContext          INFO  Route: timerToLog started and consuming from: timer://foo?delay=50s&period=6000s
[                          main] BlueprintCamelContext          INFO  Total 1 routes, of which 1 are started
[                          main] BlueprintCamelContext          INFO  Apache Camel 2.24.2 (CamelContext: blueprint-bean-context) started in 0.229 seconds
[                          main] ceptSendToMockEndpointStrategy INFO  Adviced endpoint [camel-dropbox] with mock endpoint [mock:camel-dropbox]
[                          main] DefaultShutdownStrategy        INFO  Starting to graceful shutdown 1 routes (timeout 5000 seconds)
[text) thread #2 - ShutdownTask] DefaultShutdownStrategy        INFO  Route: timerToLog shutdown complete, was consuming from: timer://foo?delay=50s&period=6000s
[                          main] DefaultShutdownStrategy        INFO  Graceful shutdown of 1 routes completed in 0 seconds
[                          main] BlueprintCamelContext          INFO  Route: timerToLog is stopped, was consuming from: timer://foo?delay=50s&period=6000s
[                          main] BlueprintCamelContext          INFO  Route: timerToLog is shutdown and removed, was consuming from: timer://foo?delay=50s&period=6000s
[                          main] RouteDefinition                INFO  AdviceWith route after: Route(timerToLog)[[From[timer:foo?period=6000s&delay=50s]] -> [To[ref:sender]]]
[                          main] RouteDefinition                INFO  Adviced route before/after as XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<route xmlns="http://camel.apache.org/schema/spring" customId="true" id="timerToLog">
    <from uri="timer:foo?period=6000s&amp;delay=50s"/>
    <to id="to1" uri="ref:sender"/>
</route>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<route xmlns="http://camel.apache.org/schema/spring" customId="true" id="timerToLog">
    <from uri="timer:foo?period=6000s&amp;delay=50s"/>
    <to id="to1" uri="ref:sender"/>
</route>

[                          main] BlueprintCamelContext          INFO  Route: timerToLog started and consuming from: timer://foo?delay=50s&period=6000s
 Dropbox Producer message from blueprint xml: $$: Login Hello
SAP Test cases  Login Hello
[                          main] BlueprintRouteTest             INFO********************************************************************************
[                          main] BlueprintRouteTest             INFO  Testing done: testRoute(com.sap.dropbox.BlueprintRouteTest)
[                          main] BlueprintRouteTest             INFO  Took: 0.555 seconds (555 millis)
[                          main] BlueprintRouteTest             INFO********************************************************************************
[                          main] BlueprintCamelContext          INFO  Apache Camel 2.24.2 (CamelContext: blueprint-bean-context) is shutting down
[                          main] DefaultShutdownStrategy        INFO  Starting to graceful shutdown 1 routes (timeout 5000 seconds)
[text) thread #2 - ShutdownTask] DefaultShutdownStrategy        INFO  Route: timerToLog shutdown complete, was consuming from: timer://foo?delay=50s&period=6000s
[                          main] DefaultShutdownStrategy        INFO  Graceful shutdown of 1 routes completed in 0 seconds
[                          main] BlueprintCamelContext          INFO  Apache Camel 2.24.2 (CamelContext: blueprint-bean-context) uptime 0.568 seconds
[                          main] BlueprintCamelContext          INFO  Apache Camel 2.24.2 (CamelContext: blueprint-bean-context) is shutdown in 0.014 seconds
fquxozlt

fquxozlt1#

对于初学者来说,您的dropbox端点配置不正确。dropbox组件的URI是dropbox://[operation]?[options],而不是camel-dropbox。此外,dropbox没有名为message的查询参数。

<endpoint id="sender" uri="dropbox://put">
    <property key="accessToken" value="xxxxxx"/>
    <property key="clientIdentifier" value="xxxxxx"/>
    <property key="remotePath" value="/root/folder1"/>
</endpoint>

然后,在测试过程中,您可以使用以下命令测试路由

@Test
public void testRoute() throws Exception 
{

    context.getRouteDefinition("timerToLog").adviceWith(context, new AdviceWithRouteBuilder(){

        @Override
        public void configure() throws Exception {

            replaceFromWith("direct:start");
            weaveByToUri("ref:*")
                .replace()
                .to("mock:result");
        }
    });

    context.start();        

    MockEndpoint resultMockEndpoint = getMockEndpoint("mock:result");
    resultMockEndpoint.expectedMessageCount(1);
    resultMockEndpoint.message(0).body().isEqualTo("Hello world");

    template.sendBody("direct:start", "Hello world");

    resultMockEndpoint.assertIsSatisfied();
}

由于我们使用的是advice with,因此请记住在每次测试期间覆盖isUseAdviceWith方法并手动启动CamelContext。

@Override
public boolean isUseAdviceWith() {
    return true;
}

相关问题