How to call a web service from Ant script or from within Jenkins?
Asked Answered
D

4

7

I am using Ant Script in Jenkins to handle the deployment of my files. What I want to do is to trigger a call to a URL that has the web service. My question is, how can I do that from Ant Script or from within Jenkins?

Thanks in advance, Monte

Dido answered 28/11, 2011 at 22:34 Comment(0)
J
22

Option 1: "get" task

Ant's get task can be used to invoke web services, but it restricted to GET operations. Only works for very simple web services

Option 2: curl

Invoke the unix curl command to call the webservice (See this post for examples)

<target name="invoke-webservice">
    <exec executable="curl">
        <arg line="-d 'param1=value1&param2=value2' http://example.com/resource.cgi"/>
    </exec>
</target>

Note:

The curl command could also be invoked as a post build action in Jenkins

Option 3: Groovy ANT task

If you need a cross platform and flexible solution embed groovy script within your build to invoke the web service.

<target name="invoke-webservice">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
        import static groovyx.net.http.ContentType.JSON
        import groovyx.net.http.RESTClient

        def client = new RESTClient("http://localhost:5498/")
        def response = client.put(path: "parking_tickets",
                                  requestContentType: JSON, 
                                  contentType: JSON)

        log.info "response status: ${response.status}"
    </groovy>
</target>

Option 4: Groovy Jenkins post build

Use the Groovy Postbuild plugin to invoke the web service.

Option 5: ANT HTTP task

The ANT HTTP task is an alternative to the groovy task above

Jallier answered 29/11, 2011 at 20:54 Comment(0)
G
0

You can:

  1. Implement a WebService Client with Java (by example Netbeans can generate it in seconds).
  2. Upload the jar of the client to subversion where can be accesible from Jenkins.
  3. Execute the client from ANT.
     <target name="run">
          <java jar="ws_client/WSClient.jar"/>
     </target> 
Grevera answered 28/11, 2011 at 22:45 Comment(2)
Thank you for your quick response. In my case though, the web service would be written in ColdFusion instead of Java.Dido
The language agnostic nature of Webservices, let you write the client of the web service in any language. My recomendation is to pick the language that will be most comfortable for you.Grevera
H
0

Related to question - how to call WebServices from Ant. In my case, Anteater helped to properly call and receive response from semi-complicated case. http://aft.sourceforge.net/index.html

<soapRequest>

Is the task you might want to take a look at.

Hardecanute answered 18/7, 2012 at 12:44 Comment(0)
T
0

Take a look at Groovy-wslite. The project page can be found here. Works like a charm, easy to integrate and intuitive to use. I've had a similar problem today and put some example code in my question / answer: Axis2 with complexTypes in Groovy

Tragedienne answered 9/10, 2012 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.