我想修改一個傳出的SOAP請求。 我想從信封的正文中刪除2個xml節點。 我設法設置了一個攔截器,並將消息集的生成的字符串值獲取到端點。如何修改出站CXF請求的原始XML消息?
但是,下面的代碼似乎不起作用,因爲傳出消息未按預期編輯。有沒有人有一些關於如何做到這一點的代碼或想法?
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);
}
感謝您的輸入約翰。與此問題相關的其他元素可以在這裏找到:http://stackoverflow.com/questions/6906499/how-to-modify-the-generated-soap-request – kiwifrog