我尝试将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 ...当我去露天的时候,文档就存在了。文件夹和文档似乎还不能进行查询,但是为什么?如果我在测试环境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);
}发布于 2012-07-04 19:15:02
您是否正在使用带有Solr的Alfresco 4.0进行索引?Solr索引最终是一致的,这意味着更新可能需要一段时间(在默认配置中最多15秒)才能显示在搜索结果中。
如果您需要立即显示更新,您可以切换到Lucene作为索引子系统。
发布于 2012-07-05 17:18:31
我不认为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;
}https://stackoverflow.com/questions/11327119
复制相似问题