Convert StreamResult to string or xml

前端 未结 4 1605
滥情空心
滥情空心 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:44

    If you use Spring you could also use this way:

        import org.springframework.core.io.Resource;
        import org.apache.commons.io.IOUtils;
        ....    
        @Value("classpath:/files/dummyresponse.xml")
        private Resource dummyResponseFile;
        ....
        public String getDummyResponse() {
            try {
                if (this.dummyResponse == null)
                    dummyResponse = IOUtils.toString(dummyResponseFile.getInputStream(),StandardCharsets.UTF_8);
            }  catch (IOException e) {
                logger.error("Fehler in Test-Service: {}, {}, {}", e.getMessage(), e.getCause(), e.getStackTrace());
                throw new RuntimeException(e);
            }
            return dummyResponse;
        }
    

提交回复
热议问题