【发布时间】:2013-02-03 07:49:17
【问题描述】:
我无法让我的 Camel 路由分别在 OSGI(Equinox)-Bundle 和插件项目中工作。
路线如下:
public class Example2Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
this.from("cxf:http://localhost:8080/exampleWS?wsdlURL=META-INF/exampleWS.wsdl&dataFormat=PAYLOAD").to("stream:out");
}
}
应该启动 Camel 上下文的我的测试类:
public class Test {
public static void run() throws Exception {
DefaultCamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new Example2Routes());
camelContext.start();
}
}
捆绑包在 Eclipse 中使用 OSGI Framework Run 配置启动。
控制台:
osgi> 19:53:17.712 DEBUG org.apache.cxf.common.logging.LogUtils:140 Using org.apache.cxf.common.logging.Slf4jLogger for logging.
19:53:17.728 INFO org.apache.cxf.bus.osgi.CXFActivator:88 Adding the extensions from bundle org.apache.camel.camel-cxf-transport (64) [org.apache.camel.component.cxf.transport.CamelTransportFactory]
19:53:17.743 INFO org.apache.camel.impl.osgi.Activator:84 Camel activator starting
19:53:17.743 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: InvokerInf
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.eclipse.osgi.services
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.eclipse.equinox.util
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: InvokerImpl
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: ch.qos.logback.core
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: ch.qos.logback.classic
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: wsdl4j
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.commons.logging
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: com.springsource.javax.activation
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: javax.mail
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.ws.xmlschema.core
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.cxf.bundle
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.transaction
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.camel.camel-cxf
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxf in bundle org.apache.camel.camel-cxf
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxfbean in bundle org.apache.camel.camel-cxf
19:53:17.760 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxfrs in bundle org.apache.camel.camel-cxf
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.neethi
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: slf4j.api
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: com.springsource.org.apache.xml.resolver
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: javax.ws.rs.javax.ws.rs-api
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.camel.camel-spring
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/spring-event in bundle org.apache.camel.camel-spring
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/spel in bundle org.apache.camel.camel-spring
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.beans
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.commons.codec
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: target
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: log4j
19:53:17.775 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.expression
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.eclipse.equinox.ds
19:53:17.791 INFO org.apache.camel.impl.osgi.Activator:87 Camel activator started
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/bean in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/browse in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/class in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/dataset in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/direct in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/direct-vm in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/file in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/language in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/log in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/mock in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/properties in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/ref in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/seda in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/stub in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/test in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/timer in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/validator in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/vm in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/xslt in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/bean in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/constant in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/file in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/header in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/property in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/ref in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/simple in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/tokenize in bundle org.apache.camel.camel-core
19:53:17.791 DEBUG org.apache.camel.impl.osgi.Activator:143 Found entry: META-INF/services/org/apache/camel/language/xpath in bundle org.apache.camel.camel-core
19:53:17.807 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.camel.camel-cxf-transport
19:53:17.807 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.context
19:53:17.807 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: CamelOSGIExample
19:53:17.807 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.eclipse.osgi
但是现在如何“启动” CamelContext?没有 osgi,作为标准的 java 应用程序,这个例子可以工作;但是我有一个包含骆驼上下文的主要方法。
我尝试使用 Activator 来启动骆驼上下文:
public class Activator implements BundleActivator {
@Override
public void start(BundleContext arg0) throws Exception {
Test.run();
}
}
但这会导致类似
的错误Failed to resolve endpoint: cxf://http://localhost:8081/exampleWS?dataFormat=PAYLOAD&wsdlURL=META-INF%2FexampleWS.wsdl due to: No component found with scheme: cxf
虽然控制台说:
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.ws.xmlschema.core
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.cxf.bundle
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.springframework.transaction
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:97 Bundle started: org.apache.camel.camel-cxf
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxf in bundle org.apache.camel.camel-cxf
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxfbean in bundle org.apache.camel.camel-cxf
20:13:04.319 DEBUG org.apache.camel.impl.osgi.Activator:128 Found entry: META-INF/services/org/apache/camel/component/cxfrs in bundle org.apache.camel.camel-cxf
可能是因为在启动所有需要的包/组件之前调用了 run 方法,所以 Activator 中的 Test.run() 出现问题? 但是如何启动骆驼上下文呢?
更新 1
更改为 OsgiDefaultCamelContext。做了一些进口。现在我得到了:
The bundle "org.apache.httpcomponents.httpclient_4.2.0 [119]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.http; version="4.2.0"
&
The bundle "CamelOSGIExample_1.0.0.qualifier [120]" could not be resolved. Reason: Missing Constraint: Import-Package: org.apache.http.nio.conn; version="4.0.0.beta3"
但是找不到这个包..
更新 2:
原因
java.lang.ClassNotFoundException: org.apache.http.nio.conn.ClientAsyncConnectionManager
我下载了 httpasyncclient-osgi-4.0-beta3.jar 并将 org.apache.http.nio.conn 添加到导入中。
在那之后我遇到了问题,以前的捆绑包需要例如org.apache.http.client 或 org.apache.http.auth。 所以我下载了 httpclient-osgi-4.2.1.jar 和 httpclient-osgi-4.2.2.jar (因为有些导入需要 4.2.1 版和一些4.2.2),其中包含所需的类。但是尽管将此捆绑包添加到午餐配置中,我还是得到了
org.osgi.framework.BundleException: Exception in siServer.Activator.start() of bundle CamleOSGIExample.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
...
Caused by: java.lang.NoClassDefFoundError: org/apache/http/nio/conn/ClientAsyncConnectionManager
at java.lang.Class.getDeclaredConstructors0(Native Method)
...
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.conn.ClientAsyncConnectionManager
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
...
Root exception:
java.lang.NoClassDefFoundError: org/apache/http/nio/conn/ClientAsyncConnectionManager
at java.lang.Class.getDeclaredConstructors0(Native Method)
...
Caused by: java.lang.ClassNotFoundException: org.apache.http.nio.conn.ClientAsyncConnectionManager
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
我不明白这个异常,因为我在导入中添加了 org.apache.http.nio.conn。
搜索需要 org.apache.http.nio.conn 的包并找到 cxf-2.7.3.jar。但我认为使用骆驼的 cfx 组件我也需要这个包..
【问题讨论】:
-
您需要安装导入所需的这些捆绑包。您可以在 maven Central 上使用高级搜索来查找包含这些包的 JAR:search.maven.org
-
顺便说一句,如果您使用 Apache Karaf / ServiceMix,那么在该容器中部署和使用 Camel 会更容易,使用特性和 spring-dm 或蓝图 xml 文件来引导您的应用程序。那么你就不需要摆弄 OSGi Activator 之类的了。
-
很遗憾,这不是我的决定。
-
查看 Apache Camel 的 features.xml 文件,你可以看到所有需要的 osgi 包 camel-cxf 等需要 - 很多。 repo2.maven.org/maven2/org/apache/camel/karaf/apache-camel/…
-
哇。有没有简单的方法来获取它们?
标签: osgi apache-camel