java - Programmatically Accessing CQ5 Content using the JCR -
i access content programmatically, tried following:
private session getsession(string user, string passwort) { session session = null; try { repository repository = jcrutils.getrepository("http://localhost:4503/crx/server"); jcrutils.getrepository("http://localhost:4503/crx/server"); session = repository.login(new simplecredentials(user, passwort.tochararray())); } catch (repositoryexception e) { log.error(e.getmessage()); } return session; }
i following exception when call getrepository
method:
javax.jcr.repositoryexception: unable access repository following settings: org.apache.jackrabbit.repository.uri: http://localhost:4503/crx/server following repositoryfactory classes consulted: perhaps repository trying access not available @ moment.
i have version cq5.4. idea?
p.s: tried access publish , author instance , got same exception.
you don't need , don't want call jcrutils.getrepository
in sling/cq app, should rather access slingrepository osgi service cq provides.
the simplest use @reference
annotation in osgi declarative services @component
- there multiple examples of in apache sling codebase, http://svn.apache.org/repos/asf/sling/trunk/samples/slingbucks sample starting point that.
if code executes part of request processing, don't need create session yourself, can calling request.getresourceresolver().adaptto(session.class)
request
slinghttpservletrequest
in sling servlet.
Comments
Post a Comment