cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript transaction, InvalidNodeRefException

pmartin
Champ in-the-making
Champ in-the-making
I have this error org.alfresco.service.cmr.repository.InvalidNodeRefException - Node does not exist: workspace://SpacesStore/7ad81e86-3a70-4cde-9c21-4d615616b6ad throw by my webscript.

This error is not throw everytime, only when other webscript delete node is use by the first webscript.

Webscript are in javascript.

Exemple :
1- Run a webscript then make an directory with two empty document.
2- Start a second  webscript that read the directorty node and save his children in a variable and after wait for 10 secondes, durring this time start a third webscript that delete one document of the directory. After the 10 seconde when the second webscript loop in the directory children an the exeption is throw (InvalidNodeRefException - Node does not exist: )

This issue il easy to reproduce and can be fix with try catch in the javascript controler but if children node is use in the view (ftl) is not catchabled.

Question

Is this a desired behavior? Why all webscript are not in a transaction. Why other webscript can make fail other webscript? Can y put somme config to solve this issue.
If y make the webscript in java can i use the transaction api to solve this issue ?


// Webscript 1
var node = companyhome;
var testTxNode = companyhome.childByNamePath("txNodeTest");
if (testTxNode != null)
{
   testTxNode.remove();
}
testTxNode = node.createFolder("txNodeTest");
var f1 = testTxNode.createFile('file1.txt');
f1.properties.content.guessMimetype('file1.txt');
var f2 = testTxNode.createFile('file2.txt');
f2.properties.content.guessMimetype('file2.txt');


// Webscript 2
function wait(msecs)
{
   var start = new Date().getTime();
   var cur = start
   while(cur - start < msecs)
   {
      cur = new Date().getTime();
   }   
}
var error = "";
var childrens = "";
var testTxNode = companyhome.childByNamePath("txNodeTest");
if (testTxNode == null)
{
   error = "Step 1 not passed correctly, Step 2 failed"
}
else
{
   var childs = testTxNode.children;
   wait(10000);
   for each (child in childs)
   {
      childrens += " - " + child.name;
   }
   error = "Step 3 not passed correctly, Step 2 Work " + childrens
}
model.error = error;



// Webscript 3
var result = "";
var testTxNode = companyhome.childByNamePath("txNodeTest/file2.txt");
if (testTxNode == null)
{
   result = "Step 1 not passed correctly, Step 3 failed";
}
else
{
   testTxNode.remove();
   result = "passed";
}
model.resultat = result;
3 REPLIES 3

openpj
Elite Collaborator
Elite Collaborator
By default for each WebScript in Alfresco there is a unique transaction.
You can try to change the transaction element in the webscript descriptor using the requiresnew value:

<transaction>requiresnew</transaction>
Maybe you could solve in this way.

But if you need to implement a more complex procedure you have to implement your own WebScript using a Java-Backed WebScript and using RetryingTransactionHelper.

Java-Backed WebScript:
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

Transactions:
http://wiki.alfresco.com/wiki/Java_Foundation_API#Handling_UserTransaction_Directly

Hope this helps.

pmartin
Champ in-the-making
Champ in-the-making
By default for each WebScript in Alfresco there is a unique transaction.
My problem proves that is not true, one webscript change data in other webscript ?


I try  <transaction>requiresnew</transaction> and this config change absolutly nothing.  :x

Can exist a solution for webscript with javascript controler ? or only in java ?

openpj
Elite Collaborator
Elite Collaborator
I think that you have to use the Java language, Alfresco doesn't provide any way to manage transactions using the Javascript API.