Here you can find the source of writeAndRead(SOAPMessage soapMessage)
private static SOAPMessage writeAndRead(SOAPMessage soapMessage) throws SOAPException, IOException
//package com.java2s; /*/* w w w . j av a 2s . co m*/ * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. * * This is free software; you can redistribute it and/or modify it * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as * published by JBoss Inc.; either version 1.0 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; public class Main { private static SOAPMessage writeAndRead(SOAPMessage soapMessage) throws SOAPException, IOException { // write to memory sink ByteArrayOutputStream soapSink = new ByteArrayOutputStream(); soapMessage.writeTo(soapSink); soapSink.writeTo(System.out); System.out.println(); // read from memory source return MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(soapSink.toByteArray())); } }