Skip to main content

ws.encoding.soap.DeserializationException : XMLStreamException: ParseError

3 replies [Last post]
flo_bzh
Offline
Joined: 2008-03-06

Hello,

I use JaxB 2.1.3 and JaxWs 2.1.2.
I have a service that return a pdf file in a byte[] tab

When the service client unmarshall the response, this exception is catch :


com.sun.xml.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[6,5]
Message: An invalid XML character (Unicode: 0x2) was found in the element content of the document.]
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:259)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:224)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:117)

[...]

Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[6,5]
Message: An invalid XML character (Unicode: 0x2) was found in t
19:39:26,368 INFO [STDOUT] he element content of the document.]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:422)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
at com.sun.xml.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:120)
at com.sun.xml.bind.api.Bridge.unmarshal(Bridge.java:233)
at com.sun.xml.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:515)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:256)
... 88 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[6,5]
Message: An invalid XML character (Unicode: 0x2) was found in the element content of the document.
at com.sun.xml.stream.XMLReaderImpl.next(XMLReaderImpl.java:571)
at com.sun.xml.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:92)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:225)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:358)
... 92 more
* *

I suppose my byte[] tab (That represent the pdf file) contain invalid encoding caracters and I try a lot of solutions to convert it. For example :

public static String fileToString (String pdfFileLocation) {
String flux = null;

try {
File myFile = new File(pdfFileLocation);
FileInputStream fis = new FileInputStream(myFile);
byte[] bytes = new byte[(int) myFile.length()];
fis.read(bytes);

String fluxO = new String(bytes, "UTF-8");
flux = new String(fluxO.getBytes("UTF-8"), "UTF-8");

fis.close();

} catch (IOException e) {
//...
}
return flux;
}

Is there a way to configure JAX-WS (or JAXB) to have the proper character encoding ? By annotations or by code ?
What is the default JaxB character encoding ?

Thanks for your help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ernestojpg
Offline
Joined: 2005-10-09

As Jitu says, using MTOM would be much more efficient. With MTOM is not necessary to transform data into Base64.

Regards.

jitu
Offline
Joined: 2003-06-14

You should use MTOM for this. See mtom-large, large-upload samples.

flo_bzh
Offline
Joined: 2008-03-06

I finally find my solution.
To transfert binary data to XML I must convert it in base 64.

Here an article that explain it : http://www.javaworld.com/javaworld/javatips/jw-javatip117.html

I use sun.misc.BASE64Encoder and BASE64Dencoder.