Search code examples
javaspring-bootsoap-clientwebservicetemplate

How to convert soap response to string in java?


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>"


Solution

  • 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())