我想修改一个即将发送的SOAP请求,删除信封正文中的两个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);
}
CachedStream
是从哪里来的?我没有看到它的导入并且找不到它。 - javamonkey79message.getInterceptorChain().doIntercept(message)
这一行会使消息内容变成null
。 - shxClient client = ClientProxy.getClient(someServicePort); client.getInInterceptors().add(new MessageChangeInterceptor() { .. });
即可,这样就可以修改原始响应。 - Boris Treukhov