// 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();
/** * @see org.apache.commons.pool.PoolableObjectFactory#makeObject() */ @Override public Object makeObject() throws Exception { if (repository == null) { throw new RepositoryUnavailableException(lastException); } return repository.createSession(); }
/** * 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);