FilePermission exception in custom Java action

0
Hi all, I am writing a custom CSV download in which the user has more flexibility than in Mendix. I want to make sure that the CSV is UTF-8 'signed' so it opens in Excel with special characters showing properly. This is a common problem in Java CSV exporting and importing in Excel. I found a solution on stackoverflow to add some characters in the outputstream before the stringwriter adds the content. So, the first line below creates the stacktrace after it:   FileOutputStream os = new FileOutputStream(fileName); os.write(0xef); os.write(0xbb); os.write(0xbf);   In this Java code, Mendix blocks me from writing to an already created file (fed as inputparameter to Java action) and throws an exception with stacktrace: com.mendix.modules.microflowengine.MicroflowException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.security.AccessControlException: access denied ("java.io.FilePermission" "Custom CSV with sorted subset of columns.csv" "write")     at OQL_modeler.IVK_parseCSV_FromList (JavaAction : 'JA_parseCSV_FromList') Advanced stacktrace:     at com.mendix.modules.microflowengine.MicroflowUtil.processException(MicroflowUtil.java:143) Caused by: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.security.AccessControlException: access denied ("java.io.FilePermission" "Custom CSV with sorted subset of columns.csv" "write")     at com.mendix.basis.component.InternalCore.execute(InternalCore.java:535) Caused by: com.mendix.core.CoreRuntimeException: com.mendix.systemwideinterfaces.MendixRuntimeException: java.security.AccessControlException: access denied ("java.io.FilePermission" "Custom CSV with sorted subset of columns.csv" "write")     at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:178) Entity access is configured and the user has all CRUD priviliges on that entity. Does anybody know how to fix this? Another workaround would also be appreciated ;).
asked
2 answers
0

Place the file in the resourcefolder.

answered
0

As an update, I found a fix for this without the need of a temporary file. I added the BOM signature to the StringWriter and after this single line of code Excel correctly interprets the character encoding, showing special characters properly.

		StringWriter sw = new StringWriter();
		
		// create char separator which is input for the CSVWriter
		char separator = separatorString.charAt(0);
		
		// 20180711 - Ivo Sturm: add BOM signature to the file as a starter. This is needed to make sure Excel directly interprets special characters correctly.
		sw.write('\uFEFF');

After this, create the lines with the content of your liking. For me it was iterating through a set of MendixObjects.

answered