【问题标题】:Sometime I get Stream Closed sometimes i don't. Why do i get this?有时我会关闭流,有时我不会。为什么我会得到这个?
【发布时间】:2012-12-26 04:21:55
【问题描述】:

我有一大段这样的代码:

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

有什么解决办法吗?

【问题讨论】:

    标签: java spring spring-ws


    【解决方案1】:

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

    【讨论】:

    • 我也试过了,但是xml是有效的。还有什么建议吗?早些时候,我没有使用 ByteArrayOutputStream,而是使用 Apache 的 XmlStreamWriter,当时一切都很好,但现在我偶尔会遇到这个异常。
    • 我将代码更改为使用 SaajSoapMessage 而不是 AxiomSoapMessage 并且它正在工作。我不知道为什么,但我很高兴知道。有没有cmets?
    • SAAJ 代表 Soap with Attachments API for Java。你的 XML 有附件吗?
    • 我知道 SAAJ 代表什么。是的,它包含内联附件。无论如何,它已经完成了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多