如何在grails中安装和使用httpbuilder插件

时间:2011-09-11 16:03:32

标签: grails groovy httpbuilder

如何在Grails中安装和使用httpbuilder插件?

3 个答案:

答案 0 :(得分:28)

将httpbuilder 0.5.1添加到您的应用程序依赖项将导致错误。特别是,你会收到类似这样的错误:

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

我认为问题在于httpbuilder将其编译时依赖项导出为运行时依赖项。一个简单的解决方法是在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'
        }
    }
}   

我认为您在存储库部分也需要mavenRepo "http://repository.codehaus.org"

答案 1 :(得分:5)

REST Client plugin

  • 安装:

    grails install-plugin rest
    
  • 示例:

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

答案 2 :(得分:0)

我最终在ataylor上使用了上述步骤,但随后注释掉了块并测试了插件:

compile ":rest:0.7"

Rest插件使用http-builder而没有上述依赖性我的应用程序仍然正常工作并通过http builder进行调用。