format.setSOAP11(msgContext.isSOAP11());
format.setCharSetEncoding(
getProperty(msgContext, Constants.Configuration.CHARACTER_SET_ENCODING));
format.setDoOptimize(msgContext.isDoingMTOM());
try {
msgElement.serializeAndConsume(baos, format);
baos.flush();
} catch (XMLStreamException e) {
handleException("XML serialization error creating BytesMessage", e);
} catch (IOException e) {
handleException("IO Error while creating BytesMessage", e);