How to debug marshaling in JAXB?
Asked Answered
J

4

6

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.

Jamieson answered 13/7, 2011 at 14:47 Comment(0)
H
1

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.

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.

Hardtack answered 13/7, 2011 at 15:10 Comment(0)
E
17

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

Edwinaedwine answered 6/3, 2012 at 10:50 Comment(0)
U
2

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).

Unlovely answered 13/7, 2011 at 15:17 Comment(1)
-Djavax.net.debug=all gives a lot of unnecessary garbage.Blus
S
2
JAXBContext context = JAXBContext.newInstance(jaxbObjectClass);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
Sporophyte answered 26/2, 2014 at 12:13 Comment(0)
H
1

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.

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.

Hardtack answered 13/7, 2011 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.