Maven插件来调用或调用其他Web服务 [英] maven plugin to call or invoke a rest web service

查看:71
本文介绍了Maven插件来调用或调用其他Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何Maven插件将调用现有的剩余Web服务?否则,可以使用任何方法在pom.xml中调用Web服务. 就像我们调用外部命令一样 org.codehaus.mojo exec-maven-plugin 1.2 请帮助我

Is there any maven plugin which will be invoking already existing rest web service? or else is there any way to invoke a web service in pom.xml. like we have for invoking a external command org.codehaus.mojo exec-maven-plugin 1.2 please help me

推荐答案

如果需要使用POST方法调用REST服务,则可以使用groovy脚本

If you need invoke a REST service using a POST method, you can use a groovy script

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myspotontheweb.demo</groupId>
    <artifactId>maven-rest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy.modules.http-builder</groupId>
            <artifactId>http-builder</artifactId>
            <version>0.5.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>execute</goal>
                      </goals>
                       <configuration>
                          <source>
                            import groovyx.net.http.RESTClient
                            import groovy.util.slurpersupport.GPathResult
                            import static groovyx.net.http.ContentType.XML

                            solr = new RESTClient('http://localhost:8080/solr/update')

                            def response = solr.post(
                                contentType: XML,
                                requestContentType: XML,
                                body: {
                                    add {
                                        doc {
                                            field(name:"id", "SOLR1000")
                                            field(name:"name", "Solr, the Enterprise Search Server")
                                            field(name:"manu", "Apache Software Foundation")
                                            field(name:"cat", "software")
                                            field(name:"cat", "search")
                                            field(name:"features", "Advanced Full-Text Search Capabilities using Lucene")
                                            field(name:"features", "Optimized for High Volume Web Traffic")
                                            field(name:"features", "Standards Based Open Interfaces - XML and HTTP")
                                            field(name:"features", "Comprehensive HTML Administration Interfaces")
                                            field(name:"features", "Scalability - Efficient Replication to other Solr Search Servers")
                                            field(name:"features", "Flexible and Adaptable with XML configuration and Schema")
                                            field(name:"features", "Good unicode support: héllo (hello with an accent over the e)")
                                            field(name:"price", "0")
                                            field(name:"popularity", "10")
                                            field(name:"inStock", "true")
                                            field(name:"incubationdate_dt", "2006-01-17T00:00:00.000Z")
                                        }
                                    }
                                }
                            )
                            log.info "Solr response status: ${response.status}"
                         </source>
                     </configuration>
                 </execution>
              </executions>
         </plugin>
    </plugins>
    </build>
</project>

REST API示例摘自休伯特·克莱因·伊金克(Hubert Klein Ikkink)的博客:

The REST API example was taken from Hubert Klein Ikkink's blog:

http://mrhaki.blogspot.com/

这篇关于Maven插件来调用或调用其他Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