Java Code Examples for javax.jcr.Session#isLive()

The following examples show how to use javax.jcr.Session#isLive() . 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: SessionLogoutSix.java    From AEM-Rules-for-SonarQube with Apache License 2.0 6 votes vote down vote up
public void six() {
    Session session = null; // Noncompliant
    String plotTwist = "twist";
    plotTwist = "anotherTwist";
    plotTwist = getMeAnotherTwist();
    plotTwist = StringUtils.capitalize(plotTwist);
    try {
        session = repository.loginService(null, null);
    } catch (RepositoryException e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isLive()) {
            //	session.logout();
            plotTwist.toString();
        }
    }
}
 
Example 2
Source File: SessionLogoutTwo.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
public void two() {
    Session session = null;
    try {
        session = repository.loginAdministrative(null);
    } catch (RepositoryException e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
Example 3
Source File: SessionLogoutFive.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
public void five() {
    Session session = null; // Noncompliant
    try {
        session = repository.loginAdministrative(null);
    } catch (RepositoryException e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isLive()) {
            //	session.logout();
        }
    }
}
 
Example 4
Source File: SessionLogoutThree.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
public void three() {
    Session session = null;
    try {
        session = repository.loginService(null, null);
    } catch (RepositoryException e) {
        e.printStackTrace();
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
Example 5
Source File: SessionLogoutOne.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
public void one() {
    Session session = null;
    try {
        session = createAdminSession();
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
 
Example 6
Source File: Activator.java    From publick-sling-blog with Apache License 2.0 5 votes vote down vote up
/**
 * Create user groups for authors and testers.
 *
 * @param bundleContext The bundle context provided by the component.
 */
private void createGroups(BundleContext bundleContext){
    ServiceReference SlingRepositoryFactoryReference = bundleContext.getServiceReference(SlingRepository.class.getName());
    SlingRepository repository = (SlingRepository)bundleContext.getService(SlingRepositoryFactoryReference);

    Session session = null;

    if (repository != null) {
        try {
            session = repository.loginAdministrative(null);

            if (session != null && session instanceof JackrabbitSession) {
                UserManager userManager = ((JackrabbitSession)session).getUserManager();
                ValueFactory valueFactory = session.getValueFactory();

                Authorizable authors = userManager.getAuthorizable(PublickConstants.GROUP_ID_AUTHORS);

                if (authors == null) {
                    authors = userManager.createGroup(PublickConstants.GROUP_ID_AUTHORS);
                    authors.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_AUTHORS));
                }

                Authorizable testers = userManager.getAuthorizable(PublickConstants.GROUP_ID_TESTERS);

                if (testers == null) {
                    testers = userManager.createGroup(PublickConstants.GROUP_ID_TESTERS);
                    testers.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_TESTERS));
                }
            }
        } catch (RepositoryException e) {
            LOGGER.error("Could not get session", e);
        } finally {
            if (session != null && session.isLive()) {
                session.logout();
                session = null;
            }
        }
    }
}
 
Example 7
Source File: SolrBulkUpdateHandler.java    From aem-solr-search with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    response.setCharacterEncoding("utf-8");

    JSONArray solrDocs = new JSONArray();

    final String slingResourceType = getSlingResourceType(request);

    if (StringUtils.isEmpty(slingResourceType)) {
        response.getWriter().write(solrDocs.toJSONString());
        return;
    }

    Map<String, String> params = new HashMap<String, String>();
    params.put("path", "/content/geometrixx-media");
    params.put("type", "cq:PageContent");
    params.put("property", "sling:resourceType");
    params.put("property.value", slingResourceType);
    params.put("p.offset", "0");
    params.put("p.limit", "50");

    Session session = null;

    try {
        session = repository.loginAdministrative(null);
        Query query = queryBuilder.createQuery(PredicateGroup.create(params), session);
        SearchResult results = query.getResult();

        LOG.info("Found '{}' matches for query", results.getTotalMatches());

        for (Hit hit: results.getHits()) {

            // The query returns the jcr:content node, so we need its parent.
            Resource page = hit.getResource().getParent();
            GeometrixxMediaContentType contentType = page.adaptTo(GeometrixxMediaPage.class);

            if (contentType != null) {
                solrDocs.add(contentType.getJson());
            }
        }

    } catch (RepositoryException e) {
        LOG.error("Error getting repository", e);
    } finally {
        if (session != null && session.isLive())  {
            session.logout();
        }
    }

    response.getWriter().write(solrDocs.toJSONString());
}