I know that it is in general not allowed to access local Files (with java.io) within an EJB: nevertheless, I have an EJB which has to open an Excel File and edit it using the apache.poi library. If I do something like this:
@Stateless
public class MyEJB {
public void editExcel(){
...
InputStream in = MyEJB.class.getClassLoader().getResourceAsStream("/xls/ExcelFile.xls");
final Workbook generatedExcel = new XLSTransformer().transformXLS(in, beans);
...
} }
The filesystem structure:
MyEar.ear
--my-ejb.jar
---com
-----company
-------ejbs
----------MyEJB.class
---xls
-----ExcelFile.xls
In this case I will get an Instance of ZipFile$ZipFileInputStream (private inner class of ZipFileInputStream) and XLSTransformer will throw an IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"), as it expects an InputStream representing ExcelFile.xls and gets instead a stream representing the whole my-ejb.jar.
My questions: do you know how to solve this situation? What is the best practice for accessing file within EJBs?
Thanks a lot!