相关疑难解决方法(0)

如何修改出站CXF请求的原始XML消息?

我想修改一个传出的SOAP请求.我想从信封的主体中删除2个xml节点.我设法建立一个Interceptor并将生成的消息集的String值获取到端点.

但是,以下代码似乎不起作用,因为未按预期编辑传出消息.有没有人有关于如何做到这一点的一些代码或想法?

public class MyOutInterceptor extends AbstractSoapInterceptor {

public MyOutInterceptor() {
        super(Phase.SEND); 
}

public void handleMessage(SoapMessage message) throws Fault { 
        // Get message content for dirty editing...
        StringWriter writer = new StringWriter();
        CachedOutputStream cos  = (CachedOutputStream)message.getContent(OutputStream.class); 
        InputStream inputStream = cos.getInputStream();
        IOUtils.copy(inputStream, writer, "UTF-8");
        String content = writer.toString();

        // remove the substrings from envelope...
        content = content.replace("<idJustification>0</idJustification>", "");
        content = content.replace("<indicRdv>false</indicRdv>", "");
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(content.getBytes(Charset.forName("UTF-8")));
        message.setContent(OutputStream.class, outputStream);
} 
Run Code Online (Sandbox Code Playgroud)

java web-services cxf interceptor

17
推荐指数
2
解决办法
3万
查看次数

标签 统计

cxf ×1

interceptor ×1

java ×1

web-services ×1