Clicky

Spring - Asynchronous rest call to a server

February 10, 2016

Implement a TaskService class responsible for running the asynchronous processing:

private class TaskService { public TaskService) { 
    // (...) 
} 

public String execute() throws InterruptedException { 
    String url = (...); RestTemplate restTemplate = new RestTemplate(); 
    return restTemplate.getForObject(url, <RETURNED_CLASS_NAME>.class); } 
}

Implement the calling code for the above TaskService:

private void callICECAT() throws IOException { 
    TaskService taskService = new TaskService(); Callable<string> callable = taskService::execute; 
    try { 
        callable.call(); 
    } catch (Exception e) { 
        (...) 
    } 
}