Announcement Announcement Module
No announcement yet.
MTOM attachment gives 'Content is not allowed in prolog.' Error Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MTOM attachment gives 'Content is not allowed in prolog.' Error


    I'm using Spring-WS 1.5.4 to run a MTOM web service using an axiomSoapMessageFactory (1.2.8). The Web service I am writting takes a XML file as an attachment. JaxB2 provides that attachment as a Javax.xml.transform.Source object. I am trying to copy the source into a file on the system using the following method:

    final Source source = request.getSource();
    StreamSource streamSource = (StreamSource) source;
    TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            File file = new File ("/tempxmlfile.xml");
            transformer.transform(streamSource, new StreamResult(file));
  "File saved in "+file.getAbsolutePath());
    whenever I do this I get the following error:
    Fatal Error :1:1: Content is not allowed in prolog.
    ERROR:  'Content is not allowed in prolog.'
    I've discovered that the problem is with the fact that the Source object, when cast as a StreamSource, has no inputStream only a Reader Object and that Reader has not properly dealt with the fact that the XML file it is reading has a UFT-8 Byte Order Mark (BOM) in the file to identify it's encoding. I know this because if I provide a UFT-8 file with no BOM the web service works fine.

    Is this a known issue, if so has it been fixed?

    If not is it an issue with Spring-WS or something which needs to be fixed in JAXB2?


  • #2
    The solution is here


    • #3

      I don't see the solution there?


      • #4
        Here it is and it is not a spring issue


        • #5

          these posts are explaining the same problem (at least the second one is, I couldn't read the first), but not the solutions.

          I know my files have a UTF-8 BOM as their first 3 bytes. I know I need to strip them off before the XMLParser runs on it but I can't find out how to do that.

          Spring and JAXB2 have kept me so far removed from the actual attachment that I can't get access to it's inputStream to remove those bytes.

          I cannot insist that users strip these bytes off before they post them because this BOM is perfectly valid according to the Unicode specification and several text editors and other frameworks do include these BOM's by default (e.g. notepad and .net).

          Is there a way using Spring to strip the UTF-8 BOM off the attachment?

          I'm using axiom soap message factory.



          • #6
            Bump... Please help!