[英]Socket exception: Connection reset when unmarshalling with JAXB
I was able to unmarshal from xml file to a class using FileInputStream to read the xml content, and I'm having a problem using InputStream instead of FileInputStream in the unmarshaling code. 我能够使用FileInputStream从xml文件解编为一个类以读取xml内容,并且在解编组代码中使用InputStream而不是FileInputStream遇到了问题。
marshal: 元帅:
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Message.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
JAXBElement<Message> je =
new JAXBElement<Message> (new QName(Message.class.getSimpleName()), Message.class, message);
jaxbMarshaller.marshal(je, os);
} catch (JAXBException e) {
e.printStackTrace();
}
Unmarshal: 解组
JAXBContext jc = null;
try {
jc = JAXBContext.newInstance(Message.class);
Unmarshaller um = jc.createUnmarshaller();
JAXBElement<Message> je = (JAXBElement<Message>) um.unmarshal(new StreamSource(is), Message.class);
message = je.getValue();
} catch (JAXBException | FileNotFoundException e) {
e.printStackTrace();
}
The error I'm getting: 我得到的错误:
javax.xml.bind.UnmarshalException
- with linked exception:
[java.net.SocketException: Connection reset]
Try something like this. 尝试这样的事情。
Use JAXBIntrospector to get the value. 使用JAXBIntrospector来获取值。
String filepath="C:\\somepath";
FileInputStream xml = new FileInputStream(filepath);
Object result = unmarshaller.unmarshaller.unmarshal(xml);
Message msg = (Message) JAXBIntrospector.getValue(result);
StreamSource xml = new StreamSource(filepath);
JAXBElement<Message> msgclass =
unmarshaller.unmarshal(xml, Message.class);
'Connection reset' has nothing to do with XML, JAXB, unmarshalling, etc. It is usually caused by writing to a connection that had already been closed by the peer. “连接重置”与XML,JAXB,解组等无关。通常是由于写入已被对等方关闭的连接而引起的。 In other words, an application protocol error.
换句话说,应用程序协议错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.