当前位置: 首页 > 知识库问答 >
问题:

如何在osgi插件项目中启动camelcontext?

孟昊空
2023-03-14

我在让我的Camel路线在OSGI(Equinox)-捆绑包和插件项目中工作时遇到了问题。

路线如下所示:

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框架运行配置启动。

安慰:

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应用程序,这个例子是有效的;但在那里,我有一个主要的方法,其中有骆驼的背景。

我尝试用一个激活器来启动camel上下文:

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

也许Activator中Test.run()的问题发生是因为在启动所有需要的捆绑包/组件之前调用了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。连接到进口。

之后我遇到了问题,以前的包需要org.apache.http.client或org.apache.http.auth,所以我下载了httpclient-osgi-4.2.1.jar和http client-OSGi-4.2.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)  

我不明白这个异常,因为我添加了o

搜索需要org.apache.http.nio的捆绑包。连接并找到了cxf-2.7.3.jar。但我认为,使用camel的cfx组件,我还需要这个包。。

共有2个答案

松元明
2023-03-14

你可以试试它为什么延迟实例化。如果一个外滩

伍皓
2023-03-14

您需要使用一个OsgiDefaultCamelContext当哟

 类似资料:
  • 问题内容: 我刚刚在eclipse中签出了一个svn项目作为Java项目。我想重用其中的几个运行启动文件,但不知道如何指向“运行”来查看或使用这些启动文件。有小费吗?谢谢 问题答案: 通常,这些将由项目自动拾取并放置在运行菜单中。如果不是,请右键单击.launch文件,然后选择“运行方式”并选择第一个选项。这将使用该运行配置运行。

  • 更新!!!! 观看缩进!我的插件部分在我的代码编辑器中缩进,因此它作为包主题的一部分读取。现在我至少有一个插件在工作,我觉得有点理智。现在开始调试另一个... 谢谢,留下这个以防其他人犯同样的错误! 作为参考: MKDocs 1.0.4 Pip 19.2.3 Python 3.8.1 很抱歉没有发布原始代码,因为这可能会有所帮助,因为需要另一个同事开发人员才能为我注意到这一点。 原帖子: 我不太确

  • 我已经为我的产品创建了一个更新站点,它由一组Eclipse插件组成。我希望在安装产品后Eclipse启动时自动启动一些插件。 实际上,我知道Eclipse在配置\org.eclipse.equinox.simpleconfigurator\bundles.info文件中保存已安装插件的自动启动属性,并在插件安装后手动修改该文件。但是我想要一种自动化的方法来提供用户友好的安装过程。 有没有办法指定插

  • 嗨,我是薄荷Linux的新手,我想问一下如何在Linux薄荷中开始我的php项目。我已经安装了netbeans和XAMPP。它和窗户很不一样。我拿不到htdocs文件夹?。我尝试了以下操作 但是我如何获得像/home/user/netbeansprojects/phpproject1这样的路径。我无法获取htdocs文件夹。但是使用localhost我不能运行我的项目。我不知道这是不是实际的方法。

  • 安装了win10,安装了Visual Studio+Xamarin。我创建了Xamarin论坛项目,并尝试在Android上运行: 如何正确地开始?

  • 我创建了一个android项目(项目A),并在其中导入了另一个项目(项目B),其中包含: - 现在我想从项目A调用位于项目B内部的活动。 我用过: 但我明白了 类不成立异常 如何解决这个问题? 使现代化 我发现我需要使用以下方法将项目B作为依赖项添加到项目a中: 项目结构/依赖关系/ 当我试图构建我得到这个错误: 错误:无法确定任务的依赖项:app: compileDebugJavaBackJav