cancel
Showing results for 
Search instead for 
Did you mean: 

New thread error to call FileFolderServiceImpl

liveljack
Champ in-the-making
Champ in-the-making
Hi all,
    A new method was added to FileFolderServiceImpl, and it run pretty well.  But when I am trying to call it from a new thread in EditContentPropertiesDialog.  The AuthenticationCredentialsNotFoundException error is thrown. I cannot find what's wrong, could any of you please be kind enough to help me out of this? Smiley Sad
    Thanks a lot!
    The exception stack is like the following:

Exception in thread "Thread-110" net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A
valid SecureContext was not provided in the RequestContext
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSe
curityInterceptor.java:477)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecur
ityInterceptor.java:355)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(Method
SecurityInterceptor.java:77)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
cation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(E
xceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
cation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:147)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
cation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInte
rceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
cation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy64.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:619)
4 REPLIES 4

mrogers
Star Contributor
Star Contributor
Each thread has its own authentication context and it looks like you have not initialised it.
On the new thread use the AuthenticationUtils class to "RunAs" the same user as your "current thread".

Also, depending upon your requirement,  you may be able to use the internal "fileFolderService" spring bean, note the little F, since that bean will not have permission checking.

liveljack
Champ in-the-making
Champ in-the-making
Thanks mrogers a lot, the new function in FileFolderService could be called successfully now.  The codes are like the following:

class ThumbnailGenerateThread extends Thread{
        FileFolderService ffservice;
        NodeRef noderef;
        public ThumbnailGenerateThread(FileFolderService service, NodeRef node){
            this.ffservice = service;
            this.noderef = node;
        }

        public void run(){
            RunAsWork<Object> thumbGeneWork = new RunAsWork<Object>()
            {
                public Object doWork() throws Exception
                {
                    System.out.println("before generation of ThumbnailGenerateThread");
                    ffservice.generaThumbnail(noderef);
                    System.out.println("after generation of ThumbnailGenerateThread");
                    return null;
                }
            };
          AuthenticationUtil.runAs(thumbGeneWork, AuthenticationUtil.SYSTEM_USER_NAME);
        }
    }


But I have got another problem while calling the newly added "generaThumbnail" function.  The error is like

Exception in thread "Thread-103" org.springframework.transaction.UnexpectedRollbackException: Transa
ction rolled back because it has been marked as rollback-only
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(Abstrac
tPlatformTransactionManager.java:717)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAft
erReturning(TransactionAspectSupport.java:394)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInte
rceptor.java:117)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvo
cation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy64.generaThumbnail(Unknown Source)
        at org.alfresco.web.bean.content.EditContentPropertiesDialog$ThumbnailGenerateWork.doWork(Ed
itContentPropertiesDialog.java:360)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.jav
a:514)
        at org.alfresco.web.bean.content.EditContentPropertiesDialog$ThumbnailGenerateThread.run(Edi
tContentPropertiesDialog.java:391)

Is there any reason why the transaction is marked as rollback-only?  Please~~

liveljack
Champ in-the-making
Champ in-the-making
Could anyone be kind enough to check this problem, please? Smiley Sad

mrogers
Star Contributor
Star Contributor
There's a problem somewhere which is resulting in an exception being thrown.   Then later on you try to commit the transaction rather than rolling it back.   The key to solving this is to find out where the first exception is occurring.   It's usually caused by code incorrectly swallowing exceptions.