SoapEnvelopeLoggingInterceptor:如何记录客户端远程URL

时间:2014-01-20 18:18:48

标签: java jax-ws spring-ws

我有一个自定义SoapEnvelopeLoggingInterceptor来使用变压器记录ws服务呼叫的soap信封 有没有办法在这个类中记录调用的远程URL? (例如IP地址)
最好是操纵像HttpServletRequest这样的东西。

在上下文中我有:

<sws:interceptors>
    <bean id="envelopeLoggingInterceptor" class="path.to.my.CustomSoapEnvelopeLoggingInterceptor">
        <property name="loggerName" value="myLogger" />
        <property name="logRequest" value="true" />
        <property name="logResponse" value="true" />
        <property name="logFault" value="true" />
    </bean>
</sws:interceptors>

我的CustomSoapEnvelopeLoggingInterceptor

public class CustomSoapEnvelopeLoggingInterceptor extends SoapEnvelopeLoggingInterceptor {
    @Override
    protected void logMessageSource(String message, Source source) throws TransformerException {
        if (source != null){
            Transformer trf = this.getTransformerFactory().newTransformer();
            trf.setOutputProperty(OutputKeys.INDENT, "yes");
            trf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

            StringWriter writer = new StringWriter();
            StreamResult stream = new StreamResult(writer);
            trf.transform(source, stream);
            writer.flush();

            this.logger.debug(message + stream.getWriter().toString());
        }
    }
}

0 个答案:

没有答案