java 如何在 JAXB 中调试封送处理?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6680804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug marshaling in JAXB?
提问by user590444
During marshaling I got next exception
在编组期间,我遇到了下一个异常
Exception in thread "main" 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]:[1,1127]
Message: XML document structures must start and end within the same entity.]
so I want see xml where [row,col]:[1,1127] is located. Please suggest.
所以我想查看 [row,col]:[1,1127] 所在的 xml。请建议。
采纳答案by AlexR
I'd suggest you to create exception breakpoint on XMLStreamException. At least eclipse allows this. So you will be able to see the point where the exception is thrown. probably it will help.
我建议您在 XMLStreamException 上创建异常断点。至少 eclipse 允许这样做。因此,您将能够看到抛出异常的点。可能会有所帮助。
BTW I am not sure that 1, 1127 is completely wrong. First check (just in case) that you do not have something illegal in this position. Second, check that it is not the 1127'th character of your file. If for example the file was generated on Unix where line separator is \n but you run code on Windows where line separator is \r\n the system probably does not recognize the line breaks, so it thinks that your XML is formatted as a very long single line.
顺便说一句,我不确定 1, 1127 是完全错误的。首先检查(以防万一)你在这个职位上没有非法的东西。其次,检查它是否不是文件的第 1127 个字符。例如,如果文件是在行分隔符为 \n 的 Unix 上生成的,但您在行分隔符为 \r\n 的 Windows 上运行代码,则系统可能无法识别换行符,因此它认为您的 XML 被格式化为非常长单行。
回答by Werner Altewischer
You can see JAXB debug output in the console by specifying -Djaxb.debug=true in the JVM options. Additionally you may want to set an event handler on the unmarshaller: unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
您可以通过在 JVM 选项中指定 -Djaxb.debug=true 在控制台中查看 JAXB 调试输出。此外,您可能希望在解组器上设置一个事件处理程序: unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
回答by Oversteer
JAXBContext context = JAXBContext.newInstance(jaxbObjectClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
回答by jkeeler
It appears you're deserializing a SOAP message. You can enable HTTP debugging by adding -Djavax.net.debug=all
to your JVM options. That'll dump the incoming message. Once you can see your input, make sure the start and end tags match (as per the second part of the error message).
看来您正在反序列化 SOAP 消息。您可以通过添加-Djavax.net.debug=all
到 JVM 选项来启用 HTTP 调试。这将转储传入的消息。一旦您可以看到您的输入,请确保开始和结束标记匹配(根据错误消息的第二部分)。