javaxmlsocketsjaxbmsxml4

What is this "socket heading" (bytes,chars) before receiving the actual xml from an msxml service?


I'm using java jaxb to unmarshal xml request via socket, before the actual xml

<?xml version="1.0"....

I receive these bytes

00 00 01 F9 EF BB BF

What are they?, size of the xml?, session id?...

The sender is using msxml4 to execute request's to my service.

Futhermore, I can see that the sender expect this type of header (it trunks the first 7 bytes if I send directly the xml response).

So when I have understood what these bytes are, is there any "normal" any method using jaxb that can be used to add this header or do I need to do it manually.

Thanks for any reply


Solution

  • This is a BOM header.

    The first 4 bytes indicate file size 00 00 01 F9 = 0 + 0 + 256 + 249 = 505 (including the 3 bytes indicating UTF-8 (EF BB BF). Hence the xml length will be 502.

    How to handle this stream with Jaxb view:

    Byte order mark screws up file reading in Java

    why org.apache.xerces.parsers.SAXParser does not skip BOM in utf8 encoded xml?

    JAXB unmarshaller BOM handlle

    However, I have prefeered to handle the stream byte by byte reading it into a StringBuffer (since I need it also in string format for logging)

    My reading byte to byte solution is implemented to wait for the '<' char, hence first char in xml message.

    To add the BOM heading before sending response I have used a similar method:

    import java.nio.ByteBuffer;
    public byte[] getBOMMessage(int xmlLenght) {
        byte[] arr = new byte[7];
        ByteBuffer buf = ByteBuffer.wrap(arr);
        buf.putInt(xmlLenght+3);
        arr[4]=(byte)0xef;
        arr[5]=(byte)0xbb;
        arr[6]=(byte)0xbf;
        return arr;
    }