サービスのデプロイ

AxisConfiguraion が取得できるところを見落としてました。いやはや、お恥ずかしい。
ServletContext に ConfigurationContext が格納されるようなので、そこから AxisConfiguraion が取得できるようですね。

ということで、早速サービスのデプロイを試してみました。


まずは、dicon で定義したコンポーネントをWebサービスに登録する AxisDeployer(S2Axis2版)を作成。

public class AxisDeployer
{
    protected S2Container          container;
    protected AxisConfiguration    axisConfig;

    public AxisDeployer()
    {}

    public void deploy()
    {
        if (this.axisConfig != null)
        {
            forEach(container.getRoot());
        }
    }
    
    protected void forEach(final S2Container container)
    {
        final int componentDefSize = container.getComponentDefSize();
        for (int i = 0; i < componentDefSize; ++i) {
            process(container.getComponentDef(i));
        }

        final int childContainerSize = container.getChildSize();
        for (int i = 0; i < childContainerSize; ++i) {
            forEach(container.getChild(i));
        }
    }

    protected void process(final ComponentDef componentDef)
    {
        final MetaDef serviceMetaDef = getMetaDef(componentDef, "service");
        if (serviceMetaDef != null)
        {
            serviceDeploy(componentDef, serviceMetaDef);
        }
    }
    
    private void serviceDeploy(ComponentDef componentDef, MetaDef metaDef)
    {
        try
        {
            String className = componentDef.getComponentClass().getName();
            Parameter parameter = new Parameter(Constants.SERVICE_CLASS, className);
            AxisService service = new AxisService(componentDef.getComponentName());
            service.addParameter(parameter);
            service.setClassLoader(Thread.currentThread()
                    .getContextClassLoader());

            Utils.fillAxisService(service, this.axisConfig);

            this.axisConfig.addService(service);
        }
        catch (AxisFault e)
        {
            e.printStackTrace();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    // S2Axis と同じメソッドは省略。

    public void setServletContext(final ServletContext servletContext)
    {
        ConfigurationContext configContext = (ConfigurationContext) servletContext
                .getAttribute("CONFIGURATION_CONTEXT");
        this.axisConfig = configContext.getAxisConfiguration();
    }

}

続いて、S2Axis の「ex01 コンポーネントをWebサービスとして公開する」のサンプルを登録してみる。
S2AxisExamples 1.0.1 で、中身のjarファイルをAxis2のものに入れ替えて、サンプルプロジェクトを作成。

既存のサンプルをそのまま利用して、次のURLにアクセスしてみます。
diconでcomponentタグのname属性に "Echo" と指定しているので、サービス名がEchoとなっています。

http://localhost:8080/s2axis2-example/services/Echo?wsdl


すると・・・



成功です!! WSDLの表示ができました。


AxisServiceクラスの作成方法などは、まだ理解不足な点があるので、各プロパティの意味をちょっと調べる必要がありそうですね。
でも、まずは一歩前進。