XSL Transformation, AccessControlException, NoClassDefFoundError and SyntheticRepository

161 views
Skip to first unread message

Jan

unread,
Jul 21, 2010, 8:42:03 AM7/21/10
to Google Web Toolkit
Hi,

I would like to use an xsl transformation inside an HttpServlet. The
code is essentially the following:

File xslfile = new File("test.xsl");
TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute( "debug", true );
Transformer transformer = factory.newTransformer(new
StreamSource( xslfile ) );

I already made sure that the xsl file is valid and I defined it as
resource-file inside appengine-web.xml

If I now call the servlet the first time, the following error occurs:

java.lang.ExceptionInInitializerError
at
com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
109)
at
com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
228)
at
com.sun.org.apache.bcel.internal.generic.ClassGen.getJavaClass(ClassGen.java:
174)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:
735)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
354)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
429)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:
795)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:
617)
at com.axag.invoiceedit.server.<MY SERVLET>.doGet(<MY SERVLET>:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.security.AccessControlException: access denied
(java.io.FilePermission <PATH TO MY PROJECT'S SRC DIRECTORY> read)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:
323)
at
java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:
532)
at com.google.appengine.tools.development.DevAppServerFactory
$CustomSecurityManager.checkPermission(DevAppServerFactory.java:166)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.exists(File.java:731)
at
com.sun.org.apache.bcel.internal.util.ClassPath.getPathComponents(ClassPath.java:
143)
at
com.sun.org.apache.bcel.internal.util.ClassPath.getClassPath(ClassPath.java:
169)
at
com.sun.org.apache.bcel.internal.util.SyntheticRepository.<clinit>(SyntheticRepository.java:
86)
... 36 more
FEHLER: 'null'
SCHWER WIEGENDER FEHLER: 'Die Formatvorlage konnte nicht kompiliert
werden.'
javax.xml.transform.TransformerConfigurationException: Die
Formatvorlage konnte nicht kompiliert werden.
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:
828)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:
617)
at com.axag.invoiceedit.server.<MY SERVLET>.doGet(<MY SERVLET>:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
(Please excuse the german error messages)



If I now refresh the browser the error message changes to:

java.lang.NoClassDefFoundError: Could not initialize class
com.sun.org.apache.bcel.internal.util.SyntheticRepository
at
com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
109)
at
com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
228)
at
com.sun.org.apache.bcel.internal.generic.ClassGen.getJavaClass(ClassGen.java:
174)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:
735)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
354)
at
com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
429)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:
795)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:
617)
at com.axag.invoiceedit.server.PDFServlet.doGet(PDFServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
FEHLER: 'Could not initialize class
com.sun.org.apache.bcel.internal.util.SyntheticRepository'
SCHWER WIEGENDER FEHLER: 'Die Formatvorlage konnte nicht kompiliert
werden.'
javax.xml.transform.TransformerConfigurationException: Die
Formatvorlage konnte nicht kompiliert werden.
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:
828)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:
617)
at com.axag.invoiceedit.server.PDFServlet.doGet(PDFServlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
(Again, please excuse the german error messages)

Does anybody have at least a clue why this happens?
Thank you very much in advance

lineman78

unread,
Jul 21, 2010, 2:23:49 PM7/21/10
to Google Web Toolkit
From what I can tell it is failing while compiling the stylesheet. I
would suggest taking app engine out of the loop altogether first and
just so it in a static main to make sure it is compiling. If it works
as a static main than it is probably the file IO. To test this I
recommend to try just reading the file to the log to make sure that
you actually have a hold of the file. I have found that the most
reliable way to read in a file is not to use the File constructor, but
assuming the name of your class is XsltService:

XsltService.class.getResourceAsStream("test.xsl"); // Assuming
test.xsl is in the same folder as the class file, set to "/test.xsl"
if it is in the root.

cokol

unread,
Jul 21, 2010, 3:24:35 PM7/21/10
to Google Web Toolkit
as already states by cause "Caused by:
java.security.AccessControlException: access denied "
you are not allowed to access the filesystem neither for read nor for
write - I remember there was a workaround for this issue, like putting
the resource into classpath or such, then you can get the stream via
getResourceAsStream("foo.xslt") from the classloader.

this should be stated in appengine faq

good luck,
> ...
>
> Erfahren Sie mehr »

emurmur

unread,
Jul 21, 2010, 4:05:17 PM7/21/10
to Google Web Toolkit
This seems very similar to issue 4267. The issue is the GWT is
setting a system property, overriding the default transformer
factory. This causes the appengine server to get the wrong
transformer factory. The exception you are getting is not exactly the
same as the bug, but the circumstances are very similary. A
workaround is, in your servlet, set the system property yourself to
the java default. This should fix the server (although it might cause
an issue in the GWT client, if you are using XML). Note that this is
only an issue in the development server and not in production.

Here is the issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=4267
Please go and check this issue so it get's some attention.

Here is the line of code to set the property on the server to work
around the GWT bug:

//
// When using GWT with appengine, we must override
the
// default TransformerFactory because GWT writes an
invalid
// default that causes an exception when trying to
// render a XML Representation. This works around the
bug.
//

System.setProperty("javax.xml.transform.TransformerFactory",
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");


On Jul 21, 5:42 am, Jan <jan.morl...@googlemail.com> wrote:
> Hi,
>
> I would like to use an xsl transformation inside an HttpServlet. The
> code is essentially the following:
>
> File xslfile = new File("test.xsl");
> TransformerFactory factory = TransformerFactory.newInstance();
> factory.setAttribute( "debug", true );
> Transformer transformer = factory.newTransformer(new
> StreamSource( xslfile ) );
>
> I already made sure that the xsl file is valid and I defined it as
> resource-file inside appengine-web.xml
>
> If I now call the servlet the first time, the following error occurs:
>
> java.lang.ExceptionInInitializerError
>         at
> com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
> 109)
>         at
> com.sun.org.apache.bcel.internal.classfile.JavaClass.<init>(JavaClass.java:
> 228)
>         at
> com.sun.org.apache.bcel.internal.generic.ClassGen.getJavaClass(ClassGen.jav a:
> 174)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Style sheet.java:
> 735)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
> 354)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
> 429)
>         at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemp lates(TransformerFactoryImpl.java:
> 795)
>         at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTran sformer(TransformerFactoryImpl.java:
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemp lates(TransformerFactoryImpl.java:
> 828)
>         at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTran sformer(TransformerFactoryImpl.java:
> com.sun.org.apache.bcel.internal.generic.ClassGen.getJavaClass(ClassGen.jav a:
> 174)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Style sheet.java:
> 735)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
> 354)
>         at
> com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:
> 429)
>         at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemp lates(TransformerFactoryImpl.java:
> 795)
>         at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTran sformer(TransformerFactoryImpl.java:
> 617)
>         at com.axag.invoiceedit.server.PDFServlet.doGet(PDFServlet.java:240)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
>         at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
> 511)
>         at org.mortbay.jetty.servlet.ServletHandler
> $CachedChain.doFilter(ServletHandler.java:1166)
>         at
> com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFi lter.java:
> ...
>
> read more »

