How to install and use httpbuilder plugin in Grails?
            Asked
            
        
        
            Active
            
        
            Viewed 9,683 times
        
    3
            
            
        - 
                    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 Answers
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 restExample:
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
 
- 
                    
 - 
                    4I haven't read the docs or ever used this plugin, but my uneducated guess would be to replace `get` with `post` – Dónal Sep 12 '11 at 14:33
 - 
                    Note that as of 2.3, `install-plugin can no longer be used to install plugins`. I'm still trying to figure out this one now, and I really miss node/npm :( – Mark K Cowan Jul 03 '14 at 19:41
 
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