Pax Web Whiteboard サービスを使用して、javax.servlet.Filter
CXF を介して登録された実行中の JaxRS エンドポイントに登録するのに問題があります。フィルターをサービスとして登録し、org.ops4j.pax.web.service.WebContainer を使用してフィルターを直接登録するという、いくつかの異なるアプローチを試しました。
私のテストでは、karaf を起動し、pax-web、webconsole、cxf、および pax-web ホワイトボード サービスをインストールしました。私はブループリントでバンドルを登録しました:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
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/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
">
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<jaxrs:server id="webfiltersample" address="/webfilter">
<jaxrs:serviceBeans>
<ref component-id="serviceBean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<service id="servletFilterService" interface="javax.servlet.Filter">
<service-properties>
<entry key="filter-name" value="BasicWebFilter"/>
<entry key="urlPatterns" value="/*"/>
<entry key="initParams" value=""/>
</service-properties>
<bean class="test.webfilter.BasicWebFilter"/>
</service>
<bean id="serviceBean" class="test.webfilter.WebFilterSample" init-method="init" destroy-method="destroy">
<property name="bundleContext" ref="blueprintBundleContext"/>
</bean>
</blueprint>
ただし、このフィルターは呼び出されません。サーブレット名と urlpatterns の両方を使用して、urlpattern /* を試すまで試しました。次に、少し異なるアプローチを試み、設計図からサービス宣言を削除し、代わりに設計図の init メソッドを使用してフィルタを直接追加しました。
public void init(){
logger.info("Starting Sample");
filter = new WebFilter();
ServiceReference<WebContainer> ref = bundleContext.getServiceReference(BasicWebFilter.class);
WebContainer container = bundleContext.getService(ref);
logger.info("Registering "+ filter + " with "+ container);
container.registerFilter(filter, new String[]{"/cxf/*"}, new String[]{""}, null, null);
bundleContext.ungetService(ref);
}
ログステートメントに反映されているように、メソッドは実際に呼び出されますが、フィルターはまだ実行されていません。
だから私はこれがどのように機能するかについて完全に間違っていますか? 私の「アプリケーション」は、CXF サーブレットに登録された単なるエンドポイントです。この部分は機能しており、そこで定義されている REST サービスを呼び出すことができます。しかし、私が何をしても、フィルターは実行されていません。ここでいくつかのライブラリを使用していますが、よくわかりません (サーブレット/フィルター、Pax-Web、および Writeboard エクステンダー)。これが機能しない理由がわかりませんか? 私の推測では、バンドルごとに異なる httpcontexts があり、別のバンドル (CXF) のフィルターを自分のテスト バンドルに単純に登録することはできません。
これが本当なら、誰かがこの問題に適切に対処する方法を教えてもらえますか? CXF バンドルの bundlecontext を取得して、それにフィルターを登録することはできましたが、これは恐ろしいハックのように思えます。そうでない場合、誰かがなぜこれが機能しないのか教えてもらえますか?