0

DotCMIS calls stop responding after I've fetched any two documents out of 5 document.

I have checked the logs on the Alfresco server and there is nothing at all related to the failed calls.

I have debugged to identify the timeout .

// define CMIS available path which is already available under alfresco parameters[DotCMIS.SessionParameter.AtomPubUrl] = "https://localhost:8080/alfresco/service/cmis";

// alfresco portal admin user name parameters[DotCMIS.SessionParameter.User] = "admin";

// alfresco portal admin password parameters[DotCMIS.SessionParameter.Password] = "w4rth0g!";

// define session factory SessionFactory factory = SessionFactory.NewInstance();

// using session factory get the default repository, on this repository we would be performing actions & create session on this repository ISession session = factory.GetRepositories(parameters)[0].CreateSession();

public ContentStream GetContentByDocumentId(string docId) { ISession session; IObjectId id; IDocument doc; IContentStream contentStream; ContentStream contentStreamModel = new ContentStream();

        try
        {
            session = GetSession();
            id = session.CreateObjectId(docId);
            doc = session.GetObject(id) as IDocument;

            // Content
            contentStream = doc.GetContentStream();

            contentStreamModel.FileName = contentStream.FileName;
            contentStreamModel.Length = contentStream.Length;
            contentStreamModel.MimeType = contentStream.MimeType;
            contentStreamModel.Stream = contentStream.Stream;

            contentStreamModel.Stream.Close();
        }
        catch (Exception ex)
        {
            throw new ApplicationException(ex.Message);
        }
        finally
        {

            session = null;
            id = null;
          //  session.Delete(id, true);
           // session.Clear();
            doc = null;
            contentStream = null;
            //contentStream.Stream.Close();
            //contentStreamModel.Stream.Close();

        }

        return contentStreamModel;
    }

Here i am closing the contenet stream . Later in the below method i am trying to loop through that

public static void CreateMergedPdf(string targetPdfLocation, IEnumerable docStreams) { try { using (FileStream stream = new FileStream(targetPdfLocation, FileMode.Create)) { var pdfDoc = new Document(PageSize.A4); PdfCopy pdf = new PdfCopy(pdfDoc, stream); pdfDoc.Open();

                foreach (var doc in docStreams)
                {
                    pdf.AddDocument(new PdfReader(doc));
                }

                pdfDoc.Close();
            }
        }
        catch (Exception ex)
        {
            throw new ApplicationException(ex.Message);
        }
    }

I have moved the closing connection to a the method where i am consuming here.

// Merge documents in order of orderNo field. var docStreams = new List(); //var docStreams2 = new List();

        **foreach (string docId in orderedDocIds)
        {
            // Retreive doc from Alfresco.
            var doc = GetContentByDocumentId(docId);
            docStreams.Add(doc.Stream);
            doc.Stream.Close();
        }**

       // docStreams.CopyTo(docStreams2.ToArray());



        // Created a merged pdf and drops in a temp folder.
        FileHelper.CreateMergedPdf(mergedPdfFileLocation, docStreams2);

        return mergedPdfFileLocation;

Here i will get cannot access closed stream.Is there any way to reopen?

On third time when the createsession() is getting called it gives timeout errror.

coder
  • 23
  • 1
  • 9

1 Answers1

1

Have you consumed and closed the document content streams? .Net allows only two concurrent connections per server. If you don't close the streams, the tow connections are used up and .Net blocks until they are closed.

See also: https://issues.apache.org/jira/browse/CMIS-559

Florian Müller
  • 3,215
  • 1
  • 14
  • 11
  • Yes,i tried by closing the contenet stream. The session timeout will now happen if i close. I am passing the added doc to another method and reading the contenet stream . Here i get errro connot access closed stream. – coder Sep 08 '16 at 10:13
  • Is there any way yo reopen ? I have updated my question with the code used. Here on foreach (var doc in docStreams) { pdf.AddDocument(new PdfReader(doc)); } i will get error in this bolck "Cannot access a closed Stream." – coder Sep 08 '16 at 10:15
  • You have to consume the stream. Just closing isn't enough. Open the stream when you need, not before. You can get all the stream metadata (name, length, size) through the document properties. Or ... increase the DefaultConnectionLimit. – Florian Müller Sep 08 '16 at 10:45
  • I have moved my content stream close to my calling method . **foreach (string docId in orderedDocIds) { // Retreive doc from Alfresco. var doc = GetContentByDocumentId(docId); docStreams.Add(doc.Stream); doc.Stream.Close(); }** – coder Sep 08 '16 at 11:17
  • How can i increase the defaultconnectionlimit. Do i need to increase it in Alfresco ???can you please plz explain a bit. I am new to the dotcmis and will be helpful if you can review the code . – coder Sep 08 '16 at 11:18
  • ServicePointManager.DefaultConnectionLimit = 100; I have added this before session = GetSession(); id = session.CreateObjectId(docId); and it seems working. Can you confirm this is what you meant – coder Sep 08 '16 at 11:35