cancel
Showing results for 
Search instead for 
Did you mean: 

CmisUnauthorizedException: Unauthorized After long WCMQS inactivity

leonardo_celati
Champ in-the-making
Champ in-the-making
Invoking an Alfresco page on WCMQS works fine and I get the page rendered properly. Then after long inactivity, which I didn't measure but seems to be at least an hour, I get this exception while accessing the page again (I am just showing part of the exception):


org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException: Unauthorized
org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException: Unauthorized
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:466)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:635)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:179)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl$5.fetchPage(SessionImpl.java:872)
   at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
   at org.apache.chemistry.opencmis.client.runtime.util.CollectionIterator.hasNext(CollectionIterator.java:48)
   at it.wzm.alfresco.client.WebSiteServiceImpl.refreshWebsiteCache(WebSiteServiceImpl.java:172)
   at it.wzm.alfresco.client.WebSiteServiceImpl.getWebSiteCache(WebSiteServiceImpl.java:155)
   at it.wzm.alfresco.client.WebSiteServiceImpl.getWebSite(WebSiteServiceImpl.java:122)



I have tried to track down the problem, but I was unable to come out with a solution.

I don't know if it is relevant, but I have only seen for example that GuestSessionFactoryImpl, which is supposed (by reading the javadoc) to create a pool of connection, gets called at startup, and its init method is launching a thread (isn't it forbidden by the specs ?) which is supposed to poll the CMIS server, such thread die as soon as it gets a connection, so the polling stops.


    @Override
    public void run()
    {
        Thread thisThread = Thread.currentThread();
        while (waitForRepository == thisThread)
        {
            // See if the repository can be reached
            try
            {
                getRepository();
                log.info("Repository available");
                break; // <– this stops the thread ?!
            }
            catch (Exception e)
            {
                lastException = e;
                log.warn("WQS unable to connect to repository: " + e.getMessage());
                if (log.isDebugEnabled())
                {
                    log.debug("Caught exception while attempting to connect to repository over CMIS", e);
                }
            }

            // Wait a bit
            try
            {
                Thread.sleep(repositoryPollInterval);
            }
            catch (InterruptedException e)
            {
            }
        }
        waitForRepository = null;
    }
2 REPLIES 2

leonardo_celati
Champ in-the-making
Champ in-the-making
Honestly, I still don't know much about WCMQS mechanism, but by commenting the line


            try
            {
                getRepository();
                log.info("Repository available");
                //break; // <– commented out ?!
            }


Cause the thread to run and therefore the connection is kept alive. But just because I don't like traditionals threads spawning the JEE application server, I have used the spring task. At least the spring framework should have full control on it.
You can notice that the invoked method 'getRepository' is the same as GuestSessionfactoryImpl, and infact I just pasted the same line of codes that was in the mentioned class.

Well, things work, but I don't know if it's to be considered a patch, or a solution, or worst if it may cause some problems. I would like a confirmation by someone more expert than me.


<task:scheduled-tasks scheduler="pollerScheduler">
    <task:scheduled ref="cmisPoller" method="getRepository" fixed-rate="${period}"/>
</task:scheduled-tasks>

<task:scheduler id="pollerScheduler" pool-size="10"/>

I got the same problem. I don't see any solution yet.