cancel
Showing results for 
Search instead for 
Did you mean: 

Catching IntegrityException on webscript

spilby
Confirmed Champ
Confirmed Champ
How can I catch an IntegrityException before my java backed webscript ends?

I use transactions when create the nodes:


       UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction(false);
      
       try {
         trx.begin();
         //create node
         trx.commit();
      } catch(Throwable e) {
         trx.rollback();
         …
      }   


but the IntegrityException is thrown after the webscript ends. Because of this, I can't catch the exception to return an specific error message.

I don't understand also why this checkIntegrity occurs at the end of the webscript. If I use transactions, why this not occurs when I do the trx.commit()?

I try to add on my desc.xml a <transaction>required</transaction> but the problem continues.

7 REPLIES 7

kaynezhang
World-Class Innovator
World-Class Innovator


IntegrityException is thrown when some operation violate integrity .for example ,Mandatory property not set,Mandatory aspect not set.

Integrity check is implementated using policy/behaviour.

You can try to use RetryingTransactionHelper instead of using TransactionService directly

I change the code and do the following:


try {
          RetryingTransactionCallback<Object> txnWork = new RetryingTransactionCallback<Object>()
           {
               public Object execute() throws Exception
               {
                  NodeRef nodeRef = null;

                  nodeRef = createNode(…);
                  
                   return nodeRef;
               }
           };
           TransactionService transactionService = serviceRegistry.getTransactionService();
           nodeRef = (NodeRef)transactionService.getRetryingTransactionHelper().doInTransaction(txnWork, true);
       } catch(Throwable e) {
         logger.error("transaccionCreateNode - ERROR: " + e);
         throw new Exception(e);
   }


But the result is the same. The exception is here (when a user try to create a folder with a "/" character):


org.alfresco.repo.node.integrity.IntegrityException: 05270651 Found 1 integrity violations:
Invalid property value:
   Node: workspace://SpacesStore/207dc36c-9096-4d80-83e6-819d8b4afd9b
   Type: {own.property}velocity
   Property: {http://www.alfresco.org/model/content/1.0}name
   Constraint: 05270650 Value 'F/ABC' is not valid as a file name. This property must be a valid file name.
        at org.alfresco.repo.node.integrity.IntegrityChecker.checkIntegrity(IntegrityChecker.java:661)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:694)
        at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:927)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
        at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:472)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:471)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:483)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:521)
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:333)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

muralidharand
Star Contributor
Star Contributor
Hi,
Can you please post little bit the operation that you're doing with your webscript?
Assume, if the node type is cm:content and if you try to add folder / or any other operation related to cm:folder, then you'll receive IntegrityException.

Yes, is a getNodeService().createNode operation. A user try to create a folder with a "/" character, and the integrity exception is thrown. I want to catch this for this reason.

kaynezhang
World-Class Innovator
World-Class Innovator
I have two questions:
1.How do you specify transaction needs in your webscript description document? is it none ,required or requiresnew ?
2.If you are using required or requiresnew ,why do you want to run a separate transaction in your webscript?

spilby
Confirmed Champ
Confirmed Champ
In my webscript description document the parameter appears like required


<transaction>required</transaction>


I do a different transactions because I want that the rollback affect only a group of operations inside the begin and commit block.

kaynezhang
World-Class Innovator
World-Class Innovator
You can either disable webscript transaction by setting
<transaction>none</transaction> 
or using
 getNonPropagatingUserTransaction
in your java code.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.