How to install and use httpbuilder plugin in grails

 ̄綄美尐妖づ 提交于 2019-12-03 20:07:48

There is the REST Client plugin:

  • Installation:

    grails install-plugin rest
    
  • Example:

    withHttp(uri: "http://www.google.com") {
       def html = get(path : '/search', query : [q:'Groovy'])
       assert html.HEAD.size() == 1
       assert html.BODY.size() == 1
    }
    

Adding httpbuilder 0.5.1 to your application dependencies will cause errors. In particular, you'll get an error something like this:

java.lang.LinkageError: loader constraint violation: when resolving overridden method "org.apache.xerces.jaxp.SAXParserImpl.getParser()Lorg/xml/sax/Parser;" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/xerces/jaxp/SAXParserImpl, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/Parser used in the signature

I think the issue is that httpbuilder is exporting it's compile-time dependencies as runtime dependencies. An easy workaround is to declare the dependency like this in your BuildConfig.groovy:

grails.project.dependency.resolution = {
    ...
    dependencies {
        runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.1') {
            excludes 'xalan'
            excludes 'xml-apis'
            excludes 'groovy'
        }
    }
}   

I think you need mavenRepo "http://repository.codehaus.org" in the repositories section as well.

I ended up using the above step by ataylor but then commented out the block and tested plugin:

compile ":rest:0.7"

Rest plugin uses http-builder and without having the above dependancy my app still works fine and makes calls through http builder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!