问题
I'm new with CMIS and Alfresco and I got this error when in try to connect to my Alfresco's repository using AtomPUB binding. I have no idea about the source of my problem. Is it unless a functionality ? Is it my Credential ? When I install it, I choose only : - Alfresco community - Solr4
How should I do if I want to use web services ? Should I install a specific plugin in my Alfresco ?
I got with error :
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/ME%2ME/.m2/repository/org/slf4j/slf4j-simple/1.7.9/slf4j-simple-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/ME%2ME/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Introuvable
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:499)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:701)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getRepositoriesInternal(AbstractAtomPubService.java:873)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:66)
at org.apache.chemistry.opencmis.client.bindings.impl.RepositoryServiceImpl.getRepositoryInfos(RepositoryServiceImpl.java:92)
at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:120)
at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.getRepositories(SessionFactoryImpl.java:107)
at fr.omb.TestOMB.connect(TestOMB.java:160)
at fr.omb.TestOMB.main(TestOMB.java:35)
My code :
package fr.omb;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.commons.lang3.StringUtils;
public class TestOMB {
private static Session session;
private static final String ALFRSCO_ATOMPUB_URL = "http://localhost:8080/alfresco/service/cmis";
private static final String TEST_FOLDER_NAME = "chemistryTestFolder";
private static final String TEST_DOCUMENT_NAME_1 = "chemistryTest1.txt";
private static final String TEST_DOCUMENT_NAME_2 = "chemistryTest2.txt";
public static void main(String[] args) {
Folder root = connect();
cleanup(root, TEST_FOLDER_NAME);
Folder newFolder = createFolder(root, TEST_FOLDER_NAME);
createDocument(newFolder, TEST_DOCUMENT_NAME_1);
createDocument(newFolder, TEST_DOCUMENT_NAME_2);
System.out.println("+++ List Folder +++");
listFolder(0, newFolder);
DeleteDocument(newFolder, "/" + TEST_DOCUMENT_NAME_2);
System.out.println("+++ List Folder +++");
listFolder(0, newFolder);
}
/**
* Clean up test folder before executing test
*
* @param target
* @param delFolderName
*/
private static void cleanup(Folder target, String delFolderName) {
try {
CmisObject object = session.getObjectByPath(target.getPath() + delFolderName);
Folder delFolder = (Folder) object;
delFolder.deleteTree(true, UnfileObject.DELETE, true);
} catch (CmisObjectNotFoundException e) {
System.err.println("No need to clean up.");
}
}
/**
*
* @param target
*/
private static void listFolder(int depth, Folder target) {
String indent = StringUtils.repeat("\t", depth);
for (Iterator<CmisObject> it = target.getChildren().iterator(); it.hasNext();) {
CmisObject o = it.next();
if (BaseTypeId.CMIS_DOCUMENT.equals(o.getBaseTypeId())) {
System.out.println(indent + "[Docment] " + o.getName());
} else if (BaseTypeId.CMIS_FOLDER.equals(o.getBaseTypeId())) {
System.out.println(indent + "[Folder] " + o.getName());
listFolder(++depth, (Folder) o);
}
}
}
/**
* Delete test document
*
* @param target
* @param delDocName
*/
private static void DeleteDocument(Folder target, String delDocName) {
try {
CmisObject object = session.getObjectByPath(target.getPath() + delDocName);
Document delDoc = (Document) object;
delDoc.delete(true);
} catch (CmisObjectNotFoundException e) {
System.err.println("Document is not found: " + delDocName);
}
}
/**
* Create test document with content
*
* @param target
* @param newDocName
*/
private static void createDocument(Folder target, String newDocName) {
Map<String, String> props = new HashMap<String, String>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put(PropertyIds.NAME, newDocName);
System.out.println("This is a test document: " + newDocName);
String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation.";
byte[] buf = null;
try {
buf = content.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ByteArrayInputStream input = new ByteArrayInputStream(buf);
ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length,
"text/plain; charset=UTF-8", input);
target.createDocument(props, contentStream, VersioningState.MAJOR);
}
/**
* Create test folder directly under target folder
*
* @param target
* @param createFolderName
* @return newly created folder
*/
private static Folder createFolder(Folder target, String newFolderName) {
Map<String, String> props = new HashMap<String, String>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
props.put(PropertyIds.NAME, newFolderName);
Folder newFolder = target.createFolder(props);
return newFolder;
}
/**
* Connect to alfresco repository
*
* @return root folder object
*/
private static Folder connect() {
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();
// User credentials.
parameters.put(SessionParameter.USER, "myuser");
parameters.put(SessionParameter.PASSWORD, "mypassword");
// Connection settings.
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.ATOMPUB_URL, ALFRSCO_ATOMPUB_URL);
parameters.put(SessionParameter.AUTH_HTTP_BASIC, "true");
parameters.put(SessionParameter.COOKIES, "true");
parameters.put(SessionParameter.OBJECT_FACTORY_CLASS,
"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
// Create session.
// Alfresco only provides one repository.
Repository repository = sessionFactory.getRepositories(parameters).get(0);
Session session = repository.createSession();
return session.getRootFolder();
}
}
回答1:
I found the solution, it's because of Alfresco's version. Since the V4.x the url of the AtomPUB is http://localhost:8080/alfresco/cmisatom.
https://community.alfresco.com/docs/DOC-5527-cmis
- For Alfresco 3.x : http://[host]:[port]/alfresco/service/cmis
- For Alfresco 4.0.x, Alfresco 4.1.x and Alfresco 4.2.a-c: http://[host]:[port]/alfresco/cmisatom
- For Alfresco 4.2.d-f, Alfresco 5.0 and Alfresco 5.1: http://[host]:[port]/alfresco/api/-default-/public/cmis/versions/1.0/atom
来源:https://stackoverflow.com/questions/41580963/cmisobjectnotfoundexception-when-trying-to-access-my-alfresco-repository