javamultithreadingplayframeworkfilenotfoundexceptionws-client

Permission denied to write file using java


I have created a REST API that is getting called asynchronously (.asyncApply), and that API is trying to write a file but getting permission denied as I have changed all types of permissions are in place in the respective directory.

I have researched a lot but not getting anything solution on this

Is there a possibility that an asynchronous call is creating the issue?

PS: this issue is occurring intermittently. Also, I am using Play-frame work and WSCliet to hit REST API.

UPDATE - api flow is like this :

Request :

Document xml = play.libs.XML.fromString("<document></document>");
 ws.url(url).post(xml);

Processing Response :

completionStage<Document> documentPromise =
ws.url(url).get().thenApplyAsync(r -> r.getBody(xml()));

during processing, it hits some API Asynchronously and while writing file it gets an exception like

2021-05-17 12:08:03.079 +0530 [DEBUG] from com.zaxxer.hikari.pool.PoolBase:? in
                application-akka.actor.default-dispatcher-1233 - HikariPool-2 - Reset (autoCommit) on connection oracle.jdbc.driver.T4CConnection@1a8c2ee6
2021-05-17 12:08:03.145 +0530 [INFO] from utils.BulkOutputFileCreator:? in
                application-akka.actor.default-dispatcher-1233 - Exception occurred in writing file
java.io.FileNotFoundException: NF/BRO_PP/SMAPLE/outPut1234.csv (Permission denied)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
    at java.io.PrintWriter.<init>(PrintWriter.java:184)
    

Solution

  • https://www.suse.com/support/kb/doc/?id=000019272

    This web page finally gave me hope that my code is not having any issue so we debugged in the Linux side where our code was deployed.

    we found a very strange behavior from NFS side, our directory permission was kept fluctuating from 777 to 755 between NFS mount point to our server-side directory

    so we gave 777 from NFS server directly and the above-mentioned functionality was working fine.

    So basically issue was occurring due to permission which was fluctuating.