2

我有一大段这样的代码:

AxiomSoapMessage message = (AxiomSoapMessage)webServiceMessage; 

SoapHeader soapHeader = message.getSoapHeader();
SOAPMessage soapMessage = message.getAxiomMessage();
    
TransportContext transContext = TransportContextHolder.getTransportContext();

HttpServletConnection connection = (HttpServletConnection)transContext.getConnection();
HttpServletRequest httpRequest = connection.getHttpServletRequest();
    
InputStream inputStream = httpRequest.getInputStream();

SniffedXmlInputStream sniffedXmlInputStream = new SniffedXmlInputStream(inputStream);

String encoding = sniffedXmlInputStream.getXmlEncoding();
sniffedXmlInputStream.close();
    
String soapVersion = message.getVersion().toString();       
    
ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
**soapMessage.serialize(baos);** //THIS LINE

这是接收 Spring ws 的WebServiceMessage的类的一部分,我从中提取SOAPMessage,如上所示。

在上面代码中用“THIS LINE”标记的粗体行,我“有时”得到以下异常

 org.springframework.integration.MessageHandlingException: 
    org.apache.axiom.om.OMException: 
       javax.xml.stream.XMLStreamException: 
          ParseError at [row,col]:[1,4090] Message: Stream closed

有什么解决办法吗?

4

1 回答 1

0

由于无效的 XML,可能会发生 javax.xml.stream.XMLStreamException。打印 XML 并查看它是否根据 DTD 或 XSD 进行验证。

于 2012-12-26T04:39:05.787 回答