Checking file type in JAVA action before or after commit doesnt work in cloud, but does work locally?

1
The following JAVA code isn't allowed to run in the cloud:   // This file was generated by Mendix Modeler. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package myModule.actions; import java.io.File; import java.io.IOException; import java.nio.file.Files; import com.mendix.core.Core; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; public class GetFileExtentionAsString extends CustomJavaAction<java.lang.String> { private java.lang.String fileName; public GetFileExtentionAsString(IContext context, java.lang.String fileName) { super(context); this.fileName = fileName; } @Override public java.lang.String executeAction() throws Exception { // BEGIN USER CODE String fileType = null; File file = new File(fileName); try { fileType = Files.probeContentType(file.toPath()); } catch (IOException ioException) { Core.getLogger("Error file type").info("Unable to determine file type for " + fileName + " due to exception " + ioException); } return fileType; // END USER CODE } /** * Returns a string representation of this action */ @Override public java.lang.String toString() { return "GetFileExtentionAsString"; } // BEGIN EXTRA CODE // END EXTRA CODE } Can anyone give a reason why this might be the case? Sorry I removed some logging from the post because apparently the forum stops showing answers @ 7 answers. Jan 11 13:06:14.958 127.0.0.1 tr10000: INFO - Unable to determine file type for TestImage.png due to exception java.security.AccessControlException: access denied ("java.io.FilePermission" "TestImage.png" "read") The reason why this is not allowed is because of the JAVA line  File file = new File(fileName); Unfortunately I haven't found a workaround yet
asked
6 answers
2

I recently published a module with a single java action that gets the file type based on the extension and file contents. Might be useful for other people who need this:

Link: File Type Checker 

answered
1

I recently published a module with a Java action that gets the file type based on the extension and content. 

Might be useful for others reading this question.

Link: File Type Checker

answered
0

"isn't allowed to run"... Could you be more specific? 

Do you get an AccessControlException?

answered
0

That part of the error merely indicates that something went wrong during the commit. The actual cause is usually a little further down in the stack trace.

Could you post the entire stack trace?

 

answered
0

Ah... that doesn't give us much more to go on. 

Probably a redundant question, but is there anything in your BCO microflow that could cause the 'return false' ?

Any error in the java-action itself (Except for IO, which you catch) should be thrown and result in a standard Mendix log error. I have seen situations in the past where this didn't happen properly however. 

Could you change your 'catch' from IOException to Exception? That should catch any and all exceptions and result in a logline right away. 

answered
0

If I recall correctly, a java.security exception refers to an error with the java.policy security settings (as opposed to a permission issue with the file or folder you're trying to access). 

However, in all cases that I've encountered a similar error, it would also occur locally when EmulateCloudSecurity was enabled (as you stated it is, for you).

That would mean that either the java.policy settings as emulated by your local deployment are different from those in the MxCloud, or I'm overlooking something. 

 

[Edited: Removed double post]

answered