1

環境で:

  • カラフ 3.0.1
  • 春 3.2.4
  • ヘシアン 4.0.33

既に CXF を介してサービスを公開しており、現在、同じサービスを Hessian Service として公開しようとしています。

war や web.xml はなく、プレーン Bean + pax-http だけで、次のことを試しました。

<bean name="/hessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
    <property name="service" ref="promocionalOnLineWebServiceBean"/>
    <property name="serviceInterface" value="org.fideliapos.promos.webservice.PromocionalOnLineFacade"/>
</bean> 
...
<bean id="hessianServlet" class="org.springframework.web.context.support.HttpRequestHandlerServlet"/>
...
<osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet">
    <service-properties>
        <entry key="alias" value="/hessian"/>
    </service-properties>         
</osgi:service>

アイデアは、ターゲットが HessianServiceExporter であるサーブレット (HttpRequestHandlerServlet) を登録することですが、WebApplicationContext が見つかりません: ContextLoaderListener が登録されていませんか? .

スプリング コードをトレースしたところ、内部の突堤がサーブレットを認識し、その init メソッドを呼び出しています。

@Override
public void init() throws ServletException {
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
    this.target = wac.getBean(getServletName(), HttpRequestHandler.class);
}

スプリング WebApplicationContext がなく、ターゲット プロパティを inyected できないため、ここに問題があります。

何か不足していますか?または、このように機能させることはできません。

回避策として、サーブレットを独自の実装 (setTarget など) で拡張することを検討していますが、それはしたくありません。


アップデート

独自の HttpContext を作成して追加しようとした後、まだ何かが欠けています:

独自の HttpContext を実装しました。

public class HessianContext implements HttpContext{
...
}

豆を追加しました

<bean id="hessianContext" class="org.fideliapos.promos.hessian.HessianContext"/>

サービス:

<osgi:service id="hessianContextService" ref="hessianContext" interface="org.osgi.service.http.HttpContext">
    <service-properties>
        <entry key="httpContext.id" value="hessian"/> <!-- also tried with contextId-->
    </service-properties>
</osgi:service>     

最後にサービスとしてのサーブレット:

<osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet">
    <service-properties>
        <entry key="alias" value="/hessian"/>
        <entry key="httpContext.id" value="hessian"/> <!-- also tried with contextId-->      
    </service-properties>         
</osgi:service>

init メソッドは WebApplicationContext を探しているので、GenericWebApplicationContext Bean を宣言して明示する必要があるように見えますが、この Bean を OSGi に必要な HttpContext に「結合」する方法がわかりません。

4

1 に答える 1