Google App Engine for Java で XPath

Google App Engine for Java の手元のjetty環境ではXPathFactoryからXPathが取得できるが、appspot.comに配備すると、500エラーが発生する。

Error: Server Error
The server encountered an error and could not complete your request.

If the problem persists, please report your problem and mention this error message and the query that caused it.



App Engine の Main の Log を確認すると次のようにあった。

java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFactory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom



XPathFactoryImplがないらしい。App Engineは特殊なJava6だからだろうか。

以下を参考に、

http://groups.google.com/group/google-appengine-java/browse_thread/thread/0af3c97432adbf1f/f794ea995fde16f8?pli=1
http://jx-script.blogspot.com/2009/05/gaejxml.html
http://code.google.com/p/googleappengine/issues/detail?id=1255

xalanj_2_7_1.jarのjarを取り出して、WEB-INF/lib以下に入れる。

 war/WEB-INF/lib/xalan.jar
 war/WEB-INF/lib/xercesImpl.jar
 war/WEB-INF/lib/xml-apis.jar
 war/WEB-INF/lib/xsltc.jar
 war/WEB-INF/lib/serializer.jar

・・・だけではうまくいかなかったので、XPathFactory取得部分を変更。

XPathFactory factory = (XPathFactory) Class.forName("org.apache.xpath.jaxp.XPathFactoryImpl").newInstance();


直接newしてしまうと今度は、jetty環境でSaxParserImplが見えなくなってしまうので仕方なくこのようにした。改善の余地あり。