wood burning stoves*
The moose likes I/O and Streams and the fly likes 'Access is Denied' when writing a file to a UNC path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark " Watch " New topic

'Access is Denied' when writing a file to a UNC path

Kevin Valencia

Joined: Aug 20, 2007
Posts: 18
I have a webapp deployed in my own terminal (has windows xp) which writes a file to a certain directory. When other terminals access this webapp, it is still able to write a file to the directory of those terminals. No problem on permissions. But when i deployed the webapp in the webserver (has windows server 2003) it can no longer write to directories even if sharing permissions have been set. Also, when the shared directories are physically mapped, files can be created in them since it has full control access.
It gives this error:

java.io.FileNotFoundException: \\PCNAME\H\Sample File (Access is denied)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.amkor.cimapps.action.MainAction.downloadMap(MainAction.java:398)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.amkor.cimapps.filter.SessionCheckerFilter.doFilter(SessionCheckerFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

Appreciate your responses!
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

I assume this is running as a Windows service. Make sure that you know what user the service is configured to run as, and make sure that user has the appropriate authority to create files in that directory. If you didn't do anything special when you set up the service then it's a local user on that computer, not a domain user, and you will have to specifically authorize that local user to have access to the other computer.
Kevin Valencia

Joined: Aug 20, 2007
Posts: 18
Hello Paul,
The webserver is running the app in Tomcat6 and login is domain user account which already have share permissions on the directory its trying to write to. How do i know which user is running the app? In the task manager, this is what i see...
tomcat6.exe --- SYSTEM
tomcat6w.exe --- domain user account

Really appreciate your help!
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

You could look at the configuration of the services that run Tomcat. But I can tell you that what we ended up doing was to make "Everyone" have full control of the directory in question, and then looked to see what user created the files.
Kevin Valencia

Joined: Aug 20, 2007
Posts: 18
Hello Paul..
I've managed to change the log on configuration of tomcat to the domain user account. Its now working. Thanks a bunch for the help!
I agree. Here's the link: http://aspose.com/file-tools
subject: 'Access is Denied' when writing a file to a UNC path
Similar Threads
Tomcat in Eclipse File Write Permissions
Eclipse WTP Tomcat startup problem/Spring bean problem
Web Application Migration from Tomcat 4.1 to Tomcat 6.0
hibernate: cascade="none" Not working for update. Child objects are updated even after this option
update query