SOAPMessageUtil { public SOAPMessage wrapRequest(Object request, MessageFactory messageFactory){ try { SOAPMessage requestMessage = messageFactory.createMessage(); Marshaller marshaller = jaxbContext.createMarshaller(); DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document document = db.newDocument(); marshaller.marshal(request, document); org.w3c.dom.Node importedNode = requestMessage.getSOAPBody().getOwnerDocument().importNode(document.getChildNodes().item(0), true); requestMessage.getSOAPBody().appendChild(importedNode); requestMessage.saveChanges(); return requestMessage; } catch (SOAPException | ParserConfigurationException | JAXBException e) { throw new RuntimeException(e); } } SOAPMessageUtil(JAXBContext jaxbContext); Object parseRequest(SOAPMessage soapMessage); Object parseFault(SOAPFault soapFault); SOAPMessage wrapRequest(Object request, MessageFactory messageFactory); SOAPMessage wrapResponse(Object response, MessageFactory messageFactory); SOAPMessage wrapFault(JAXBElement fault, String faultString, MessageFactory messageFactory, boolean soap12);  }
@Test public void parseMessage() throws RuntimeException, SOAPException { SOAPMessageUtil soapMessageUtil = new SOAPMessageUtil(JAXBSoapUtil.getJAXBContextForWebService(HelloWorld.class)); SOAPMessage soapMessage = soapMessageUtil.wrapRequest(new SoapDummyRequest(), MessageFactory.newInstance()); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { soapMessage.writeTo(out); String strMsg = new String(out.toByteArray()); System.out.println(strMsg); } catch (SOAPException | IOException e) { throw new RuntimeException(e); } }