gravitee-io / issues

Gravitee.io - API Platform - Issues
65 stars 26 forks source link

[policy] [groovy] Calling external rest api : Error Groovy script: startup failed #479

Open kkatta opened 7 years ago

kkatta commented 7 years ago

groovyScriptFailure-StackTrace.zip

Issue: I have the below groovy script to call an external Rest service for enrichment of response use case.

import groovy.json.JsonSlurper import groovy.json.JsonOutput import groovyx.net.http.RESTClient

localDictionary = new RESTClient('http://restmirror.appspot.com/') def new_word = "[name: 'bob', title: 'construction worker']" def resp = localDictionary.post(path : '', body : new_word, requestContentType : groovyx.net.http.ContentType.JSON)

def jsonSlurper = new JsonSlurper() def object = jsonSlurper.parseText(resp) return JsonOutput.toJson(object)

Current Behavior

Getting an error in the gateway API response: Unable to run Groovy script: startup failed: aab362f6d9919baba8f5c5e0c6f5759aa19976b8: 3: unable to resolve class groovyx.net.http.RESTClient @ line 3, column 1. import groovyx.net.http.RESTClient ^

1 error

Is the groovyx.net support OOTB. Attached the stacktrace

Thanks

NicolasGeraud commented 7 years ago

Hi @kkatta As you can see here https://github.com/gravitee-io/gravitee-policy-groovy/blob/master/pom.xml org.codehaus.groovy.modules.http-builder:http-builder is not part of the groovy plugin. If you need it, you have to install it in $GRAVITEE_GATEWAY_HOME/lib/ext

kkatta commented 7 years ago

Ok will try installing the library . Thanks

brasseld commented 7 years ago

As part of this issue, I think we have to consider a better way to let the user being able to "extend" the plugin / policy classloader by providing its own jar into a dedicated directory. By putting a new jar in $GRAVITEE_GATEWAY_HOME/lib/ext, the gateway classloader is directly impacted and I'm not sure that it's the ideal way.

bssaini001 commented 3 years ago

Is the above issue still present in API gateway 3.x version?