Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Session being closed before access content with query builder on Publish environment

Avatar

Avatar
Validate 10
Level 3
elizabethp60981
Level 3

Likes

8 likes

Total Posts

42 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 3
elizabethp60981
Level 3

Likes

8 likes

Total Posts

42 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
elizabethp60981
Level 3

26-02-2018

Hi,

I have a WCMUsePojo class that uses query builder. To create a session I am doing this.

ResourceResolver  resolver = getResourceResolver();

    Session session = resolver.adaptTo(Session.class);

Query query = builder.createQuery(PredicateGroup.create(map), session);

This works fine on author, but returns an http error 500 on publish environment.

I was looking on the internet that I should do this with SlingRepository, is that right?

I have this code below, and I am not sure what this sling var is.

SlingRepository repos = sling.getService(SlingRepository.class);

The log gives me the error below.

26.02.2018 20:33:34.749 *ERROR* [0:0:0:0:0:0:0:1 [1519673614703] GET /content/latam-portal-agencias/es_cl/contingencias.html HTTP/1.1] org.apache.sling.engine.impl.DefaultErrorHandler Error handler failed:java.io.IOException

java.io.IOException: Error handler failed: org.apache.sling.api.SlingException

    at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:765)

    at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:492)

    at org.apache.sling.engine.impl.DefaultErrorHandler.handleError(DefaultErrorHandler.java:133)

    at org.apache.sling.engine.impl.SlingRequestProcessorImpl$2.render(SlingRequestProcessorImpl.java:377)

    at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:77)

    at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83)

    at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

    at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)

    at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:68)

    at org.apache.sling.engine.impl.SlingRequestProcessorImpl.handleError(SlingRequestProcessorImpl.java:384)

    at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:186)

    at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:219)

    at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:85)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:79)

    at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:308)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:96)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:295)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:138)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:72)

    at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:135)

    at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:74)

    at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:128)

    at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)

    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)

    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)

    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)

    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)

    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)

    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)

    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)

    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)

    at org.eclipse.jetty.server.Server.handle(Server.java:499)

    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)

    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)

    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)

    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)

    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)

    at java.lang.Thread.run(Unknown Source)

Caused by: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: This session has been closed

    at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:510)

    at org.apache.sling.servlets.resolver.internal.SlingServletResolver.handleError(SlingServletResolver.java:756)

    ... 51 common frames omitted

Caused by: java.lang.IllegalStateException: This session has been closed

    at com.google.common.base.Preconditions.checkState(Preconditions.java:150)

    at org.apache.jackrabbit.oak.core.ContentSessionImpl.checkLive(ContentSessionImpl.java:85)

    at org.apache.jackrabbit.oak.core.MutableRoot.checkLive(MutableRoot.java:174)

    at org.apache.jackrabbit.oak.core.MutableTree.beforeRead(MutableTree.java:333)

    at org.apache.jackrabbit.oak.core.MutableTree.getPath(MutableTree.java:108)

    at org.apache.jackrabbit.oak.plugins.tree.impl.AbstractTree.toString(AbstractTree.java:158)

    at org.apache.jackrabbit.oak.plugins.tree.impl.AbstractTree.toString(AbstractTree.java:153)

    at java.lang.String.valueOf(Unknown Source)

    at java.lang.StringBuilder.append(Unknown Source)

    at com.google.common.base.Objects$ToStringHelper.toString(Objects.java:398)

    at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.toString(NodeDelegate.java:877)

    at java.lang.String.valueOf(Unknown Source)

    at java.lang.StringBuilder.append(Unknown Source)

    at org.apache.jackrabbit.oak.jcr.session.ItemImpl.toString(ItemImpl.java:312)

    at org.apache.jackrabbit.oak.jcr.session.NodeImpl.toString(NodeImpl.java:106)

    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrItemResourceFactory.getSubitem(JcrItemResourceFactory.java:151)

    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrItemResourceFactory.createResource(JcrItemResourceFactory.java:94)

    at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProvider.getResource(JcrResourceProvider.java:300)

    at org.apache.sling.resourceresolver.impl.providers.stateful.AuthenticatedResourceProvider.getResource(AuthenticatedResourceProvider.java:135)

    at org.apache.sling.resourceresolver.impl.helper.ResourceResolverControl.getResource(ResourceResolverControl.java:223)

    at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getAbsoluteResourceInternal(ResourceResolverImpl.java:1045)

    at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getResourceInternal(ResourceResolverImpl.java:671)

    at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getResource(ResourceResolverImpl.java:642)

    at com.day.cq.wcm.core.impl.PageImpl.getContentResource(PageImpl.java:130)

    at com.day.cq.wcm.scripting.impl.WCMBindingsValuesProvider.addBindings(WCMBindingsValuesProvider.java:181)

    at org.apache.sling.scripting.core.impl.DefaultSlingScript.verifySlingBindings(DefaultSlingScript.java:735)

    at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:200)

    at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:184)

    at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:491)

    ... 52 common frames omitted

View Entire Topic

Avatar

Avatar
Give Back
Level 1
aem_raw
Level 1

Likes

2 likes

Total Posts

7 posts

Correct Reply

1 solution
Top badges earned
Give Back
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Give Back
Level 1
aem_raw
Level 1

Likes

2 likes

Total Posts

7 posts

Correct Reply

1 solution
Top badges earned
Give Back
Validate 1
Boost 1
Affirm 1
View profile
aem_raw
Level 1

26-02-2018

In WCMUsePojo class you can use

SlingRepository repos =getSlingScriptHelper().getService(SlingRepository.class);

to access SlingRepository API.

You can increase the search speed by creating custom indexes. Also please check other classes in the bundle whether you are properly closing resourceResolver which you instantiated  (In WCMUsePojo class you don't need to instantiate getResourceResolver( )   ).