Explorer Lib not working

Enonic version: 7.10.3
OS: Windows
Sandbox: Locally

I’ve been trying to expose the indexed data from the Explorer application via a service.
From the “Explorer Client starter” (Explorer Client starter - Enonic Developer Portal) I found the service “searchDefaultInterface” which should expose the data.

Deploying that app to my current app/sandbox did not work as any service that is using “.es” file ending does not work when trying to reach the endpoint with urls such as:

localhost:8080/site/${projectName}/master/${siteName}/_/service/${appName}/${serviceName}

I scrapped the idea of using this old(?) “Explorer Client starter” application and rather moved the service over to my headless CMS app.
When changing the file type to “.js” it will complain about not supporting ECMAscript 6 and you’ll have to rewrite it to a ES5-friendly format. This is the curret rewrite for the service in order to work with ES5:

const libExplorer = require("/lib/explorer"); // Make sure this is included in build.gradle

exports.get = function (req) {
  const count = req.params.count || 10;
  const searchString = req.params.q || "";

  return {
    body: libExplorer.search({
      count: count,
      interface: "default",
      searchString: searchString,
    }),
    contentType: "application/json;charset=utf-8",
  };
};

All dependencies are included as pr Explorer API - Enonic Developer Portal.
I have not found any traces of a different version of the Explorer lib than “3.20.1” as stated on that page.

Deploying this makes the service work, but return the following:

