Reputation: 563
I use an XML file to hold my SQL queries. As per the app engine guidelines here: http://code.google.com/appengine/kb/java.html#readfile
I have the file in my war/WEB-INF directory and load is as such:
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse("\\WEB-INF\\Queries.xml");
When I deploy to GAE I see this in the logs:
access denied (java.io.FilePermission /\WEB-INF\Queries.xml read)
Did I miss something?
Upvotes: 1
Views: 140
Reputation: 9116
I found out that there is no need to use the ServletContext to access the external file. Simply using new File("WEB-INF/Queries.xml") works. (Notice the lack of slash on the first char of the file path)
For example, I use this to access the backends.xml file:
File tBackendFile = new File( "WEB-INF/backends.xml" );
Document tBackendDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(tBackendFile);
Upvotes: 0
Reputation: 10241
it is taking the path as an absolute path and therefore it is saying access denied for that file.
Instead use an overload of parse(InputStream is) which takes InputStream as an argument.
try this piece of code, it should work fine.
ServletContext context = getServletContext();
InputStream is = context.getRealPath("/WEB-INF/Queries.xml");
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse(is);// throws SAXException and IOException
Upvotes: 2