I've been using JXL for a while to process excel files from inside the webapp folder. This works in both development and production. I just inject a ServletContext
and call something like:
Workbook.getWorkbook(new File(servletContext.getRealPath("WEB-INF/myfile.xls")))
and JXL can read the file and process it.
I recently switched to using Apache POI in an App Engine Servlet but I get an exception:
[ERROR] java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\Users\Drew\IntelliJ\UsavApp\target\UsavAppV7-1.0-SNAPSHOT\WEB-INF\myfile.xlsx" "write")
[ERROR] at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
[ERROR] at java.security.AccessController.checkPermission(AccessController.java:559)
[ERROR] at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
[ERROR] at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)
[ERROR] at java.lang.SecurityManager.checkWrite(SecurityManager.java:979)
[ERROR] at java.io.RandomAccessFile.<init>(RandomAccessFile.java:229)
[ERROR] at org.apache.poi.poifs.nio.FileBackedDataSource.newSrcFile(FileBackedDataSource.java:130)
[ERROR] at org.apache.poi.poifs.nio.FileBackedDataSource.<init>(FileBackedDataSource.java:46)
[ERROR] at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:218)
[ERROR] at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:166)
[ERROR] at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:278)
[ERROR] at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:250)
[ERROR] at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:229)
[ERROR] at com.utilitiessavings.usavappv7.server.handler.parse.ParseElecTariffBooksHandler.processTariffsFromExcel(ParseElecTariffBooksHandler.java:108)
[ERROR] at com.utilitiessavings.usavappv7.server.handler.parse.ParseElecTariffBooksHandler.execute(ParseElecTariffBooksHandler.java:91)
[ERROR] at com.utilitiessavings.usavappv7.server.handler.parse.ParseElecTariffBooksHandler.execute(ParseElecTariffBooksHandler.java:39)
...etc
From reading around I gather POI isn't totally compatible with GAE, but most people talk about creating files from scratch, or writing them to the local disk. I'm not doing either of those so I wanted to be sure this is a limitation of App Engine and not something I'm doing.
My guess from the exception would be that POI needs write access even to read the file, whereas JXL didn't. Is there a way to read a spreadsheet in app engine using Apache POI?