ご連絡をお待ちしております。その間、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 サービス クライアントが機能しないためです。
乾杯ヨハネス