From 6aed1db28241e904cfaa34d8e1a497d383902c28 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Wed, 10 Mar 2010 16:53:35 +0000 Subject: [PATCH] Merging /BRANCHES/DEV/BELARUS/HEAD-2010_03_09/ to HEAD: 19193: CMIS WS transaction atomicity problem was resolved. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19196 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/cmis-ws-context.xml | 5 +- .../cmis/ws/DMServicePortThrowsAdvice.java | 12 +-- .../ws/DMTransactionWrappingInterceptor.java | 89 +++++++++++++++++++ 3 files changed, 99 insertions(+), 7 deletions(-) create mode 100755 source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java diff --git a/config/alfresco/cmis-ws-context.xml b/config/alfresco/cmis-ws-context.xml index 11c801b2ff..ffc416d965 100644 --- a/config/alfresco/cmis-ws-context.xml +++ b/config/alfresco/cmis-ws-context.xml @@ -285,13 +285,14 @@ - + - + + diff --git a/source/java/org/alfresco/repo/cmis/ws/DMServicePortThrowsAdvice.java b/source/java/org/alfresco/repo/cmis/ws/DMServicePortThrowsAdvice.java index fc79f31f79..68ac99dde7 100644 --- a/source/java/org/alfresco/repo/cmis/ws/DMServicePortThrowsAdvice.java +++ b/source/java/org/alfresco/repo/cmis/ws/DMServicePortThrowsAdvice.java @@ -40,18 +40,21 @@ public class DMServicePortThrowsAdvice implements ThrowsAdvice { LOGGER.error(e.toString(), e); } - throw ExceptionUtil.createCmisException(("Access denied. Message: " + e.toString()), e); } public void afterThrowing(java.lang.RuntimeException e) throws CmisException { + Throwable result = e; + if (null != e.getCause()) + { + result = e.getCause(); + } if (LOGGER.isErrorEnabled()) { - LOGGER.error(e.toString(), e); + LOGGER.error(result.toString(), result); } - - throw ExceptionUtil.createCmisException(("Runtime error. Message: " + e.toString()), e); + throw (result instanceof CmisException) ? ((CmisException) result) : (ExceptionUtil.createCmisException(("Runtime error. Message: " + result.toString()), result)); } public void afterThrowing(java.lang.Exception e) throws CmisException @@ -60,7 +63,6 @@ public class DMServicePortThrowsAdvice implements ThrowsAdvice { LOGGER.error(e.toString(), e); } - if (!(e instanceof CmisException)) { throw ExceptionUtil.createCmisException(("Some error occured during last service invokation. Message: " + e.toString()), e); diff --git a/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java b/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java new file mode 100755 index 0000000000..6e27805eaa --- /dev/null +++ b/source/java/org/alfresco/repo/cmis/ws/DMTransactionWrappingInterceptor.java @@ -0,0 +1,89 @@ +/* +* Copyright (C) 2005-2010 Alfresco Software Limited. +* +* This file is part of Alfresco +* +* Alfresco is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Alfresco is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with Alfresco. If not, see . +*/ +package org.alfresco.repo.cmis.ws; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.transaction.TransactionService; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.transaction.interceptor.TransactionAspectSupport; +import org.springframework.transaction.interceptor.TransactionAttribute; + +/** + * @author Dmitry Velichkevich + */ +public class DMTransactionWrappingInterceptor extends TransactionAspectSupport implements MethodInterceptor +{ + private TransactionService transactionService; + + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + + public Object invoke(final MethodInvocation target) throws Throwable + { + if ((null != target) && (null != target.getThis()) && (null != target.getMethod())) + { + final Method method = target.getMethod(); + final TransactionAttribute transactionAttribute = getTransactionAttributeSource().getTransactionAttribute(method, target.getThis().getClass()); + if (null != transactionAttribute) + { + return AuthenticationUtil.runAs(new RunAsWork() + { + public Object doWork() throws Exception + { + return transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() + { + public Object execute() throws Throwable + { + try + { + return method.invoke(target.getThis(), target.getArguments()); + } + catch (InvocationTargetException e) + { + if (null != e.getTargetException()) + { + throw e.getTargetException(); + } + else + { + throw new AlfrescoRuntimeException(e.getMessage(), e); + } + } + } + }, transactionAttribute.isReadOnly(), (TransactionAttribute.PROPAGATION_REQUIRES_NEW == transactionAttribute.getPropagationBehavior())); + } + }, AuthenticationUtil.getFullyAuthenticatedUser()); + } + else + { + return method.invoke(target.getThis(), target.getArguments()); + } + } + throw new AlfrescoRuntimeException("Invalid undefined MethodInvocation instance"); + } +}