Convert StreamResult to string or xml

前端 未结 4 1604
滥情空心
滥情空心 2021-02-02 08:18

Using spring ws to get the StreamResult as below

StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System         


        
4条回答
  •  面向向阳花
    2021-02-02 08:56

    If none of these works, try this

    System.out.println(result.getOutputStream().toString());
    

    Assuming you have this kind of structure ,

    private static StreamResult printSOAPResponse(SOAPMessage soapResponse) throws Exception {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        Source sourceContent = soapResponse.getSOAPPart().getContent();
        System.out.print("\nResponse SOAP Message = ");
        StreamResult result = new StreamResult(System.out);
        transformer.transform(sourceContent, result);
        return result;
    }
    

    You can try this way , although the same thing, wanted to point it out clearly

    System.out.println(printSOAPResponse(soapResponse).getOutputStream().toString());
    

提交回复
热议问题