我的Web服务上出现了太多打开文件错误,只是想确保没有其他需要关闭的内容。我在close()
(outWriter
)上添加了StringWriter
,但是JavaDoc表示这没有效果。 getCachedExtractSoapBodyXslt()
获取javax.xml.transform.Transformer
对象。
String payload;
StreamResult result=null;
StringWriter outWriter=null;
try {
// Programmatically extract the SOAP Body from message
outWriter = new StringWriter();
result = new StreamResult(outWriter);
Source src = new StreamSource(new java.io.StringReader(doc));
getCachedExtractSoapBodyXslt().transform(src, result);
StringBuffer sb = outWriter.getBuffer();
payload = sb.toString();
} catch (TransformerException e) {
throw new ComponentException("Unable to extract SOAP Body");
}
finally {
LOG.debug("Closing XSLT transformer output stream");
try {
outWriter.close();
}
catch (IOException e) {
LOG.error("Failed to close stream for SOAP message");
}
}
最佳答案
我不得不将其移动到它自己的变量并关闭它
new java.io.StringReader(doc)