// User credentials. parameters.put(SessionParameter.USER, "admin"); parameters.put(SessionParameter.PASSWORD, "admin"); // Connection settings. parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/service/cmis"); // URL to your CMIS server. parameters.put(SessionParameter.AUTH_HTTP_BASIC, "true" ); parameters.put(SessionParameter.COOKIES, "true" ); // Create session. // Alfresco only provides one repository. Repository repository = sessionFactory.getRepositories(parameters).get(0); Session session = repository.createSession();
@Override public void afterPropertiesSet() throws Exception { String defaultRepositoryId = (String)cmisSessionInitProperties.get(SessionParameter.REPOSITORY_ID); if (defaultRepositoryId == null){ // If not repository is specified, the first repository is taken as default List<Repository> repositories = sessionFactory.getRepositories(cmisSessionInitProperties); Repository repository = repositories.get(0); cmisSessionInitProperties.put(SessionParameter.REPOSITORY_ID, repository.getId()); } }
public static String getRepositoryID(Map<String, String> parameters, String baseURL) { String repoID = null; try { logger.debug("Attempting to dynamically obtain the repository ID."); List<Repository> repositoryList = SessionFactoryImpl.newInstance().getRepositories(parameters); if (repositoryList.isEmpty()) { logger.error("No repositories were returned at the CMIS server URL \"" + baseURL + "\". " + "The connector is currently non-functional."); } else { // Get the first repo in the list. Repository firstRepo = repositoryList.get(0); // Extract the ID of this repo, and add it to the parameters list. repoID = firstRepo.getId(); logger.debug("The repository ID that will be used is " + repoID + "."); } } catch (Exception repoIDEx) { throw new CMISConnectorConnectionException("An error occurred while attempting to dynamically obtain a repository ID: " + repoIDEx.getMessage() + ". The connector is currently non-functional. ", repoIDEx); } return repoID; // end getRepositoryID }
/** * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() */ @Override public Object makeObject() throws Exception { if (repository == null) { throw new RepositoryUnavailableException(lastException); } return repository.createSession(); }
protected Session getCmisSession() { if (cachedSession == null) { synchronized (this) { if (cachedSession == null) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(SessionParameter.USER, cmisUser); parameters.put(SessionParameter.PASSWORD, cmisPassword); parameters.put(SessionParameter.ATOMPUB_URL, cmisAtompubUrl); parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // We're using the Alfresco extensions parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); // First need to fetch the repository info to know the repo id SessionFactory sessionFactory = SessionFactoryImpl.newInstance(); List<Repository> repositories = sessionFactory.getRepositories(parameters); String repositoryId = repositories.get(0).getId(); parameters.put(SessionParameter.REPOSITORY_ID, repositoryId); cachedSession = sessionFactory.createSession(parameters); } } } return cachedSession; }
/** * Gets a CMIS Session by connecting to the Alfresco Cloud. * * @param accessToken * @return Session */ public Session getCmisSession() { // default factory implementation SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, ATOMPUB_URL); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true"); parameter.put(SessionParameter.USER, USER_NAME); parameter.put(SessionParameter.PASSWORD, PASSWORD); parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); List<Repository> repositories = factory.getRepositories(parameter); return repositories.get(0).createSession(); }
/** * Gets a CMIS Session by connecting to the Alfresco Cloud. * * @param accessToken * @return Session */ public Session getCmisSession() throws Exception { if (cmisSession == null) { // default factory implementation SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, ATOMPUB_URL); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); parameter.put(SessionParameter.AUTH_HTTP_BASIC, "false"); parameter.put(SessionParameter.HEADER + ".0", "Authorization: Bearer " + getAccessToken()); parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); List<Repository> repositories = factory.getRepositories(parameter); this.cmisSession = repositories.get(0).createSession(); } return this.cmisSession; }
/** * Gets a CMIS Session by connecting to the Alfresco Cloud. * * @param accessToken * @return Session */ public Session getCmisSession() { if (cmisSession == null) { String accessToken = getCredential().getAccessToken(); System.out.println("Access token:" + accessToken); // default factory implementation SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, this.getAtomPubURL()); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); parameter.put(SessionParameter.AUTH_HTTP_BASIC, "false"); parameter.put(SessionParameter.HEADER + ".0", "Authorization: Bearer " + accessToken); parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); List<Repository> repositories = factory.getRepositories(parameter); cmisSession = repositories.get(0).createSession(); } return cmisSession; }
/** * Gets a CMIS Session by connecting to the local Alfresco server. * * @return Session */ public Session getCmisSession() { if (cmisSession == null) { // default factory implementation SessionFactory factory = SessionFactoryImpl.newInstance(); Map<String, String> parameter = new HashMap<String, String>(); // connection settings parameter.put(SessionParameter.ATOMPUB_URL, getAtomPubURL(getRequestFactory())); parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true"); parameter.put(SessionParameter.USER, getUsername()); parameter.put(SessionParameter.PASSWORD, getPassword()); parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); List<Repository> repositories = factory.getRepositories(parameter); cmisSession = repositories.get(0).createSession(); } return this.cmisSession; }
public void testDownloadEvent() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); String docname = "mydoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, docname); } // content byte[] byteContent = "Hello from Download testing class".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream); Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); ContentStream content = doc1.getContentStream(); assertNotNull(content); //range request content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4)); assertNotNull(content); }
@Override public void run() throws Exception { Session session; SessionParameterMap parameters = new SessionParameterMap(getParameters()); if (!parameters.containsKey(SessionParameter.USER_AGENT)) { parameters.setUserAgent(TCK_USER_AGENT); } String repId = parameters.get(SessionParameter.REPOSITORY_ID); if (repId != null && repId.length() > 0) { session = factory.createSession(parameters); } else { session = factory.getRepositories(parameters).get(0).createSession(); } // switch off the cache session.getDefaultContext().setCacheEnabled(false); try { run(session); } catch (Exception e) { if (!(e instanceof FatalTestException)) { addResult(createResult(UNEXPECTED_EXCEPTION, "Exception: " + e, e, true)); } } catch (Error err) { addResult(createResult(UNEXPECTED_EXCEPTION, "Error: " + err, err, true)); } finally { testFolder = null; } }
Session session = repository.createSession(); Folder rootFolder = session.getRootFolder();
public void DISABLED_testBasicFileOps() { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); // create folder Map<String,String> folderProps = new HashMap<String, String>(); { folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate()); } Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext()); Map<String, String> fileProps = new HashMap<String, String>(); { fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt"); } ContentStreamImpl fileContent = new ContentStreamImpl(); { ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt")); writer.putContent("Ipsum and so on"); ContentReader reader = writer.getReader(); fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN); fileContent.setStream(reader.getContentInputStream()); } folder.createDocument(fileProps, fileContent, VersioningState.MAJOR); }
public void testALF10085() throws InterruptedException Session session = repository.createSession(); Folder rootFolder = session.getRootFolder();
Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);