title: Spring Web service SoapMessage.writeTo(OutputStream o)
body: <p>We are trying to convert SoapMessage to String value, In our code, we are writing the SoapMessage to ByteArrayOutputStream. But with ByteArrayOutputStream, there is lot of issues like memory leakage issue and performance issues</p>
  
  <p>Please find below our code:</p>
  
  <pre><code>MessageContext messageContext;
  SoapMessage requestSoapMessage = (SoapMessage)messageContext.getRequest();
  SoapMessage responseSoapMessage = (SoapMessage)messageContext.getResponse();
  
  //Getting request
  ByteArrayOutputStream baos_req = new ByteArrayOutputStream();
  requestSoapMessage.WriteTo(baos_req);
  String soapReqMsg = baos_req.toString();
  
  //Getting response
  ByteArrayOutputStream baos_resp = new ByteArrayOutputStream();
  responseSoapMessage.WriteTo(baos_resp);
  String soapRespMsg = baos_resp.toString();
  </code></pre>
  
  <p>Please any one guide me,
  Is there any way of getting Soap request and response in String without using OutputStream.</p>
  
  <p>Thanks in advance!!!!</p>