cancel
Showing results for 
Search instead for 
Did you mean: 

RESOLVED: Read only web scripts

tara_b
Champ in-the-making
Champ in-the-making
Hello,

I have implemented a way to make Alfresco read-only during the time that we back it up, by using a Toggle (http://cedric.bosdonnat.free.fr/wordpress/?p=87).  We have a single server, so i dont have the option of having a slave for backing up.

I can successfully make Alfresco read-only using the above toggling method by scheduling a java app to run, which runs the following code:

       TransactionService myTransactionService = this.services.getTransactionService();
       TransactionServiceImpl serviceAction = (TransactionServiceImpl)myTransactionService;

       boolean status = myTransactionService.isReadOnly();
       if(aToggle && !status)
       {
          //toggle read only
          serviceAction.setAllowWrite(false);
          aMessage = "Alfresco in read-only status";
          System.out.println("Toggling read-only");
       }

This all works well, however I am using Alfresco as a backend to a Joomla website. Joomla will access various webscripts in Alfresco when a user browses the pages, so the Alfresco webscripts have to be up 24/7. When i have the toggle to read-only, I can run webscripts if they dont contain a .js, however as soon as i run webscript with a .js, i get the following error:

 <status>
  500
  <name>Internal Error</name>
  <description>An error inside the HTTP server which prevented it from fulfilling the request.</description>
  </status>
  <message>Wrapped Exception (with status template): Failed to execute script '/com/moxy/Metadata/metadata.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': Read-Write transaction started within read-only transaction</message>
  <exception>org.alfresco.web.scripts.WebScriptException - Wrapped Exception (with status template): Failed to execute script '/com/moxy/Metadata/metadata.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': Read-Write transaction started within read-only transaction</exception>
  <callstack>org.alfresco.error.AlfrescoRuntimeException: Read-Write transaction started within read-only transaction org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:292) org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227) org.alfresco.repo.web.scripts.RepoStore$RepoScriptContent$1.doWork(RepoStore.java:906) org.alfresco.repo.web.scripts.RepoStore$RepoScriptContent$1.doWork(RepoStore.java:904) org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:437) org.alfresco.repo.web.scripts.RepoStore$RepoScriptContent.getInputStream(RepoStore.java:902) org.alfresco.repo.web.scripts.RepositoryScriptProcessor$RepositoryScriptLocation.getInputStream(RepositoryScriptProcessor.java:163) org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:119) org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:263) org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:108) org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:800) org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:90) org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:319) org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320) org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227) org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:368) org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:390) org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:273) org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:261) org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139) org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:116)


My web script has the following authentication:

 <authentication>guest</authentication>
<transaction>none</transaction>

The Web scripts are not writing to Alfresco or the database - they are actually read-only. Is there a way to overwrite the safety check which causes the error above?  Thanks in advance for your help!

Tara
3 REPLIES 3

zaizi
Champ in-the-making
Champ in-the-making
Can you move your web script out of the repository and in the class path on the file system and try that? See http://wiki.alfresco.com/wiki/Web_Scripts#Deciding_Where_to_Place_Web_Script_Implementation for details.

tara_b
Champ in-the-making
Champ in-the-making
Thanks for your reply, i will try that.

tara_b
Champ in-the-making
Champ in-the-making
Thank you so much! When I use the classpath method, it works perfectly.