Daya Ck
Daya Ck

Reputation: 21

Spring Web service SoapMessage.writeTo(OutputStream o)

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

Please find below our 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();

Please any one guide me, Is there any way of getting Soap request and response in String without using OutputStream.

Thanks in advance!!!!

Upvotes: 2

Views: 2200

Answers (1)

Arjen Poutsma
Arjen Poutsma

Reputation: 1256

There is no other way than using a ByteArrayOutputStream. In fact, that is the same technique I use in Spring-WS myself. Though I would recommend using a UTF-8 character encoding:

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    message.writeTo(bos);
    return bos.toString("UTF-8");

I am not sure what you mean with "memory leakage and performance issues", I am not aware that the BAOS has any.

Upvotes: 4

Related Questions