2

I am invoking JsonBuilder.toString() in Groovy code inside a Camel route. This Camel route runs inside Widlfly Camel 12.0. The code looks like so:

def builder = new JsonBuilder()
builder {
'myField': myFieldVal
}
return builder.toString()

The builder.toString() method invocation produces the following error:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
groovy.json.internal.FastStringUtils

But I do have the dependencies mentioned properly in pom.xml like so:

<dependency>
 <groupId>org.apache.camel</groupId>
 <artifactId>camel-groovy</artifactId>
 <scope>provided</scope>
</dependency>

I also tried adding this extra dependency to resolve the problem:

<dependency>
 <groupId>org.codehaus.groovy</groupId>
 <artifactId>groovy-json</artifactId>       
 <version>2.4.13</version>
</dependency>

But I still keep on getting the above exception. However when I run the same Camel code using the camel-maven-plugin, without deploying it inside Wildfly, it runs perfectly.

Can someone please help?

Thanks in advance.

sanjbh
  • 45
  • 1
  • 6

1 Answers1

2

I think the problem is that module org.apache.camel.script.groovy cannot access sun.misc.Unsafe. So I added the following module dependency to modules/system/layers/fuse/org/apache/camel/script/groovy/main/module.xml.

<module name="sun.jdk">
  <imports>
    <include path="sun/misc/Unsafe"/>
  </imports>
</module>

Your example worked for me afterwards.

James Netherton
  • 1,092
  • 1
  • 7
  • 9
  • Hi James, thank you so much for your help. How did you find out that the module org.apache.camel.script.groovy cannot access sun.misc.Unsafe? I wish I had debugging skills half as good as you. – sanjbh May 22 '18 at 14:28
  • 1
    Hi - Glad you got it working. I noticed on the first request that it complained about sun.misc.Unsafe then afterwards it threw the error about FastStringUtils. The problem should be fixed in the next release https://github.com/wildfly-extras/wildfly-camel/issues/2536. – James Netherton May 22 '18 at 15:10