2016-09-07 36 views
0

DotCMIS调用在我从5个文档中提取任何两个文档后停止响应。Alfresco奇怪的超时问题

我检查了Alfresco服务器上的日志,没有任何事情与失败的调用有关。

我已调试以识别超时。

//定义CMIS可用路径,该路径已经在露天 参数下可用[DotCMIS.SessionParameter.AtomPubUrl] =“https://localhost:8080/alfresco/service/cmis”;

// alfresco门户管理员用户名 参数[DotCMIS.SessionParameter.User] =“admin”;

// alfresco门户管理员密码 参数[DotCMIS.SessionParameter.Password] =“w4rth0g!”;

//定义会话工厂 SessionFactory factory = SessionFactory.NewInstance();我们将执行操作&在此存储库上创建会话 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; 
    } 

在这里,我正在关闭比赛流。后来在以下方法,我通过

公共静态无效CreateMergedPdf试图环路(串targetPdfLocation,IEnumerable的docStreams) { 尝试 { 使用(的FileStream流=新的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); 
     } 
    } 

我已经把闭合连接移到了我在这里消费的方法。

//按照orderNo字段的顺序合并文档。 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; 

在这里,我将无法访问封闭的stream.Is有什么办法重新打开?

第三次当createsession()被调用时,它给出超时errror。

+0

只需打开一个会话并重新使用它。不需要为每个文档打开一个会话。 –

回答

1

您是否已经使用并关闭了文档内容流? .Net允许每个服务器只有两个并发连接。如果你不关闭流,那么拖拽连接就会被用完,而.Net阻止,直到它们关闭。

另请参阅:https://issues.apache.org/jira/browse/CMIS-559

+0

是的,我试图通过关闭比赛流。会话超时现在将发生,如果我关闭。我将添加的文档传递给另一种方法并读取竞争网络流。在这里我得到errro connot访问封闭流。 – coder

+0

有什么方法可以重新打开吗?我用所用的代码更新了我的问题。这里 \t \t \t \t \t的foreach(在docStreams VAR DOC) \t \t \t \t \t { \t \t \t \t \t \t pdf.AddDocument(新PdfReader(DOC)); \t \t \t \t \t}我会在这个bolck中得到错误“无法访问封闭的流”。 – coder

+0

您必须使用流。仅仅关闭是不够的。当你需要时打开流,而不是之前。您可以通过文档属性获取所有流元数据(名称,长度,大小)。或者...增加DefaultConnectionLimit。 –