" /> " /> "/>

How to convert soap response to string in java?

2.5k Views Asked by At

I am using WebServiceTemplate to consume SOAP response. For logging purpose i need to get the SOAP response in string. For example , "<envelope><body><name>xyz</name></body></envelope>"

2

There are 2 best solutions below

0
Bhushan Uniyal On BEST ANSWER

You can achive it like below with WebServiceTemplate:

ByteArrayOutputStream  bytArrayOutputStream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bytArrayOutputStream);
wsTemplate.sendSourceAndReceiveToResult(defautUri, source, result); 
final String reply = new String(bytArrayOutputStream.toByteArray())
1
FPratama On

If you using spring, you can add log using log4j in interceptor. Log4j can write to file or even db. I hope its help you.