Java Code Examples for org.apache.chemistry.opencmis.client.api.SessionFactory#createSession()

The following examples show how to use org.apache.chemistry.opencmis.client.api.SessionFactory#createSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_10_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_OC, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example 2
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getATOMPUB_11_Session()
{
    try
    {
        Map<String, String> parameters = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.ATOMPUB_URL, MessageFormat.format(ATOMPUB_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());
        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example 3
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Session getBROWSER_11_Session()
{
    try
    {
        Map<String, String> parameter = new HashMap<String, String>();
        int port = getTestFixture().getJettyComponent().getPort();

        parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
        parameter.put(SessionParameter.BROWSER_URL, MessageFormat.format(BROWSE_URL_11, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameter.put(SessionParameter.COOKIES, "true");

        parameter.put(SessionParameter.USER, ADMIN_USER);
        parameter.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);

        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();

        parameter.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameter).get(0).getId());
        return sessionFactory.createSession(parameter);
    }
    catch (Exception ex)
    {
        logger.error(ex);

    }
    return null;
}
 
Example 4
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create a CMIS session using Enterprise AtomPub binding.
 *
 * @param repositoryId String
 * @param username String
 * @param password String
 * @return CmisSession
 */
public CmisSession createCMISSession(String repositoryId, String username, String password)
{
    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameters = new HashMap<String, String>();

    // user credentials
    parameters.put(SessionParameter.USER, username);
    parameters.put(SessionParameter.PASSWORD, password);

    // connection settings
    parameters.put(SessionParameter.ATOMPUB_URL, client.getCmisUrl(repositoryId, null));
    parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    if(repositoryId != null)
    {
        parameters.put(SessionParameter.REPOSITORY_ID, repositoryId);
    }
    parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, AlfrescoObjectFactoryImpl.class.getName());

    // create session
    Session session = factory.createSession(parameters);

    CmisSession cmisSession = new CmisSession(session);
    return cmisSession;
}
 
Example 5
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Connect to logicaldoc repository
 * 
 * @return root folder object
 */
private static Folder connect(String username, String password) {
	SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
	Map<String, String> parameter = new HashMap<String, String>();
	parameter.put(SessionParameter.USER, username);
	parameter.put(SessionParameter.PASSWORD, password);
	parameter.put(SessionParameter.ATOMPUB_URL, CONNECTION_URL);
	parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
	parameter.put(SessionParameter.REPOSITORY_ID, Long.toString(5L));

	session = sessionFactory.createSession(parameter);
	return session.getRootFolder();
}
 
Example 6
Source File: TestCMIS.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void testCanConnectCMISUsingDefaultTenantImpl(Binding binding, String cmisVersion)
{
    String url = httpClient.getPublicApiCmisUrl(TenantUtil.DEFAULT_TENANT, binding, cmisVersion, null);
    
    Map<String, String> parameters = new HashMap<String, String>();
    
    // user credentials
    parameters.put(SessionParameter.USER, "admin");
    parameters.put(SessionParameter.PASSWORD, "admin");
    
    parameters.put(SessionParameter.ATOMPUB_URL, url);
    parameters.put(SessionParameter.BROWSER_URL, url);
    parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
    
    SessionFactory factory = SessionFactoryImpl.newInstance();
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}
    List<Repository> repositories = factory.getRepositories(parameters);
    
    assertTrue(repositories.size() > 0);
    
    parameters.put(SessionParameter.REPOSITORY_ID, TenantUtil.DEFAULT_TENANT);
    Session session = factory.createSession(parameters);
    // perform request : http://host:port/alfresco/api/-default-/public/cmis/versions/${cmisVersion}/${binding}/type?id=cmis:document
    ObjectType objectType = session.getTypeDefinition("cmis:document");
    
    assertNotNull(objectType);
}
 
Example 7
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Session getWEBSERVICE_10_Session()
{
    try
    {
        SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
        int port = 8080;

        Map<String, String> parameters = new HashMap<String, String>();

        parameters.put(SessionParameter.USER, ADMIN_USER);
        parameters.put(SessionParameter.PASSWORD, ADMIN_PASSWORD);
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());

        parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE,
                MessageFormat.format(ACLSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
                MessageFormat.format(DISCOVERYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
                MessageFormat.format(MULTIFILINGSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
                MessageFormat.format(NAVIGATIONSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE,
                MessageFormat.format(OBJECTSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE,
                MessageFormat.format(POLICYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
                MessageFormat.format(RELATIONSHIPSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
                MessageFormat.format(REPOSITORYSERVICE_OC_URL, DEFAULT_HOSTNAME, String.valueOf(port)));
        parameters.put(SessionParameter.REPOSITORY_ID, sessionFactory.getRepositories(parameters).get(0).getId());

        return sessionFactory.createSession(parameters);
    }
    catch (Exception ex)
    {
        logger.error(ex);
    }
    return null;
}
 
Example 8
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public CmisSession createPublicApiCMISSession(Binding binding, String version, String objectFactoryName)
{
    CmisSession cmisSession = null;

    RequestContext rc = getRequestContext();
    if(rc == null)
    {
        throw new RuntimeException("Must set a request context");
    }

    String networkId = rc.getNetworkId();
    String username = rc.getRunAsUser();
    UserData userData = findUser(rc.getRunAsUser());
    if(userData != null)
    {
        String password = userData.getPassword();

        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();

        // user credentials
        parameters.put(SessionParameter.USER, username);
        parameters.put(SessionParameter.PASSWORD, password);

        // connection settings
        if(binding == Binding.atom)
        {
            parameters.put(SessionParameter.ATOMPUB_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        }
        else if(binding == Binding.browser)
        {
            parameters.put(SessionParameter.BROWSER_URL, client.getPublicApiCmisUrl(networkId, binding, version, null));
            parameters.put(SessionParameter.BINDING_TYPE, binding.getOpenCmisBinding().value());
        }
        if(networkId != null)
        {
            parameters.put(SessionParameter.REPOSITORY_ID, networkId);
        }
        if(objectFactoryName != null)
        {
            parameters.put(SessionParameter.OBJECT_FACTORY_CLASS, objectFactoryName);
        }

        // create session
        Session session = factory.createSession(parameters);

        cmisSession = new CmisSession(session);
    }

    return cmisSession;
}