Karaf启动期间Camel端点创建失败

时间:2016-03-14 05:28:59

标签: java spring apache-camel apache-karaf

我正在使用Apache Karaf 2.3.1和Apache Camel 2.10.4。不管怎样,我想声明我无法更改任何一种产品的版本。

我在Karaf部署了许多捆绑包,一切正常。但有一段时间我在Karaf启动时遇到以下异常:

13:11:02,728 | ERROR | ExtenderThread-4 | BundleApplicationContextListener   50 | 68 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=camel-context.xml, config=osgibundle:/META-INF/spring/*.xml)) org.apache.camel.RuntimeCamelException:
**org.apache.camel.FailedToCreateRouteException: Failed to create route bosService: Route[[From[cxf:bean:MyServiceEndpoint]] -> [Bean[ref:JAXBF... because of Failed to resolve endpoint: cxf://bean:MyServiceEndpoint due to: No component found with scheme: cxf**    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1316)[176:org.apache.camel.camel-core:2.10.4]     at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120)[222:org.apache.camel.camel-spring:2.10.4]     at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:280)[222:org.apache.camel.camel-spring:2.10.4]   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)[63:org.springframework.context:3.1.4.RELEASE]  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:327)[63:org.springframework.context:3.1.4.RELEASE]   at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:941)[63:org.springframework.context:3.1.4.RELEASE]  at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)[67:org.springframework.osgi.core:1.2.1]   at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)[67:org.springframework.osgi.core:1.2.1]   at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[67:org.springframework.osgi.core:1.2.1]    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[67:org.springframework.osgi.core:1.2.1]     at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[68:org.springframework.osgi.extender:1.2.1]  at java.lang.Thread.run(Thread.java:724)[:1.7.0_25]
**Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route bosService: Route[[From[cxf:bean:MyServiceEndpoint]] -> [Bean[ref:JAXBF... because of Failed to resolve endpoint: cxf://bean:MyServiceEndpoint due to: No component found with scheme: cxf**     at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:177)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:722)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1789)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1575)[176:org.apache.camel.camel-core:2.10.4]    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1444)[176:org.apache.camel.camel-core:2.10.4]     at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:179)[222:org.apache.camel.camel-spring:2.10.4]    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)[176:org.apache.camel.camel-core:2.10.4]    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1412)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:228)[222:org.apache.camel.camel-spring:2.10.4]     at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:118)[222:org.apache.camel.camel-spring:2.10.4]     ... 10 more
**Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://bean:MyServiceEndpoint due to: No component found with scheme: cxf**    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:485)[176:org.apache.camel.camel-core:2.10.4]  at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:50)[176:org.apache.camel.camel-core:2.10.4]    at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:187)[176:org.apache.camel.camel-core:2.10.4]     at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:108)[176:org.apache.camel.camel-core:2.10.4]  at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:114)[176:org.apache.camel.camel-core:2.10.4]  at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:72)[176:org.apache.camel.camel-core:2.10.4]    at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:90)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:857)[176:org.apache.camel.camel-core:2.10.4]   at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:172)[176:org.apache.camel.camel-core:2.10.4]

这是我的 camel-context.xml

<beans:beans
       xmlns:beans="http://www.springframework.org/schema/beans"
       xmlns:camel-cxf="http://camel.apache.org/schema/cxf"
       xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://camel.apache.org/schema/cxf
                             http://camel.apache.org/schema/cxf/camel-cxf-2.15.2-spring.xsd
                           http://cxf.apache.org/transports/http-jetty/configuration
                             http://cxf.apache.org/schemas/configuration/http-jetty.xsd
                           http://cxf.apache.org/jaxrs
                             http://cxf.apache.org/schemas/jaxrs.xsd
                           http://www.springframework.org/schema/osgi  
                             http://www.springframework.org/schema/osgi/spring-osgi.xsd
                           http://camel.apache.org/schema/spring
                             http://camel.apache.org/schema/spring/camel-spring-2.10.4.xsd">
    <osgi:reference id="MyService"      
                     interface="com.foo.blah.camel.MyService"/>

    <beans:bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus"/>

    <httpj:engine-factory bus="cxf">
        <httpj:engine port="8888">
            <httpj:sessionSupport>true</httpj:sessionSupport>
        </httpj:engine>
    </httpj:engine-factory>

    <camel-cxf:cxfEndpoint id="MyServiceEndpoint"
                     serviceClass="com.foo.blah.service.MyWebService"
                     address="http://0.0.0.0:8888/MyWebService">
        <camel-cxf:inInterceptors>
            <beans:bean class="com.foo.blah.camel.SomeInInterceptor"/>
        </camel-cxf:inInterceptors>
        <camel-cxf:outInterceptors>
            <beans:bean class="com.foo.blah.camel.SomeOutInterceptor"/>
        </camel-cxf:outInterceptors>
    </camel-cxf:cxfEndpoint>

    <camelContext id="my-camel-ctx" 
                xmlns="http://camel.apache.org/schema/spring" trace="true">
        <route id="MyRoute">
            <from uri="cxf:bean:MyServiceEndpoint"/>
            <bean id="myService" ref="MyService"/>
        </route>
    </camelContext>
</beans:bean>

因为这个问题是间歇性的,所以我将成功的日志与包含上述堆栈的日志进行了比较。虽然大多数内容都是相同的,但我确实注意到以下明显的差异:

成功的日志摘录:

  

11:23:00,072 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到2个@Converter类来   加载11:23:00,104 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到2个@Converter类来   加载11:23:00,104 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到0 @Converter类来   加载11:23:00,119 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到2个@Converter类来   加载11:23:00,150 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到1个@Converter类来   加载11:23:00,150 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到1个@Converter类来   加载11:23:00,166 |信息| ExtenderThread-4 |   BundleTypeConverterLoader $ Loader 353 | 175 -   org.apache.camel.camel-core - 2.10.4 |找到1个@Converter类来   加载11:23:00,229 |信息| ExtenderThread-4 |   e.camel.impl.DefaultCamelContext 1398 | 175 -   org.apache.camel.camel-core - 2.10.4 | Apache Camel 2.10.4   (CamelContext:my-camel-ctx)正在开始

日志摘录失败:

  

13:11:02,587 |信息| ExtenderThread-4 |   e.camel.impl.DefaultCamelContext 1398 | 176 -   org.apache.camel.camel-core - 2.10.4 | Apache Camel 2.10.4   (CamelContext:my-camel-ctx)开始于13:11:02,587 |信息|   ExtenderThread-4 | e.camel.impl.DefaultCamelContext 1464 | 176 -   org.apache.camel.camel-core - 2.10.4 |已启用跟踪   CamelContext:my-camel-ctx 13:11:02,712 |信息| ExtenderThread-4 |   e.camel.impl.DefaultCamelContext 1590 | 176 -   org.apache.camel.camel-core - 2.10.4 | Apache Camel 2.10.4   (CamelContext:my-camel-ctx)正在关闭 13:11:02,712 |信息|   ExtenderThread-4 | verter.BaseTypeConverterRegistry 522 | 176 -   org.apache.camel.camel-core - 2.10.4 | TypeConverterRegistry   利用率[企图= 5,命中数= 4,未命中= 1 ,失败= 0]   映射[总计= 172,未命中= 1 ] 13:11:02,728 |信息| ExtenderThread-4   | e.camel.impl.DefaultCamelContext 1656 | 176 -   org.apache.camel.camel-core - 2.10.4 | Apache Camel 2.10.4   (CamelContext:my-camel-ctx)在0.000秒内关闭。正常运行时间   0.141秒。

正如你所看到的,Camel在启动后几乎立即关闭,我猜这是导致手头异常的原因。此外,它没有列出成功日志中表示的@Converter类,而是表示有一个未命中。我不确定这与关机有什么关系,但这是我在http://camel.apache.org/type-converter.html找到的:

  

返回空值默认情况下,在POJO中使用方法时   @Converter返回null的注释不是有效的响应。如果   返回null,然后Camel将该类型转换器视为a   想念,并防止将来使用它。如果为null应该是   允许作为有效的响应,然后从Camel 2.11.2 / 2.12开始   可以在注释中指定它,如下所示:

@Converter(allowNull = true) 
public static InputStream toInputStream(File file) throws
 IOException {
     if (file.exist()) {
         return new BufferedInputStream(new FileInputStream(file));
     } else {
         return null;
     } 
}

我的代码中没有任何@Coverter实例,因此必须抱怨我的应用程序引用的库中的实例。我到处寻找解决方案,但没有成功。所以任何帮助将不胜感激。谢谢。

0 个答案:

没有答案