Jan

unread,
Jul 23, 2010, 6:23:43 AM7/23/10
to Google Web Toolkit
Hi,

I made further investigations. The strange thing about this error is
the fact that AccessControlException occurs for my project's src
directory. The path, which the error message specifies, is even an
absolute windows path. However, the resource files, which I open
inside the program, are located inside war/WEB-INF.

Searching the internet, I found the following explanation (Citation
from http://forums.sun.com/thread.jspa?threadID=5370375):
"we encountered this as well. upon investigating into the depths of
the transformer code, the problem seems to be that the class
SyntheticRepository is making a call to ClassPath.getClassPath() which
attempts to access all the directories listed in various system
classpaths. if the calling code does not have read access to these
paths, then the call throws a securityexception and the
SyntheticRepository class fails to load, which borks the overall
transformer initialization. the kicker in all of this, is that the
call to ClassPath.getClassPath() seems entirely extraneous, as the
results of the call are never actually used for anything! it's pretty
much a bug."

In the following you can find a code snippet which works on a local
tomcat server however fails on gwt/gae. It considers already the
workaround for the bug emurmur mentioned. You can take the stylesheet
from
http://www.antennahouse.com/XSLsample/sample-xsl-xhtml2fo/xhtml2fo.xsl

protected void doGet(HttpServletRequest request,HttpServletResponse
response) throws ServletException, IOException
{

System.setProperty("javax.xml.transform.TransformerFactory","com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

String xslInputFilename = "/WEB-INF/xhtml2fo.xsl";

TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute("debug", true);

try {
Transformer transformer = factory.newTransformer(new
StreamSource(getServletContext().getResourceAsStream(xslInputFilename)));
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
}

I would really appreciate further help. Especially a workaround for
the misbehaviour of SyntheticRepository would be nice.
Thanks

Jan

unread,
Jul 27, 2010, 9:46:48 AM7/27/10
to Google Web Toolkit
I'm sorry, the reason for having all those error messages was that I
forgot to put serializer-<version>.jar and xalan-<version>.jar into /
WEB-INF/lib.
Best regards
Jan
Reply all
Reply to author
Forward
0 new messages