0

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();
            }
    }

バンドルは、OSGI フレームワークの実行構成を使用して Eclipse 内で開始されます。

コンソール:

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

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.connを追加しました。

その後、以前のバンドルにはorg.apache.http.clientorg.apache.http.authなどを必要とするという問題が発生しました。そこで、必要なクラスを含むhttpclient-osgi-4.2.1.jarhttpclient-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 を見つけました。しかし、camel の cfx-component を使用するには、このバンドルも必要だと思います..

4

2 に答える 2

2

OSGi を使用する場合は、OsgiDefaultCamelContext を使用する必要があります。このクラスは camel-core-osgi にある必要があります。

于 2013-02-19T07:29:15.343 に答える
0

なぜ怠惰なインスタンス化を試すことができます。バンドルの開始ポリシーが「lazy」に設定されている場合、クラスがロードされ、そのクラスの1つが別のバンドルによってロードされたときにのみ開始されます。 http://www.osgi.org/Design/LazyStart

于 2013-02-18T19:37:10.227 に答える