Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB2 Mtom attachment broken by BOM
    primarykey
    data
    text
    <p>I'm using JAXB2 to to do OXM in a Spring-WS. The XSD I've specified requires a large XML file to be attached to the soap message so I'm using MTOM to transfer the file and have enabled MTOM on my JAXB2Marshaller.</p> <p>When JAXB2 marshalls an MTOM attachment which has an expected mime type of text/xml it delivers that element as a javax.xml.transform.Source object. After some searching I was able to find out how I can send that Source object to a file.</p> <pre><code>final Source source = request.getSource(); StreamSource streamSource = (StreamSource) source; TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); File file = new File ("/tempxmlfile.xml"); try{ transformer.transform(streamSource, new StreamResult(file)); LOG.info("File saved in "+file.getAbsolutePath()); } catch(Exception ex){ ex.getMessage(); } </code></pre> <p>The problem I am having is that when I send a UTF-8 encoded file as the attachment I get the following error:</p> <pre><code>[Fatal Error] :1:1: Content is not allowed in prolog. ERROR: 'Content is not allowed in prolog.' </code></pre> <p>This is being caused by a Byte Order Mark in front of the encoded text in the file, although this BOM is not required in a UTF-8 encoded file it is allowed by the Unicode standard, Java does not support BOMs in UTF-8 encoded streams.</p> <p>I can solve this problem by sending a file without the BOM but this is not really feasible as it will cause problems with most Microsoft products which do insert the BOM.</p> <p>There are lots of workarounds for Sun/Oracle's refusal to fix this issue with the Streams but they all require you to have access to the Stream, the Source Object provided by JAXB2 does not have an InputStream it only has a Reader object. Is there a way for me to solve this problem, either by wrapping the Sources Reader object with a reader which knows how to ignore a BOM in UTF-8 encoding or to change the way JAXB2 reads the attachment into the source so that it can ignore the BOM in UTF-8 encoding.</p> <p>Thanks in advance, Craig </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload