### Question:
SoapPayloadIO implements IPayloadIO<SOAPEnvelope> { @Override public byte[] marshall(SOAPEnvelope data) throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(data); transformer.transform(source, result); String xml = result.getWriter().toString(); String enc = data.getOwnerDocument().getXmlEncoding(); if (enc == null) { enc = "UTF8"; } return xml.getBytes(enc); } SoapPayloadIO(); SOAPEnvelope parse(InputStream input); SOAPEnvelope parse(byte [] bytes); @Override SOAPEnvelope unmarshall(InputStream input); @Override SOAPEnvelope unmarshall(byte[] input); @Override byte[] marshall(SOAPEnvelope data);  }### Answer:
@Test public void testMarshall_Simple() throws Exception { MessageFactory msgFactory = MessageFactory.newInstance(); SOAPMessage message = msgFactory.createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPHeader header = envelope.getHeader(); SOAPHeaderElement cheader = header.addHeaderElement(new QName("urn:ns1", "CustomHeader")); cheader.setTextContent("CVALUE"); SoapPayloadIO io = new SoapPayloadIO(); byte[] data = io.marshall(envelope); String actual = new String(data); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http: Assert.assertEquals(expected, actual); }