2012-09-06 58 views
1

我们的一个Web应用程序长期在我们的生产环境中运行,最近它在发生大量事务时发生奇怪的错误。我们无法弄清楚究竟是什么问题的根源,但是我们在前一版本中发现了一些类似的问题,WebSphere 6与应用服务器使用的Xalan版本中的错误有关。我们的应用服务器实际上是WebSphere 7,它应该已经修复了,除此之外它不再使用Xalan。我们的应用程序也没有嵌入Xalan jar。 要修复它,我们只需重新启动应用程序本身。 一个重要的注意事项是正在缓存文档(docs.get(tableName))并重新用于执行XPath评估。我们这样做是为了避免每次解析文档的成本。XPath中的未知错误

的应用程序代码是

 Document doc = null; 
     try { 
      doc = docs.get(tableName); 

      if (doc == null) 
       return null; 

      XPathFactory xFactory = XPathFactory.newInstance(); 
      XPath xpath = xFactory.newXPath(); 
      XPathExpression expr = xpath.compile(toUpper(xPathQuery)); 
      Object result = expr.evaluate(doc, XPathConstants.NODESET); 

      return (NodeList) result; 
     } catch (XPathExpressionException e) { 
      logger.error("Error executing XPath", e); 
     } 

和错误堆在这里

javax.xml.transform.TransformerException: Unknown error in XPath. 
at java.lang.Throwable.<init>(Throwable.java:67) 
at javax.xml.transform.TransformerException.<init>(Unknown Source) 
at org.apache.xpath.XPath.execute(Unknown Source) 
at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(Unknown Source) 
Caused by: java.lang.NullPointerException 
at org.apache.xerces.dom.ElementNSImpl.getPrefix(Unknown Source) 
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.processNamespacesAndAttributes(Unknown Source) 
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(Unknown Source) 
at org.apache.xml.dtm.ref.DTMDefaultBase._nextsib(Unknown Source) 
at org.apache.xml.dtm.ref.DTMDefaultBase.getNextSibling(Unknown Source) 
at org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$ChildTraverser.next(Unknown Source) 
at org.apache.xpath.axes.AxesWalker.getNextNode(Unknown Source) 
at org.apache.xpath.axes.AxesWalker.nextNode(Unknown Source) 
at org.apache.xpath.axes.WalkingIterator.nextNode(Unknown Source) 
at org.apache.xpath.axes.NodeSequence.nextNode(Unknown Source) 
at org.apache.xpath.axes.NodeSequence.runTo(Unknown Source) 
at org.apache.xpath.axes.NodeSequence.setRoot(Unknown Source) 
at org.apache.xpath.axes.LocPathIterator.execute(Unknown Source) 
... 16 more 

这是类似的问题,我提到。 http://www-01.ibm.com/support/docview.wss?uid=swg1PK42574

Thakns。

+0

'xPathQuery'的价值是什么? –

回答

1

许多人没有意识到DOM不是线程安全的(即使你只是在读取)。如果您正在缓存DOM对象,请确保您同步对其的所有访问。

坦率地说,这使得DOM不适合这种应用。我知道我有偏见,但我会建议转向撒克逊,撒克逊的原生树实现不仅比DOM更快,而且也是线程安全的。一位用户最近在发布此转换时发布了关于获得100倍性能改进的推文。

+0

我已经考虑过这种可能性,它不是线程安全的。现在我知道了,在我们看看撒克逊时,我正在进行同步。 同步(doc){ result = expr.evaluate(doc,XPathConstants.NODESET); } – user1650564