我们将数据作为XML,并且有多种格式化的XSL样式。它在IE中工作得很好。
然后,我们需要在Chrome中显示与HTML相同的内容。因此,我们在服务器端(Java)找到了一个API,用于将XML + XSL转换为HTML。
public static String convertXMLXSL(String xml, String xsl) throws SQLException {
System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
TransformerFactory tFactory = TransformerFactory.newInstance();
String html = "";
try {
try {
StreamResult result = new StreamResult(new StringWriter());
**Transformer trans = tFactory.newTransformer(new StreamSource(new ByteArrayInputStream(xsl.getBytes("utf-8"))));
trans.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))), result);**
html = result.getWriter().toString();
} catch (TransformerException te) {
te.printStackTrace();
}
} catch (Exception e) {
AppendExceptionToLog(e);
}
return html;
}
但是,过了一段时间之后,我们看到一些线程转储在 javax.xml.transform.Transformer
的 trasform 方法中被阻止 Sep 12, 2017 12:07:49 PM org.apache.catalina.valves.StuckThreadDetectionValve notifyStuckThreadDetected
WARNING: Thread "http-8080-12" (id=15800) has been active for 6,516 milliseconds (since 9/12/17 12:07 PM) to serve the same request for
and may be stuck (configured threshold for this StuckThreadDetectionValve is 5 seconds).
There is/are 3 thread(s) in total that are monitored by this Valve and may be stuck.
java.lang.Throwable
at org.apache.xpath.axes.AxesWalker.getNextNode(AxesWalker.java:333)
at org.apache.xpath.axes.AxesWalker.nextNode(AxesWalker.java:361)
at org.apache.xpath.axes.WalkingIterator.nextNode(WalkingIterator.java:192)
at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:281)
at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:435)
at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:218)
at org.apache.xpath.axes.LocPathIterator.execute(LocPathIterator.java:210)
at org.apache.xpath.XPath.execute(XPath.java:335)
at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:278)
at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:246)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at Util.processXMLXSL(Util.java:3364)
在这里,我想知道..
1)我们是否有任何其他已知的实现在服务器端执行相同的操作?
2)我是否应该考虑使用Mozilla的 XSLTProcessor 来使用客户端方法?