[opencms-dev] Access denied on writeFile() - prior solutions ineffective

M Butcher mbutcher at grcomputing.net
Tue Apr 20 19:41:01 CEST 2004


I recently had a similar problem. Rather than resolve it, I switched to 
the other createResource() method:

  newFile = cms.createResource( "/outdir/",
                                       "myFile.txt",
                                       "plain",
                                       new Hashtable(),
                                       contentsByteArray );



Matt

Kenny MacLeod wrote:
> Hi folks,
> 
> I found this same problem detailed in two previous posts to this list, but
> the suggested solutions do not work (nor did they work for the original
> posters).
> 
> The problem concerns Access Denied exceptions being thrown by the
> writeFile() method of the CmsObject class.  An example code fragment (where
> "cms" is the CmsObject) would be:
> 
>   cms.getRequestContext().setCurrentProject(4);
>   CmsFile cmsFile = (CmsFile) cms.createResource(folderPath, fileName,
> "plain");
>   cmsFile.setContents(fileData);        
>   cms.writeFile(cmsFile);
> 
> The final line throws the following exception:
> 
>     [exec] com.opencms.core.CmsException: 1 Access denied. Detailed error:
> [com.opencms.file.mySql.CmsResourceBroker] /test/file.txt
>     [exec]      at
> com.opencms.file.genericSql.CmsResourceBroker.writeFile(CmsResourceBroker.ja
> va:7475)
>     [exec]      at com.opencms.file.CmsObject.writeFile(CmsObject.java:3863)
> 
> 
> As you can see, I can create the CmsResource OK - if I go to the OpenCMS
> explorer at this point, and select the Offline project, I can see the file
> there, marked as locked, as expected.  But writeFile() still throws that
> exception.
> 
> The previous suggested solution was to incorporate the call to
> setCurrentProject(), but as you can see, that's what I've done, and it
> doesn't fix the problem.  If setCurrentProject() is removed, then the code
> fails during createResource() instead, which is what I would expect.
> 
> So, my question is, what other changes do I have to make to the code to
> allow writeFile() to succeed?  I notice from the source of the
> com.opencms.workplace.CmsEditor class that writeFile() is used successfully.
> So what's the secret?
> 
> Regards,
> 
> 
> Kenny
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev




More information about the opencms-dev mailing list