Question

I am running Grails 1.3.7; I have server A that needs to make a POST request on server B. I am using the http-builder library to make these requests. The request seems to be composed correctly

RESTClient http = new RESTClient( searchServerUrl );

Map body = ...;     
logger.trace("request: ${request}, body: ${body}")
def response = http.post( path: request, body: body, requestContentType: URLENC)
logger.trace("response: ${response}");
return response;

Server B performs the computation correctly, and returns a JSON structure to server A. When Server A tries to parse it, I see a long stack of exceptions rooted here:

Caused by: java.lang.NoClassDefFoundError: groovy/json/JsonSlurper
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
... 145 more

EDITED The http-builder library comes with groovy-1.8.8.jar in its dependencies folder, but I would rather use the standard Groovy library (v. 1.7.8) that comes with my Grails runtime. Unfortunately, the groovy.json namespace doesn't seem to be there. What should I do?

Was it helpful?

Solution

Because http-builder-0.6 is based on Groovy 1.8.8, it assumes that the JSONSlurper class is available with the Groovy libraries. Since I was using a version of Grails that comes with Groovy 1.7.8, I did not have that library. At this stage there were two choices: upgrade the app to a more recent grails version, or downgrade the http-builder library to one that includes the JSON classes explicitly. I opted for the second solution (upgrading from Grails 1.3.7 to 2.2 is not trivial), and was able to get my code to work with http-builder-0.5.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top