本文介绍了CXF日志SOAP输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从服务器记录输出的SOAP消息。 handleMessage方法不会按预期覆盖消息内容。我将如何存储传出的SOAP消息?

I am having trouble logging an outgoing SOAP message from the server. The handleMessage method does not overwrite the message content as expected. How would I store the outgoing SOAP to the message?

public class OutgoingSoapInterceptor extends AbstractPhaseInterceptor<Message> {
    private static final Logger logger = LoggerFactory.getLogger(OutgoingSoapInterceptor.class.getName());

    public OutgoingSoapInterceptor ()
    {
        super(Phase.PRE_STREAM);
    }

    @Override
    public void handleMessage(Message message) throws Fault {
        logger.debug("outbound soap handleMessage");

        OutputStream os = message.getContent ( OutputStream.class );
        CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream ( os);
        message.setContent ( OutputStream.class, cwos );

        cwos.registerCallback ( new LoggingOutCallBack ( ) );
    }
}


推荐答案

有是使用CXF LoggingInInterceptor LoggingOutInterceptor

  LogUtils.setLoggerClass(org.apache.cxf.common.logging.Log4jLogger.class);

  yourService = new YourService(wsdlURL, SERVICE_NAME);
  port = yourService.getServicePort();

  Client client = ClientProxy.getClient(port);
  client.getInInterceptors().add(new LoggingInInterceptor());
  client.getOutInterceptors().add(new LoggingOutInterceptor());

或在< cxf:bus> 带弹簧

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
     http://cxf.apache.org/core
     http://cxf.apache.org/schemas/core.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />

    <cxf:bus>
        <cxf:features>
            <cxf:logging />
        </cxf:features>
    </cxf:bus>

    <jaxws:endpoint ... />
</beans>

查看

这篇关于CXF日志SOAP输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:06