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());
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:
You can also use Apache HttpClient or OkHttp
source share