cancel
Showing results for 
Search instead for 
Did you mean: 

Sessions not closing in tomcat after calling webservices

nuga
Champ in-the-making
Champ in-the-making
My Sessions not closing in tomcat after calling webservices.

is anyone else having this problem.  right now the number of sessions is i kid you not 5,647

i can't figure out why


/alfresco     Alfresco Web Client     true     5,647        Start   Stop   Reload   Undeploy
7 REPLIES 7

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

I've logged an issue in JIRA for this.  http://issues.alfresco.com/browse/AR-1210

If you have any example code or unit tests of the client code that is causing this issue could you post it here or attach it to the bug.

This will help us ensure that we resolve your issue.

Many thanks,
Roy

nuga
Champ in-the-making
Champ in-the-making
A simple test would be to loop a query 500x as i have done below.
then open up the tomcat manager and you will see that there are 501 sessions.  And they remain open for quite a while.  is this the expected behaviour for alfresco?


-Luke



package com.nk.fmc.stars.test;


import java.rmi.RemoteException;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.alfresco.webservice.authentication.AuthenticationServiceLocator;
import org.alfresco.webservice.authentication.AuthenticationServiceSoapBindingStub;
import org.alfresco.webservice.classification.ClassificationServiceSoapBindingStub;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
import org.hibernate.SessionFactory;
import org.nkics.contentretrieval.ContentRetriever;
import org.nkics.contentretrieval.ContentRetrieverImpl;
import org.nkics.contentretrieval.AlfrescoWSImpl.AlfrescoWebServiceContentTransformer;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;



public class LoadTestQuery extends TestCase {
   Store STORE = null;
   RepositoryServiceSoapBindingStub repository;
   ContentServiceSoapBindingStub content;
   ClassificationServiceSoapBindingStub classification;
   private static final String REF_TEXT1 = "/*[@cm:name=\"";

   private static final String REF_TEXT2 = "\"]";

   private static final String NODE_REF = "workspace://SpacesStore/";

   protected void setUp() throws Exception {
      super.setUp();
      
      AuthenticationUtils.startSession("admin", "admin");
         AuthenticationServiceSoapBindingStub authenticationService =
               (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
        
         //AuthenticationResult result = authenticationService.startSession("admin", "admin");
      //   ticket = result.getTicket();
      STORE = new Store(Constants.WORKSPACE_STORE,
      "SpacesStore");
      
      
      repository = WebServiceFactory
            .getRepositoryService();
      content = WebServiceFactory
      .getContentService();
      classification = WebServiceFactory
      .getClassificationService();
   

   }
   

   public void testCategoriesSearch() throws Exception
   {
      for (int x= 0; x<500; x++)
      {
      //Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/cm:generalclassifiable//cm:Regions\"");
      Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/cm:generalclassifiable//cm:Eastern_x0020_Asia\"");
      //Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/cm:generalclassifiable//cm:AK\"");
      QueryResult result = repository.query(STORE, query, true);
   
      ResultSet rs = result.getResultSet();
      ResultSetRow[] rows = rs.getRows();

   
      for (ResultSetRow row : rows) {
         System.out.println("UID: "+    row.getNode().getId());
         System.out.println("Type: "+    row.getNode().getType());
         NamedValue[] values = row.getColumns();
         System.out.println("Properties: ");
         for (NamedValue col : values) {
            System.out.println("\tName: " + col.getName());
            System.out.println("\tValue: " + col.getValue());
            
         }
      }
      }
   
   }



   protected void tearDown() throws Exception {

      AuthenticationUtils.endSession();
      super.tearDown();
   }
}

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Thanks for that.

There is some more information on this issue here http://issues.alfresco.com/browse/AR-993 .

It seems that we need to figure out a way to pass cookie information, like the web client, so that Tomcat does not create a new session for every request.

Cheers,
Roy

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

This has been fixed now.

The authentication service returns the session id back with the user name and ticket.  This can then be passed on subsequent requests as a cookie allowing Tomcat to reuse the same session.

The client libraries have been updated to this this automatically.

Cheers,
Roy

isanalon
Champ in-the-making
Champ in-the-making
Hi,

This has been fixed now.

The authentication service returns the session id back with the user name and ticket.  This can then be passed on subsequent requests as a cookie allowing Tomcat to reuse the same session.

The client libraries have been updated to this this automatically.

Cheers,
Roy

I'm having exactly the same issue as nuga states in his first post on this thread: for every query to Alfresco, I'm getting a new session on Tomcat. This causes the creation of hundreds, sometimes thousands of sessions in my application!
rwetherall, I have read the solution you've provided but I don't understand how to make it work (no idea about cookie creation and management) Could you -or anyone else- please post source code for managing cookies in a way that will allow us to reuse the session, or at least post a link to any web page that explains clearly how to do it? I've searched for quite a long time without much success. This would really make my day, I've been having a lot of trouble trying to find a solution to this problem.
Thanks a lot in advance.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Are you using the Alfresco java web service client library or are you doing things yourself?

I presume you are using Java to access the web services?

Cheers,
Roy

isanalon
Champ in-the-making
Champ in-the-making
Hi,

Are you using the Alfresco java web service client library or are you doing things yourself?

I presume you are using Java to access the web services?

Cheers,
Roy

Hi Roy,

Yes, I'm using good old Java and Yes, I'm using your webservices (I haven't developed others)
I think I found the solution to the problem. I was using an old version of the Alfresco repository, and although I'd updated my webservices to version 2.1 (I was using 1.4 before) I was accessing an old repository and sessions just popped up without any control.
With the new version of the repository (2.0), and the new webservices (2.1) everything seems to go just about fine but there's still one issue that intrigues me: ONE (and only one) Tomcat session is created, but when I end the session (using AuthenticationUtils.endSession();   ) it's still "alive" as I have checked on the Tomcat manager.
This is obviously a minor problem compared to the one I had before, but I wonder if this is the expected behaviour or should the Tomcat session end after calling AuthenticationUtils.endSession();  … if not,
Is there any other way to end the Tomcat session after the execution of the application?

Thanks again for your response.