1

1 つのサーブレットと 1 つの JPS で WAR を構築し、maven バンドル プラグインを使用してバンドルを作成するように変換しました。サーブレットと jsp は、pax-web を使用する Apache Karaf で正常に動作しています。今、そのサーブレットで Web サービス クライアントを使用したいと考えています。どうすればそれを達成できますか?

ここまでは、cxf-codegen maven プラグインを使用して、クライアントを構築するために必要なすべてのクラスを作成しました。すべての依存関係があります: cxf-rt-transports-httpcxf-rt-ws-addrcxf-rt-ws-policycxf-rt-frontend-jaxrscxf-rt-ws-securityおよびcxf-rt- transports-http-jettyは Maven で宣言されています。さらに、blueprint.xml 内に次のエントリがあります。

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
   http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
   http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd">


    <bean id="myServlet" class="com.production.dashboard.DataCombination">
            <property name="dataMergingService" ref="dataMergingService"/>
    </bean>

    <service ref="myServlet" interface="javax.servlet.http.HttpServlet">
            <service-properties>
                    <entry key="alias" value="/hello" />
            </service-properties>
    </service>

    <jaxws:client id="dataMergingService"
            serviceClass="com.production.engine.datacombination.OrderDataMergingService"
            address="http://localhost:8181/engine/datacombination?wsdl" />

このアプローチを使用すると、クライアントが常に null であるため、インジェクションは失敗します。

Web サービス クライアントを OSGi、ブループリント、および war 対応バンドルと組み合わせて使用​​する方法を説明してもらえますか?

よろしくお願いします。

乾杯ヒルデリッヒ

4

2 に答える 2

1

ご連絡をお待ちしております。その間、OSGi コンテナーで実行されている Java Web アプリケーションについての理解が深まりました。

まず、私のアプリケーションは通常の Java Web アプリケーション、つまり WAR です。追加の OSGi マニフェスト メタ データ ( Web-ContextPath、Webapp-Context ) により、WAR は Web アプリケーション バンドル (WAB) として有効になりました。さらに、前述のように、ブループリント エクステンダーが検出しようとしているマニフェスト メタデータ ( Bundle-Blueprint ) がなかったため、 blueprint.xmlは OSGi コンテナーApache Karafによって認識されませんでした。

Maven バンドル プラグイン (つまり、bnd ツール) は、すべてのビルドで WAB をビルドしています。

<plugin>
       <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <inherited>true</inherited>
        <executions>
           <execution>
            <id>bundle-manifest</id>
            <phase>process-classes</phase>
            <goals>
                  <goal>manifest</goal>
            </goals>
            <configuration>
                     <supportedProjectTypes>
                <supportedProjectType>jar</supportedProjectType>
                <supportedProjectType>bundle</supportedProjectType>
                <supportedProjectType>war</supportedProjectType>
                  </supportedProjectTypes>
            <instructions>
                <Bundle-SymbolicName>${web.contextPath}</Bundle-SymbolicName>
                <Bundle-ClassPath>
                    .,
                    WEB-INF/classes,
                    WEB-INF/lib/jstl-1-2.jar,
                    WEB-INF/lib/ops4j-base-io-1.4.0.jar,
                    WEB-INF/lib/ops4j-base-lang-1.4.0.jar,
                    WEB-INF/lib/ops4j-base-monitors-1.4.0.jar,
                    WEB-INF/lib/ops4j-base-store-1.4.0.jar,
                    WEB-INF/lib/ops4j-base-util-property-1.4.0.jar,
                    WEB-INF/lib/org.ops4j.pax.tipi.hamcrest.core-1.3.0.1.jar,
                    WEB-INF/lib/standard-1.1.2.jar
                </Bundle-ClassPath>
                <Bundle-Blueprint>WEB-INF/classes/OSGI-INF/blueprint/*.xml</Bundle-Blueprint>
                <Web-ContextPath>${web.contextPath}</Web-ContextPath>
                    <Webapp-Context>${web.contextPath}</Webapp-Context>
                <Export-Package>
                    !org.production.engine.datacombination
                </Export-Package>
                <Import-Package>
                    javax.servlet,
                    javax.servlet.http,
                    javax.servlet.*,
                    javax.servlet.jsp.*,
                    javax.servlet.jsp.jstl.*,
                    !junit.framework,
                    !org.junit,
                    !sun.misc,
                        !org.ops4j.pax.swissbox.*,
                        *
                </Import-Package>
                <DynamicImport-Package>
                    javax.*,
                    org.xml.sax,
                    org.xml.sax.*,
                    org.w3c.*
                </DynamicImport-Package>
            </instructions>
            </configuration>
        </execution>
    </executions>

</plugin>

ただし、Apache Karafで Web アプリケーションを実行するには、機能warをインストールする必要があります。

features:install war

さらに、jre 1.6 はさらにパッケージをエクスポートする必要がありました ( jre.propertiesの抜粋):

jre-1.6= \
     ...
     com.sun.org.apache.xalan.internal.res, \
     com.sun.org.apache.xml.internal.utils, \
     com.sun.org.apache.xpath.internal, \
     com.sun.org.apache.xpath.internal.jaxp, \
     com.sun.org.apache.xpath.internal.objects

以上で、サーブレット コンテナ (Jetty) が実行され、JSP ページが正しくレンダリングされました。

次に、サーブレット内で Web サービス クライアントを使用する方法について説明します。リソース ディレクトリにある WSDL ファイルを使用して、Web サービス クライアントを構築するために必要なすべてのクラスを作成します。これを簡単に行うために、Maven cxf-codegen-pluginは次のクラスを作成します。

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                <encoding>UTF-8</encoding>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>src/main/resources/datacombination_1.wsdl</wsdl>
                        <wsdlLocation>classpath:datacombination_1.wsdl</wsdlLocation>
                        <extraargs>
                            <extraarg>-b</extraarg>
                            <extraarg>${basedir}/src/main/resources/jaxb-binding-date.xml</extraarg>
                            <extraarg>-compile</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

これで、生成された Web サービス クラスをblueprint.xml内の実際の Web サービスに接続し、OSGi サービスとして公開できます。

<jaxws:client id="dms"
        serviceClass="org.production.engine.datacombination.OrderDataMerging"
        address="/engine/datacombination" 
        wsdlLocation="classpath:/datacombination_1.wsdl"
        serviceName="ns1:OrderDataMergingService" 
        endpointName="ns1:OrderDataMergingPort" />  

<service ref="dms" interface="org.production.engine.datacombination.OrderDataMerging" />

サーブレット クラス内で、生成されたサービス クラスをインスタンス化できるようになり、リモート マシンで Web サービスが呼び出されました。

OrderDataMergingService dataMergingService = new OrderDataMergingService();
String orderId = dataMergingService.getOrderDataMergingPort()
                .importOrder(wsRequest);

まだ考えていない唯一の秘密は、なぜその OSGi サービスを公開しなければならないのかということです。OSGi サービス ( blueprint.xmlの ref="dms" ) が見つからない場合、Web サービス クライアントが機能しないためです。

乾杯ヨハネス

于 2013-07-17T10:19:35.743 に答える