I've a strange problem with creation of a file in the remote shared network folder.
Use case:
- My development environment is located in some local VM.
- Application calculates some data. Creates and saves a xml file under specific path. (example: C:/ProgramData/MyApp/exp/heregoestofile.txt).
- You can specify the file location. So it could be a local folder within the VM, or remote shared network folder.
Problem: When I run the application on my local machine, everything is working fine if i specify the file location within the local VM and xml file is created without any problem. However my issue is that, in my application I have an option to specify where the file should be created. So, for my use case, file has to be created in some shared remote network directory. When I try to create the file, I get the following exception:
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|directory is created: \\Win-ris3devae1\hfshare\ERS01[2021-02-08 10-42-35-000]
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|some directory is about to be created: \\Win-ris3devae1\hfshare\ERS01[2021-02-08 10-42-35-000]
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|[org.subethamail.smtp.server.Session-/0:0:0:0:0:0:0:1:49945] ERROR com.ricoh.sdced.ers.xmlparser.XMLParser - An exception occured in writeXMLDocumentToFile method:
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|directory is created: \\Win-ris3devae1\hfshare\ERS01[2021-02-08 10-42-35-000]
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|java.io.IOException: Access is denied
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|till here it comes without any problem
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at java.io.WinNTFileSystem.createFileExclusively(Native Method)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36|creating a new file with path: \\Win-ris3devae1\hfshare\ERS01[2021-02-08 10-42-35-000]\index.xml
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at java.io.File.createNewFile(File.java:1014)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at com.ricoh.sdced.ers.xmlparser.XMLParser.writeXMLDocumentToFile(XMLParser.java:90)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at com.ricoh.sdced.ers.server.MailHandler.saveMetadataToFolder(MailHandler.java:58)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at com.ricoh.sdced.ers.server.MailHandler.saveMailToFolder(MailHandler.java:47)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at com.ricoh.sdced.ers.server.MailHandlerFactory$Handler.data(MailHandlerFactory.java:65)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.internal.command.DataCommand.execute(DataCommand.java:58)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.internal.server.RequireTLSCommandWrapper.execute(RequireTLSCommandWrapper.java:32)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.internal.server.RequireAuthCommandWrapper.execute(RequireAuthCommandWrapper.java:35)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.internal.server.CommandHandler.handleCommand(CommandHandler.java:86)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.server.Session.runCommandLoop(Session.java:233)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at org.subethamail.smtp.server.Session.run(Session.java:147)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
INFO|4288/0|Service Ricoh ERS|21-02-08 10:42:36| at java.lang.Thread.run(Thread.java:748)
The code I use to create the file is this:
public void writeXMLDocumentToFile(String folderPath) {
try (FileOutputStream stream = new FileOutputStream(folderPath + XML_FILE_NAME)) {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, YES);
transformer.setOutputProperty(XSLT_INDENT_AMOUNT_STRING, INDENTATION_AMOUNT);
Source s = new DOMSource(this.document);
Result res = new StreamResult(stream);
transformer.transform(s, res);
} catch (TransformerException | IOException e) {
logger.error(EXCEPTION_IN_WRITEXMLDOCUMENTTOFILE_METHOD, e);
}
}
Note: You can say that I might not have the permission for writing & reading to this remote shared folder. I already gave it and its not the case unfortunately.I did the following test:
- My development environment is in a VM.
- I open the command line in my development VM and do something like echo hello >> \someaddress\myapplication\hello.txt and its created all fine. That means remote folder is opened for write read access within my vm.
So this means i dont have any network permission issue, as I can already create a file in remote shared network folder, inside this VM using a command line.