Jenkins Webservice

I need to write a webservice client and call him from Jenkins. Below are my questions:

  • What is the best way to call a web service from Jenkins? Is any standard version available? I need to pass XML data as input to a web service.
  • If the plugin is not an option, can you tell me what are other ways to achieve this (ANT + JAVA, etc.)?
  • If you have sample code, this will be great.

Thanks Arawind

+6
source share
2 answers

It would be great to know that you just need to call your client as part of some complex stream implemented as Jenkins task, or you want to concentrate on testing web services.

WillieT pointed you to some simple recipes that can be used to solve some basic problems. If you need more energy, better reporting, some additional features, please consider the following:

Apache JMeter ( details )

JMeter can be integrated into Jenkins using the Performance Plugin . Report Example:

enter image description here

Grinder ( details )

I prefer to use this tool, but it can be difficult / heavy for you.

Grinder can be integrated into Jenkins using the Grinder plugin . Report Example:

enter image description here

+3
source

If you are developing a plugin, for example. extends hudson.tasks.Builder, include the following in pom.xml for the JAX-RS client:

<dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.25.1</version> </dependency> 

JAX-RS Client Sample:

 import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.glassfish.jersey.client.ClientConfig; public class RestClient { private static String BASE_URL = "http://localhost:8090/rest"; private static String ACCESS_TOKEN = "8900***bc1"; public static String query(String path) { ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(getBaseURI()); // token authentication String result = target.path(path).request().header("Authorization", "Token " + ACCESS_TOKEN) .accept(MediaType.APPLICATION_JSON).get(String.class); return result; } private static URI getBaseURI() { return UriBuilder.fromUri(BASE_URL).build(); } } 

where http: // localhost: 8090 / rest is the base URL for relaxing outside the Jenkins environment. Anywhere in your plugin code, you can simply call it as needed:

 String rsData = RestClient.query("/project_type"); 

Suppose the full URL of a holiday web service

 http://localhost:8090/rest/project_type 

You can also use Apache HttpClient or OkHttp

0
source

All Articles