Posted In: Spring, Spring REST

AsyncRestTemplate example

import org.springframework.http.ResponseEntity;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.client.AsyncRestTemplate;

public class AsyncRestTmpltExample {
	public static void main(String[] args) {
		new AsyncRestTmpltExample().proceed();
	}

	public void proceed() {
		AsyncRestTemplate art = new AsyncRestTemplate();
		ListenableFuture<ResponseEntity<String>> lf = art
		        .getForEntity("http://www.google.com",
		                String.class);
		try {
			ResponseEntity<String> entity = lf.get();
			System.out.println(entity.getBody());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Tags:

by , on July 17th, 2017

  • Categories