How To Modify The Raw XML message of an Outbound CXF Request?

前端 未结 6 653
滥情空心
滥情空心 2020-11-27 17:07

I would like to modify an outgoing SOAP Request. I would like to remove 2 xml nodes from the Envelope\'s body. I managed to set up an Interceptor and get the generated Stri

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 17:44

    I had this problem as well today. After much weeping and gnashing of teeth, I was able to alter the StreamInterceptor class in the configuration_interceptor demo that comes with the CXF source:

    OutputStream os = message.getContent(OutputStream.class);
    CachedStream cs = new CachedStream();
    message.setContent(OutputStream.class, cs);
    
    message.getInterceptorChain().doIntercept(message);
    
    try {
        cs.flush();
        CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class);
    
        String soapMessage = IOUtils.toString(csnew.getInputStream());
        ...
    

    The soapMessage variable will contain the complete SOAP message. You should be able to manipulate the soap message, flush it to an output stream and do a message.setContent(OutputStream.class... call to put your modifications on the message. This comes with no warranty, since I'm pretty new to CXF myself!

    Note: CachedStream is a private class in the StreamInterceptor class. Don't forget to configure your interceptor to run in the PRE_STREAM phase so that the SOAP interceptors have a chance to write the SOAP message.

提交回复
热议问题