Reputation: 61
I need to write a webservice client and call it from Jenkins. Below are my questions:
Thanks Aravind
Upvotes: 6
Views: 11770
Reputation: 391
I used 'HTTP Request' Plugin. This plugin works for REST as well as SOAP api.
enter image description here
Plugin image
Upvotes: 0
Reputation: 10668
If you develop a plugin, e.g. extends hudson.tasks.Builder, include the following in pom.xml for 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>
A sample JAX-RS Client:
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 rest url outside of Jenkins environment. Anywhere in your plugin code, you can simple call this as needed:
String rsData = RestClient.query("/project_type");
assume the full rest web service url is
http://localhost:8090/rest/project_type
You may also use Apache HttpClient, or OkHttp
Upvotes: 0
Reputation: 17895
It would be great to know you just need to call your client as part of some complex flow, implemented as a Jenkins job, or you want to concentrate on webservice testing.
WillieT has pointed you to several simple recipes which can be used to solve some basic tasks. If you need more power, better reporting, some additional features please consider the following:
Apache JMeter (details)
JMeter can be integrated into Jenkins using Performance plugin. Report example:
Grinder (details)
I prefer to use this tool, but it might be to complex/heavy for you.
Grinder can be integrated into Jenkins using Grinder plugin. Report example:
Upvotes: 3