3

How to install and use httpbuilder plugin in Grails?

ataylor
  • 64,891
  • 24
  • 161
  • 189
user903772
  • 1,554
  • 5
  • 32
  • 55
  • There's no plugin named "httpbuilder". There's a [REST Client](http://www.grails.org/plugin/rest) plugin, though. Was there something unclear about its installation or usage in the [documentation](http://www.grails.org/plugin/rest)? Your question is rather broad. – Rob Hruska Sep 11 '11 at 16:15

3 Answers3

28

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.

ataylor
  • 64,891
  • 24
  • 161
  • 189
5

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
    }
    
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
0

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.

V H
  • 8,382
  • 2
  • 28
  • 48