【发布时间】:2015-09-18 07:38:45
【问题描述】:
我写了从java字符串生成soap消息的方法:
private SOAPMessage createRequest(String msg) {
SOAPMessage request = null;
try {
MessageFactory msgFactory = MessageFactory.newInstance();
request = factory.createMessage();
SOAPPart msgPart = request.getSOAPPart();
SOAPEnvelope envelope = msgPart.getEnvelope();
SOAPBody body = envelope.getBody();
StreamSource _msg = new StreamSource(new StringReader(msg));
msgPart.setContent(_msg);
request.saveChanges();
} catch(Exception ex) {
ex.printStackTrace();
}
}
然后,我尝试生成一些消息。例如:
createRequest("test message");
但是在这里 - request.saveChanges(); 我发现了这个异常:
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
我的错误在哪里?
【问题讨论】:
-
你没有阅读整个异常堆栈,最重要的部分应该是 org.xml.sax.SAXParseException;行号:1;列号:1; prolog 中不允许内容,这意味着您的 msg 首先应该是有效的 XML。