outofcoffee / imposter

Scriptable, multipurpose mock server. Run standalone mock servers, or embed mocks within your tests.

Home Page:https://imposter.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Precompiling js script files fails from docker container

gkontos opened this issue · comments

When running the container 'outofcoffee/imposter-all:3.36.0' with a script, the following error is encountered:

20:06:34 DEBUG i.g.i.s.n.s.NashornScriptServiceImpl - Precompiling script: /opt/imposter/config/scripts/myscript.js
Exception in thread "DefaultDispatcher-worker-1" com.google.common.util.concurrent.ExecutionError: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.FieldVisitor, but class was expected
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2053)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3966)
	at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4863)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.getCompiledScript(NashornScriptServiceImpl.kt:171)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.initScript(NashornScriptServiceImpl.kt:105)
	at io.gatehill.imposter.scripting.common.service.DelegatingJsScriptServiceImpl.initScript(DelegatingJsScriptServiceImpl.kt:86)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.initScriptFilesAndSteps(ScriptedResponseServiceImpl.kt:149)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.initScripts(ScriptedResponseServiceImpl.kt:125)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.afterRoutesConfigured(ScriptedResponseServiceImpl.kt:110)
	at io.gatehill.imposter.Imposter$configureRoutes$5.invoke(Imposter.kt:228)
	at io.gatehill.imposter.Imposter$configureRoutes$5.invoke(Imposter.kt:227)
	at io.gatehill.imposter.lifecycle.LifecycleHooks.forEach(LifecycleHooks.kt:77)
	at io.gatehill.imposter.Imposter.configureRoutes(Imposter.kt:227)
	at io.gatehill.imposter.Imposter.access$configureRoutes(Imposter.kt:88)
	at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:135)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@2c1cd0b0, Dispatchers.Default]
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.FieldVisitor, but class was expected
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.field(ClassEmitter.java:606)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.field(ClassEmitter.java:619)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.defineCommonStatics(ClassEmitter.java:270)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.<init>(ClassEmitter.java:210)
	at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:766)
	at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:774)
	at org.openjdk.nashorn.internal.codegen.Compiler.addCompileUnit(Compiler.java:759)
	at org.openjdk.nashorn.internal.codegen.CompilationPhase$SplittingPhase.transform(CompilationPhase.java:117)
	at org.openjdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:614)
	at org.openjdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:641)
	at org.openjdk.nashorn.internal.runtime.Context.compile(Context.java:1531)
	at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:785)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine.asCompiledScript(NashornScriptEngine.java:486)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compile(NashornScriptEngine.java:178)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.getCompiledScript$lambda$3(NashornScriptServiceImpl.kt:180)
	at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4868)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3533)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2282)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049)
	... 20 more

The script in question was simplified to

var requestStore = stores.open('myRequest');

respond()
    .usingDefaultBehaviour()

This error does not occur when running the same version of imposter through the CLI or Jar files when running with openJDK 19 or jdk-22.

I hit the same issue. It does work with the outofcoffee/imposter image, but https://docs.imposter.sh/scripting_modern_js/ recommended to use the gral-js plugin which I hoped would be included in the outofcoffee/imposter-all image.

Ah! We didn't try the gral-js plugin, just the default js. We were using imposter-all for the faker plugin.

Hi @gkontos and @rnestler - thank you for raising this and investigating.

This is caused by a clash between some of the plugins included in the all distro. Whilst we work on fixing that, there's an interim solution where the all distro now includes the js-graal plugin as suggested by @rnestler.

This is released in v3.36.1.

It looks like the work-around you used (specifying the IMPOSTER_JS_PLUGIN=js-graal environment variable) avoids this issue in v3.36.1.

The underlying issue with the plugin conflict in the all distro should be fixed in v3.36.2.

Please let me know if this resolves the issue.

v3.36.2 fixes the issue for me. I was wondering why graal-js isn't the default though. It was very surprising to me, that the JS scripting didn't support "modern" features by default.

The update resolves the issue for me too. Thanks!