Spring

Spring is one of widest used libraries to build applications with in Java. The spring-web module comes with the client RestTemplate that can be used to manage the most advanced HTTP communications.

RestTemplate is the client object you will use to make the http call. Despite the somewhat confusing name RestTemplate, this is actually a plain HTTP client that you can use for other things besides REST calls. Create an instance like this:

RestTemplate restTemplate = new RestTemplate();

Make a GET request and receive the response as a String

ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8080", String.class);
System.out.println(response.getBody());

//output:
{"id":1,"content":"Hello World!"}

Deserialization of the response to pojo's is easily done with the jackson dependencies

public static void main() {    
  ResponseEntity<Greeting> response = restTemplate.getForEntity("http://localhost:8080", Greeting.class);
  Greeting greeting = response.getBody();
  System.out.println(greeting.getContent());
}
//output:
Hello World!

Of cource it's possible to POST, PUT and use the other HTTP methods, as well as handling HTTP Headers

HttpHeaders headers = new HttpHeaders();
headers.add("Connection", "keep-alive");
HttpEntity<String> req = new HttpEntity<>("", headers);
ResponseEntity<String> resp = t.exchange(url, HttpMethod.GET, req, String.class);

HTTPS / TLS (SSL)

If you want to call an endpoint over TLS, you need to create the RestTemplate so that it accepts the server certificate. There are a number of ways to do this.

Maven dependencies

Here are the Maven dependencies you need to use Spring as the client library for your load tests

<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-web</artifactId>
	<version>3.0.2.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<dependency>
	<groupId>org.codehaus.jackson</groupId>
	<artifactId>jackson-mapper-asl</artifactId>
	<version>1.9.13</version>
</dependency>