Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 套接字异常:使用JAXB解组时重置连接_Java_Xml_Serialization_Deserialization_Unmarshalling - Fatal编程技术网

Java 套接字异常:使用JAXB解组时重置连接

Java 套接字异常:使用JAXB解组时重置连接,java,xml,serialization,deserialization,unmarshalling,Java,Xml,Serialization,Deserialization,Unmarshalling,我能够使用FileInputStream将xml文件解组到一个类来读取xml内容,并且在解组代码中使用InputStream而不是FileInputStream时遇到问题 元帅: try { JAXBContext jaxbContext = JAXBContext.newInstance(Message.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); JAXBElement

我能够使用FileInputStream将xml文件解组到一个类来读取xml内容,并且在解组代码中使用InputStream而不是FileInputStream时遇到问题

元帅:

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();
}

试试这样的

使用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);

“连接重置”与XML、JAXB、解组等无关。它通常是由写入已被对等方关闭的连接引起的。换句话说,应用程序协议错误

javax.xml.bind.UnmarshalException
 - with linked exception:
[java.net.SocketException: Connection reset]
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);