Results 1 to 6 of 6

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

  1. #1
    Join Date
    Jan 2011
    Posts
    7

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

    Hi,

    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:

    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());
            }
    whenever I do this I get the following error:
    Code:
    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?

    Regards,
    Craig

  2. #2

  3. #3
    Join Date
    Jan 2011
    Posts
    7

    Default

    Mada,

    I don't see the solution there?

  4. #4

  5. #5
    Join Date
    Jan 2011
    Posts
    7

    Default

    Mada,

    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.

    Craig

  6. #6
    Join Date
    Jan 2011
    Posts
    7

    Default

    Bump... Please help!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •