dev@fi.java.net

if SAXDocumentSerializer support CDATA

From: Jia, Quansheng <Quansheng.Jia_at_fnis.com>
Date: Wed, 12 Mar 2008 12:44:13 -0500

Hi;

 

I use below code snip to convert a JAXB bean to a FI string in my
application. I wonder if SAXDocumentSerializer support CDATA. If it
supports, can you provide an example?

 

 

          ByteArrayOutputStream output = new ByteArrayOutputStream();

               SAXResult _result = new SAXResult();

                    SAXDocumentSerializer serializer = new
SAXDocumentSerializer();

                    serializer.setOutputStream(output);

                    _result.setHandler(serializer);

                         _result.setLexicalHandler(serializer);

                    m.marshal(newPayload, _result);

 

 

 

Thanks

 

Quansheng Jia

________________________________

From: Oleksiy.Stashok_at_Sun.COM [mailto:Oleksiy.Stashok_at_Sun.COM]
Sent: Friday, February 29, 2008 4:54 AM
To: dev_at_fi.dev.java.net
Subject: Re: Wierd exception in JAXB deserialization

 

Hello,

 

can you pls. attach byte[] dump, result of serialize method call?

 

Thanks.

 

WBR,

Alexey.

 

On Feb 29, 2008, at 0:03 , Avinash Lakshman wrote:





Could someone please give me some pointers as to where I should start
looking when I attempt tracking this one?

We are reading some bytes from a TCP socket and submitting these bytes
to be deserialized on a separate thread in a dedicated thread pool.
Every once in a while I see this wierd exception.
java.io.IOException: Illegal state for UTF-8 encoded string
at
com.sun.xml.fastinfoset.Decoder.decodeUtf8StringIllegalState(Decoder.jav
a:1780)
at
com.sun.xml.fastinfoset.Decoder.decodeTwoToFourByteUtf8Character(Decoder
.java:1532)
at
com.sun.xml.fastinfoset.Decoder.decodeUtf8StringIntoCharBuffer(Decoder.j
ava:1471)
at
com.sun.xml.fastinfoset.Decoder.decodeUtf8StringAsCharBuffer(Decoder.jav
a:1392)
at
com.sun.xml.fastinfoset.stax.StAXDocumentParser.processUtf8CharacterStri
ng(StAXDocumentParser.java:488)
at
com.sun.xml.fastinfoset.stax.StAXDocumentParser.next(StAXDocumentParser.
java:323)
at
com.sun.xml.bind.v2.runtime.unmarshaller.FastInfosetConnector.bridge(Fas
tInfosetConnector.java:130)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unm
arshallerImpl.java:358)
at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unma
rshallerImpl.java:330)
at
com.firm.infrastructure.net.io.BinarySerializer.deserialize(BinarySerial
izer.java:177)
at
com.firm.infrastructure.net.MessageDeserializationTask.run(MessageDeseri
alizationTask.java:36)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
a:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
va:603)
at java.lang.Thread.run(Thread.java:675)

Here is how I implement the serialization/deserialization:

public byte[] serialize(Object message) throws IOException
    {
        byte[] bytes = new byte[0];
        long startTime = System.currentTimeMillis();
        
        if ( message != null )
        {
            try
            {
                JAXBContext context =
SerializationManager.getContext();
                Marshaller m = context.createMarshaller();

                FastByteArrayOutputStream bos = new
FastByteArrayOutputStream();
                StAXDocumentSerializer sw = new
StAXDocumentSerializer();
                sw.setOutputStream(bos);
                m.marshal(message, (XMLStreamWriter)sw);
                bytes = bos.toByteArray();
            }
            catch ( JAXBException ex )
            {
                SerializationManager.handleJAXBException(ex, message);

            }
        }
        logger_.info("JAXB serialize: " + (System.currentTimeMillis() -
startTime) + " ms.");
        return bytes;
    }

    public Object deserialize(byte[] bytes) throws IOException
    {
        Object message = null;
        long startTime = System.currentTimeMillis();
        try
        {
            JAXBContext context = SerializationManager.getContext();

            Unmarshaller um = context.createUnmarshaller();
            FastByteArrayInputStream bis = new
FastByteArrayInputStream(bytes);
            XMLStreamReader xr = new StAXDocumentParser(bis);

            message = um.unmarshal(xr);
        }
        catch ( JAXBException ex )
        {
            SerializationManager.handleJAXBException(ex);
        }
        logger_.info("JAXB deserialize: " + (System.currentTimeMillis()
- startTime) + " ms.");
        return message;
    }

What would cause this? Please advice.

Thanks
A

________________________________

Connect and share in new ways with Windows Live. Get it now!
<http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_01
2008>

 

______________

The information contained in this message is proprietary and/or confidential. If you are not the
intended recipient, please: (i) delete the message and all copies; (ii) do not disclose,
distribute or use the message in any manner; and (iii) notify the sender immediately. In addition,
please be aware that any message addressed to our domain is subject to archiving and review by
persons other than the intended recipient. Thank you.
_____________