我尝试将dotcmis和alfresco集成到我的应用程序中。 在创建单元测试时,我遇到了这个问题: - 如果有的话,我删除“myfolder”来设置我的测试环境 - 我创建了myfolder并将文档放入其中
然后我尝试找到该文件: - 第一次(当myfolder之前不存在时),搜索返回0结果 - 下次,当myfolder存在之前并被我的测试设置删除时,我得到一个例外:
Apache Chemistry OpenCMIS - runtime error
HTTP Status 500 - <!--exception-->runtime<!--/exception--><p><!--message-->Node does not exist: missing://missing/missing(null)<!--/message--></p><hr noshade='noshade'/><!-- stacktrace--><pre>
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Node does not exist: missing://missing/missing(null)
at org.alfresco.opencmis.AlfrescoCmisExceptionInterceptor.invoke(AlfrescoCmisExceptionInterceptor.java:80)
at ...
当我去Alfresco时,文件存在。 看来文件夹和文件对于查询来说还不是很难理解,但为什么呢? 如果我对测试环境init进行注释,则会找到该文档
也许我做错了什么但是什么?
这是我的代码:
[TestMethod()]
[DeploymentItem(@"Files\SearchTest_1", @"Files\SearchTest_1")]
public void SearchTest_2()
{
string myfoldername = "myfolder";
// Session creation
var p = new Dictionary<String, String>();
p[SessionParameter.User] = _userName;
p[SessionParameter.Password] = _userPassword;
p[SessionParameter.BindingType] = BindingType.AtomPub;
p[SessionParameter.AtomPubUrl] = _serverUrl;
var session = DotCMIS.Client.Impl.SessionFactory.NewInstance().GetRepositories(p)[0].CreateSession();
session.DefaultContext.CacheEnabled = false;
var operationContext = session.CreateOperationContext();
operationContext.IncludeAcls = true;
// Delete and create back folder and document
// /*
DotCMIS.Client.IFolder rootFolder = this._testSession.GetRootFolder(operationContext);
DotCMIS.Client.IFolder myFolder = null;
Dictionary<String, Object> properties = null;
// Le dossier de destination des tests existe-t-il ?
var myFolderExists = rootFolder.GetChildren(operationContext).Any(child => child.Name.Equals(myfoldername));
if (myFolderExists)
{
myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
myFolder.DeleteTree(true, DotCMIS.Enums.UnfileObject.Delete, true);
}
properties = new Dictionary<String, Object>();
properties[PropertyIds.Name] = myfoldername;
properties[PropertyIds.ObjectTypeId] = "cmis:folder";
myFolder = rootFolder.CreateFolder(properties);
rootFolder.Refresh();
myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
FileInfo sourceFile = new FileInfo(@"Files\SearchTest_1\SearchTest_1.pdf");
properties = new Dictionary<String, Object>();
properties[PropertyIds.ObjectTypeId] = "cmis:document";
properties[PropertyIds.Name] = sourceFile.Name;
using (var fileStream = sourceFile.OpenRead())
{
var contentStream = new DotCMIS.Data.Impl.ContentStream();
contentStream.MimeType = "application/pdf";
contentStream.Stream = fileStream;
contentStream.Length = fileStream.Length;
//this._testSession.CreateDocument(properties, this._testSession.CreateObjectId(myFolder.Id), contentStream, null);
DotCMIS.Client.IDocument createdDocument = myFolder.CreateDocument(properties, contentStream, null);
}
// */
// Recherche
string query = @"SELECT * FROM cmis:document WHERE cmis:name = 'SearchTest_1.pdf'";
var results = this._testSession.Query(query, false, operationContext).ToArray();
Assert.AreEqual(1, results.Length);
}
答案 0 :(得分:3)
您使用Alfresco 4.0和Solr进行索引吗? Solr索引最终是一致的,这意味着在搜索结果中显示更新可能需要一段时间(在默认配置中最多15秒)。
如果您需要立即显示更新,可以切换到Lucene作为索引子系统。
答案 1 :(得分:0)
我认为solr的“最终一致”方面不是生产中的问题。 可能是在测试时,但我更喜欢在生产中使用更好的系统,并且在调试中遇到一些问题,而不是相反。
为了解决我在调试中遇到的问题,我首先放了一个Thread.Sleep(20)......但它确实有效,但是......调试时间很长。
我的第二个解决办法似乎是使用url地址检查solr的索引状态:8080 / solr / admin / cores?action = REPORT(我的代码中为_solrStateUrl)。 问题是它只能由SSL默认访问。 因此,您需要从afresco服务器获取文件“browser.p12”并将其放入您的项目中。
所以我做了两个方法: - 正在解析xml响应以查找正在进行的事务的CheckIndexingState - 在CheckIndexingState上循环的WaitForIndexingDone
此代码可能不太安全,但它只是用于测试......
在这里。希望这会有所帮助...
private bool CheckIndexingState()
{
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; });
System.Net.HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(_solrStateUrl);
request.ClientCertificates.Add(new X509Certificate2(@"ssl/browser.p12", "alfresco"));
var sb = new System.Text.StringBuilder();
byte[] buffer = new byte[256];
int nbRead = -1;
using (var stream = request.GetResponse().GetResponseStream())
{
while (nbRead != 0)
{
nbRead = stream.Read(buffer, 0, 256);
sb.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, nbRead));
}
}
String state = sb.ToString();
try
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
var node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of transactions in the index but not the DB']");
int count = Int32.Parse(node.InnerText);
if (count > 0)
return false;
node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of acl transactions in the index but not the DB']");
count = Int32.Parse(node.InnerText);
if (count > 0)
return false;
node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing transactions from the Index']");
count = Int32.Parse(node.InnerText);
if (count > 0)
return false;
node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing acl transactions from the Index']");
count = Int32.Parse(node.InnerText);
if (count > 0)
return false;
}
catch (Exception)
{
throw;
}
return true;
}