2022-10-20 13:30:17,128 ERROR c.e.x.p.i.e.ExceptionRendererImpl - TypeError: Number.isInteger is not a function
com.enonic.xp.web.WebException: TypeError: Number.isInteger is not a function```

Full trace:

2022-10-20 14:00:12,665 ERROR c.e.x.p.i.e.ExceptionRendererImpl - TypeError: Number.isInteger is not a function
com.enonic.xp.web.WebException: TypeError: Number.isInteger is not a function
        at com.enonic.xp.web.impl.exception.ExceptionMapperImpl.map(ExceptionMapperImpl.java:33)
        at com.enonic.xp.portal.handler.BasePortalHandler.handleError(BasePortalHandler.java:60)
        at com.enonic.xp.portal.handler.BasePortalHandler.doHandle(BasePortalHandler.java:52)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:66)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.impl.trace.TraceWebFilter.doHandle(TraceWebFilter.java:38)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:66)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.impl.handler.WebDispatcherImpl.dispatch(WebDispatcherImpl.java:35)
        at com.enonic.xp.web.impl.handler.WebDispatcherServlet.doHandle(WebDispatcherServlet.java:140)
        at com.enonic.xp.web.impl.handler.WebDispatcherServlet.service(WebDispatcherServlet.java:68)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at com.enonic.xp.web.impl.dispatch.mapping.ServletDefinitionImpl.service(ServletDefinitionImpl.java:40)
        at com.enonic.xp.web.impl.dispatch.pipeline.ServletPipelineImpl.service(ServletPipelineImpl.java:38)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:51)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at com.enonic.xp.portal.impl.idprovider.IdProviderFilter.doHandle(IdProviderFilter.java:46)
        at com.enonic.xp.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:31)
        at com.enonic.xp.web.filter.BaseWebFilter.doFilter(BaseWebFilter.java:33)
        at com.enonic.xp.web.impl.dispatch.mapping.FilterDefinitionImpl.doFilter(FilterDefinitionImpl.java:41)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at com.enonic.xp.web.impl.context.ContextFilter.lambda$doHandle$0(ContextFilter.java:34)
        at com.enonic.xp.context.ContextImpl.callWith(ContextImpl.java:100)
        at com.enonic.xp.web.impl.context.ContextFilter.doHandle(ContextFilter.java:33)
        at com.enonic.xp.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:31)
        at com.enonic.xp.web.filter.BaseWebFilter.doFilter(BaseWebFilter.java:33)
        at com.enonic.xp.web.impl.dispatch.mapping.FilterDefinitionImpl.doFilter(FilterDefinitionImpl.java:41)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at com.enonic.xp.web.vhost.impl.VirtualHostFilter.doHandle(VirtualHostFilter.java:73)
        at com.enonic.xp.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:31)
        at com.enonic.xp.web.filter.BaseWebFilter.doFilter(BaseWebFilter.java:33)
        at com.enonic.xp.web.impl.dispatch.mapping.FilterDefinitionImpl.doFilter(FilterDefinitionImpl.java:41)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at com.enonic.xp.web.impl.dos.DosFilterWrapper.doFilter(DosFilterWrapper.java:65)
        at com.enonic.xp.web.impl.dispatch.mapping.FilterDefinitionImpl.doFilter(FilterDefinitionImpl.java:41)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at org.eclipse.jetty.servlets.HeaderFilter.doFilter(HeaderFilter.java:117)
        at com.enonic.xp.web.impl.header.HeaderFilterWrapper.doHandle(HeaderFilterWrapper.java:51)
        at com.enonic.xp.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:31)
        at com.enonic.xp.web.filter.BaseWebFilter.doFilter(BaseWebFilter.java:33)
        at com.enonic.xp.web.impl.dispatch.mapping.FilterDefinitionImpl.doFilter(FilterDefinitionImpl.java:41)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:33)
        at com.enonic.xp.web.impl.dispatch.pipeline.FilterPipelineImpl.filter(FilterPipelineImpl.java:37)
        at com.enonic.xp.web.impl.dispatch.DispatchServletImpl.service(DispatchServletImpl.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:554)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
        at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:772)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:516)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
        at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.enonic.xp.resource.ResourceProblemException: TypeError: Number.isInteger is not a function
        at com.enonic.xp.resource.ResourceProblemException$Builder.build(ResourceProblemException.java:131)
        at com.enonic.xp.script.impl.util.ErrorHelper.doHandleException(ErrorHelper.java:54)
        at com.enonic.xp.script.impl.util.ErrorHelper.handleError(ErrorHelper.java:27)
        at com.enonic.xp.script.impl.value.FunctionScriptValue.call(FunctionScriptValue.java:41)
        at com.enonic.xp.script.impl.executor.ScriptExportsImpl.executeMethod(ScriptExportsImpl.java:59)
        at com.enonic.xp.portal.impl.controller.ControllerScriptImpl.doExecute(ControllerScriptImpl.java:71)
        at com.enonic.xp.portal.impl.controller.ControllerScriptImpl.lambda$execute$0(ControllerScriptImpl.java:36)
        at com.enonic.xp.trace.Tracer.traceEx(Tracer.java:72)
        at com.enonic.xp.trace.Tracer.trace(Tracer.java:51)
        at com.enonic.xp.trace.Tracer.trace(Tracer.java:98)
        at com.enonic.xp.portal.impl.controller.ControllerScriptImpl.execute(ControllerScriptImpl.java:36)
        at com.enonic.xp.portal.impl.handler.service.ServiceHandlerWorker.execute(ServiceHandlerWorker.java:101)
        at com.enonic.xp.portal.impl.handler.service.ServiceHandler.doHandle(ServiceHandler.java:65)
        at com.enonic.xp.portal.impl.handler.service.ServiceHandler.doHandle(ServiceHandler.java:24)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:66)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.web.handler.BaseWebHandler.handle(BaseWebHandler.java:75)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.portal.impl.handler.mapping.MappingHandler.handle(MappingHandler.java:84)
        at com.enonic.xp.web.impl.handler.WebHandlerChainImpl.handle(WebHandlerChainImpl.java:28)
        at com.enonic.xp.portal.handler.BasePortalHandler.doHandle(BasePortalHandler.java:46)
        ... 86 common frames omitted
Caused by: jdk.nashorn.internal.runtime.ECMAException: TypeError: Number.isInteger is not a function
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Undefined.lookup(Undefined.java:100)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:106)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96)
        at jdk.dynalink/jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:161)
        at jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:109)
        at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(LinkerServicesImpl.java:137)
        at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(LinkerServicesImpl.java:168)
        at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:135)
        at jdk.dynalink/jdk.dynalink.DynamicLinker.relink(DynamicLinker.java:242)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1979$35121A$buildHighlights.L:1#\==\_\!1#\==\_\!1051#isNumber(no.sio:/lib/explorer/client/buildHighlights.js:1100)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1978$35343AA$buildHighlights.L:1#\==\_\!1#\==\_\!1051#splitString(no.sio:/lib/explorer/client/buildHighlights.js:1132)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1977$36337$buildHighlights.L:1#\==\_\!1#\==\_\!1051#split#L:1150(no.sio:/lib/explorer/client/buildHighlights.js:1151)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1973$34881AAA$buildHighlights.L:1#\==\_\!1#\==\_\!1051#memoize(no.sio:/lib/explorer/client/buildHighlights.js:1091)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1972$36271AA$buildHighlights.L:1#\==\_\!1#\==\_\!1051#split(no.sio:/lib/explorer/client/buildHighlights.js:1150)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1968$36876AAAA$buildHighlights.L:1#\==\_\!1#\==\_\!1051#setValue(no.sio:/lib/explorer/client/buildHighlights.js:1178)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1963$39619A$buildHighlights.L:1#\==\_\!1#\==\_\!1247#buildHighlights#L:1280(no.sio:/lib/explorer/client/buildHighlights.js:1325)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:657)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
        at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeArray$9.forEach(NativeArray.java:1577)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.arrays.IteratorAction.apply(IteratorAction.java:110)
        at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeArray.forEach(NativeArray.java:1580)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1962$39494A$buildHighlights.L:1#\==\_\!1#\==\_\!1247#buildHighlights(no.sio:/lib/explorer/client/buildHighlights.js:1280)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1890$36287A$index.L:1#\==\_\!1#\==\_\!1164#search(no.sio:/lib/explorer/client/index.js:1478)
        at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$1889$165A$searchDefaultInterface/0x000000080129f040.L:1#get(no.sio:/services/searchDefaultInterface/searchDefaultInterface.js:8)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:657)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
        at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
        at jdk.scripting.nashorn/jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:120)
        at com.enonic.xp.script.impl.value.FunctionScriptValue.call(FunctionScriptValue.java:36)
        ... 111 common frames omitted

Which version of lib-explorer are you using?

lib-explorer is supposed to polyfill Number.isInteger, because Nashorn doesn’t have it…

Number.isInteger = Number.isInteger || function(value) {
	return typeof value === 'number' &&
	isFinite(value) &&
	Math.floor(value) === value;
};

The newest is 3.20.6
https://repo.enonic.com/service/rest/repository/browse/public/com/enonic/lib/lib-explorer/3.20.6/

The polyfill

The alias

Global is always polyfilled

But Number.isInteger is only selectively polyfilled, example:

Looks like I forgot to do that here:

I actually have an issue, I’ll up the priority in it:

It might be that if you upgrade lib-explorer to a version newer than 3.20.3, then your problem goes away?

@JonasR did you figure this one out?

Upgrading to 3.20.6 did indeed fix it!
Like I mentioned I was unable to find different versions (Google didn’t want to display the github result for some reason) so 3.20.3 was all I found (via the docs).

1 Like

so 3.20.3 was all I found (via the docs).

Do we mention specific version number anywhere in the docs?

These two mention 3.20.1

and then I think I found the 3.20.3 via the “Explorer Client starter” (project)

Thanks for letting us know. I have upped version in the starter and the docs, and also added a note in both places in the docs saying that developers should make sure that they are using the latest released version (as docs won’t be automatically updated with every new release).