Help on using Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server"); | Community
Skip to main content
Level 6
October 16, 2015
Solved

Help on using Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

  • October 16, 2015
  • 4 replies
  • 2812 views
I am trying to update an xtype selection on a component.
 
I want to dynamically create the nodes for values under the select node's options so that the authors can select the values that are dynamically populated.
 
I decided to try the approach of creating and deleting nodes in the JCR  for the dialog.
 
However, when I try create a session to the jcr in AEM 6 from my component's jsp page using the following code 
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server"); 
 
I get an error in the error.log as  (AEM 6 is definitely running)
 
Unable to access a repository with the following settings:
    org.apache.jackrabbit.repository.uri: http://localhost:4502/crx/server
The following RepositoryFactory classes were consulted:
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:223)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263)
at org.apache.jsp.apps.Checkers_co_za.components.cards.Specials_002dCard.Specials_002dCard_jsp._jspService(Specials_002dCard_jsp.java:178)
at org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
... 219 common frames omitted
 
I am using the following jcr imports on my jsp page
 
<%@page import="javax.jcr.Repository"%
<%@page import="javax.jcr.Session"%> 
<%@page import="javax.jcr.SimpleCredentials"%>
<%@page import="javax.jcr.Node"%> 
<%@page import="org.apache.jackrabbit.commons.JcrUtils"%>
 
 
Regards
 
Clive Stewart
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

See the community article that gets at the local JCR from a component. 

http://helpx.adobe.com/experience-manager/using/creating-custom-cq-tree.html

It populates the front end component with data from the JCR. 

Also - from an OSGi component (or JSP) never use:

//Create a connection to the Adobe Day CQ repository running on local host 
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

This code is used when you want to get at the JCR from an external Java app - like a console app or a Swing app. For details about how to write a Java Swing app that that pull up data from an AEM JCR -- see:

http://helpx.adobe.com/experience-manager/using/java-swing-applications.html

To properly get at the JCR from within an OSGi component - use:

resourceResolver.adaptTo(Session.class);

To learn how to write an OSGi component that uses this code to retrieve JCR Data:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

4 replies

Runal_Trivedi
Level 6
October 16, 2015

Hi Clive,

If your need is to only list down the select options dynamically then you can also drive it from servlet of JSP file.

refer to foundations, list component - /libs/foundation/components/list/dialog/items/list/items/displayAs to know how you can do it.

Also can you put down the details why you are trying to get repository reference? if you simply want to drive drop down options from somewhere else in repository like etc/dropdownnodes/node1 etc.. then you can directly get the parent node reference using Resourceresolver and if you are to consider permissions before getting the nodes options then as Fieke suggested don't use admin session, rather use logged-in user session.

- Runal

Level 6
October 16, 2015

Use the below code to create session

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null); Session session = resourceResolver.adaptTo(Session.class);
smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

See the community article that gets at the local JCR from a component. 

http://helpx.adobe.com/experience-manager/using/creating-custom-cq-tree.html

It populates the front end component with data from the JCR. 

Also - from an OSGi component (or JSP) never use:

//Create a connection to the Adobe Day CQ repository running on local host 
Repository repository = JcrUtils.getRepository("http://localhost:4502/crx/server");

This code is used when you want to get at the JCR from an external Java app - like a console app or a Swing app. For details about how to write a Java Swing app that that pull up data from an AEM JCR -- see:

http://helpx.adobe.com/experience-manager/using/java-swing-applications.html

To properly get at the JCR from within an OSGi component - use:

resourceResolver.adaptTo(Session.class);

To learn how to write an OSGi component that uses this code to retrieve JCR Data:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

hi clive,

The code that you have is used to connect to another/external JcrRepository.

From your JSP/component you can do this:

resource.getResourceResolver().adaptTo(Session.class)

This then uses the session of the current user (and his permissions).

And yes you can also use the 'admin resource-resolver', but try to avoid that unless there is a real need for it.

--
feike