How to install and use httpbuilder plugin in Grails?
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.
来源:https://stackoverflow.com/questions/7379455/how-to-install-and-use-httpbuilder-plugin-in-grails