getTestResource(TestConstants.SOAP_SOAPMESSAGE), null);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream,
OMConstants.DEFAULT_CHAR_SET_ENCODING);
SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
env.serializeAndConsume(writer);
writer.flush();
String outputString = new String(byteArrayOutputStream.toByteArray());
assertTrue(outputString != null && !"".equals(outputString) && outputString.length() > 1);
writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream,
OMConstants.DEFAULT_CHAR_SET_ENCODING);
StringWriter stringWriter = new StringWriter();
//now we should not be able to serilaize anything ! this should throw
//an error
try {
env.serializeAndConsume(writer);
fail();
} catch (UnsupportedOperationException e) {
e.printStackTrace(new PrintWriter(stringWriter, true));
assertTrue(stringWriter.toString()
.indexOf("The parser is already consumed!") > -1);