骆驼蓝图测试由于错误而失败无法启动捆绑包:org.apache.cxf.cxf-rt-transports-http

时间:2018-12-17 08:02:00

标签: apache-camel blueprint-osgi

我的骆驼蓝图测试失败,但出现以下异常:

Security Question 1 :
<select id="question1" name="question1">
  <option value="What is your favorite color?">What is your favorite color?</option>
  <option value="What is the name of your school in elementary?">What is the name of your school in elementary?</option>
  <option value="What is the name of your fist pet?">What is the name of your fist pet?</option>
  <option value="Who is your first love?">Who is your first love?</option>
</select>
<br/><br/> Security Question 2 :
<select id="question2" name="question2">
  <option value="What is your favorite color?">What is your favorite color?</option>
  <option value="What is the name of your school in elementary?">What is the name of your school in elementary?</option>
  <option value="What is the name of your fist pet?">What is the name of your fist pet?</option>
  <option value="Who is your first love?">Who is your first love?</option>
</select>
<br/><br/> Security Question 3 :
<select id="question3" name="question3">
  <option value="What is your favorite color?">What is your favorite color?</option>
  <option value="What is the name of your school in elementary?">What is the name of your school in elementary?</option>
  <option value="What is the name of your fist pet?">What is the name of your fist pet?</option>
  <option value="Who is your first love?">Who is your first love?</option>
</select>

这是测试的代码:

org.osgi.framework.BundleException: Unable to start bundle
                at org.apache.felix.connect.PojoSRBundle.start(PojoSRBundle.java:163)
                at org.apache.felix.connect.PojoSR.startBundles(PojoSR.java:304)
                at org.apache.felix.connect.PojoSR.<init>(PojoSR.java:248)
                at org.apache.felix.connect.PojoSR.<init>(PojoSR.java:129)
                at org.apache.felix.connect.PojoServiceRegistryFactoryImpl.newPojoServiceRegistry(PojoServiceRegistryFactoryImpl.java:52)
                at org.apache.camel.test.blueprint.CamelBlueprintHelper.createBundleContext(CamelBlueprintHelper.java:143)
                at org.apache.camel.test.blueprint.CamelBlueprintHelper.createBundleContext(CamelBlueprintHelper.java:108)
                at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createBundleContext(CamelBlueprintTestSupport.java:94)
                at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:199)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:498)
                at org.junit.runners.model.FrameworkMethod$1.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$1.evaluate(TestWatcher.java:55)
                at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
                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$3.run(ParentRunner.java:238)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
                at org.junit.runners.ParentRunner$2.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.junit.runner.JUnitCore.run(JUnitCore.java:160)
                at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
                at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
                at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
                at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/Servlet
                at java.lang.Class.getDeclaredConstructors0(Native Method)
                at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
                at java.lang.Class.getConstructor0(Class.java:3075)
                at java.lang.Class.newInstance(Class.java:412)
                at org.apache.felix.connect.PojoSRBundle.start(PojoSRBundle.java:152)
                ... 35 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.Servlet
                at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
                at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
                ... 40 more
Unable to start bundle: org.apache.cxf.cxf-rt-transports-http [11]

java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)

                at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:265)
                at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:226)
                at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createCamelContext(CamelBlueprintTestSupport.java:409)
                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:202)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:498)
                at org.junit.runners.model.FrameworkMethod$1.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$1.evaluate(TestWatcher.java:55)
                at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
                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$3.run(ParentRunner.java:238)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
                at org.junit.runners.ParentRunner$2.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.junit.runner.JUnitCore.run(JUnitCore.java:160)
                at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
                at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
                at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
                at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


Process finished with exit code -1

这是蓝图配置。看到,没有声明cxf-endpoint,只有ActiveMQ的属性:

import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.apache.activemq.junit.EmbeddedActiveMQBroker;

public class EnrichMessageWithSourceDataProcessorTest  extends CamelBlueprintTestSupport {
@Rule
public EmbeddedActiveMQBroker broker = new EmbeddedActiveMQBroker();

@Override
protected String getBlueprintDescriptor() {
    return "OSGI-INF/blueprint/configuration.xml";
}
@Test
public void processWithNullableExchangeSouldFail(){
// NOP - test fails even if no action has been taken
}
}

这是pom.xml依赖关系块(我们使用骆驼版本2.15.1.redhat-621084作为JBossFuse ESB的组件):

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           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">
    <cm:property-placeholder id="adpnfmout.placeholder" persistent-id="adpnfmout">
        <cm:default-properties>
            <cm:property name="module" value="AdpNFMOut"/>

            <!-- Public message broker settings -->
            <cm:property name="publicamq.userName" value=""/>
            <cm:property name="publicamq.password" value=""/>
            <cm:property name="publicamq.brokerURL" value="vm://localhost"/>

        </cm:default-properties>
    </cm:property-placeholder>
    <bean id="publicamq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="brokerURL" value="${publicamq.brokerURL}"/>
        <property name="userName" value="${publicamq.userName}"/>
        <property name="password" value="${publicamq.password}"/>
    </bean>
    <camelContext id="ctxUpdateClientRq" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="route1" startupOrder="20">
        </route>
    </camelContext>
</blueprint>

有一种特殊情况:开始测试时会生成与CXF相关的日志:

<dependencies>

    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-camel</artifactId>
    </dependency>


    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <scope>test</scope>
    </dependency>       
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test-blueprint</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq.tooling</groupId>
        <artifactId>activemq-junit</artifactId>
        <version>${activemq-junit.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

,如果我从pom中删除了CXF依赖关系,则测试成功通过。

1 个答案:

答案 0 :(得分:0)

听起来像您自己通过消除camel-cxf依赖关系来解决的问题。但是,如果您确实需要它,则需要添加一个传输实现以在测试期间使用,例如:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <scope>test</scope>
    </dependency>