我正在使用 Metro 调用 SOAP Web 服务。我从无法控制的服务器接收到正文中包含无效字符引用的 SOAP 响应。我想在 Metro 解组 XML 并向我的客户端抛出异常之前修复它。这可能吗?
我尝试添加 aLogicalHandler
和 aSOAPHandler
但是当我尝试获取有效负载时它们都抛出相同的解组异常(分别失败LogicalMessage.getPayload()
)SOAPMessageContext.getMessage()
。当响应没有无效的 XML 时,处理程序工作正常,让我可以访问消息。
这是异常的样子:
com.sun.xml.internal.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:421)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:357)
at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:109)
at com.sun.xml.internal.bind.api.Bridge.unmarshal(Bridge.java:222)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:539)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
... 41 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:81)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:182)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:355)
有没有办法我可以获得原始有效载荷,修复它并替换它并继续?