matsukaz's blog

Agile, node.js, ruby, AWS, cocos2d-xなどなどいろいろやってます

Spring Web Services まとめ その6

EndpointInterceptorインタフェース (Chapter5)

その5で説明したエンドポイントマッピングには、エンドポイントインターセプターを適用することができる。エンドポイントインターセプターを利用することで、セキュリティ情報を扱うSOAPヘッダの解釈や入出力メッセージのロギングなど、何らかの処理をエンドポイントマッピングに埋め込むことができる。
エンドポイントインターセプターを利用するためには、EndpointInterceptorインタフェースを実装する必要がある。Spring-WSにあらかじめ用意されているEndpointInterceptorインタフェースの実装クラスは、以下の通りである。

クラス名 用途
PayloadLoggignInterceptor 入出力メッセージのログ出力
PayloadTransformingInterceptor XSLTを利用してペイロードの内容を変換する
PayloadValidatingInterceptor XML SchemaまたはRelaxNGを利用してペイロードの内容をバリデーションする
SoapEnvelopeLoggingInterceptor SOAPメッセージのログ出力
XwsSecurityInterceptor SunのXML and Web Services Security package(XWSS)をベースとしたWS-Security用のインターセプター。詳細はChapter7参照

以下は、エンドポイントインターセプターの適用例である。

  • PayloadLoggignInterceptorとSoapEnvelopeLoggingInterceptor
<beans>
    <bean id="endpointMapping"
        class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
        <property name="interceptors">
            <list>
                <ref bean="loggingInterceptor"/>
            </list>
        </property>
        <property name="mappings">
            <props>
                <prop key="{http://samples}orderRequest">getOrderEndpoint</prop>
                <prop key="{http://samples}order">createOrderEndpoint</prop>
            </props>
        </property>
    </bean>

    <bean id="loggingInterceptor"
    class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
</beans>

ペイロードの内容がCommons Loggingのログに出力される。SoapEnvelopeLoggingInterceptorを利用した場合は、SOAPメッセージが同様にログ出力される。

  • PayloadValidatingInterceptor
<bean id="validatingInterceptor"
        class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    <property name="schema" value="/WEB-INF/orders.xsd"/>
    <property name="validateRequest" value="false"/>
    <property name="validateResponse" value="true"/>
</bean>

出力メッセージの内容がバリデーションされる。

  • PayloadTransformingInterceptor
<bean id="transformingInterceptor"
        class="org.springframework.ws.server.endpoint.interceptor.PayloadTransformingInterceptor">
    <property name="requestXslt" value="/WEB-INF/oldRequests.xslt"/>
    <property name="requestXslt" value="/WEB-INF/oldResponses.xslt"/>
</bean>

指定したXSLTファイルを元に、ペイロードの内容が変換される。