I've implemented Consuming Rest tutorial some months ago (link: https://spring.io/guides/gs/consuming-rest/) and successfully implemented the RestTemplate in Spring Boot with web-mvc as you can see at the github link (https://github.com/alessandroargentieri/twoSpringBootMicroservices).
But recently I'm not succeeding in implementing this pattern anymore and I'm not getting why.
I'm able to reach my RestController(the one which must consume the rest call), I'm able to reach the Rest Web Service (the one I want to consume, but when it comes to ask the RestController to make a call and consume another rest service it gives me errors.
I've used cabled internet connection and wifi with no proxy set.
This is the RestController:
@org.springframework.web.bind.annotation.RestController
public class RestController {
@RequestMapping("/hey")
public String hey(){
return "You told me hey!!";
}
@RequestMapping("/restme")
public String restme(){
try {
RestTemplate restTemplate = new RestTemplate();
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
return quote.toString();
}catch (Exception e){
return e.toString();
}
}
@RequestMapping("/restme2")
public Quote restme2(){
RestTemplate restTemplate = new RestTemplate();
Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
return quote; //it uses JacksonLibrary
}
@RequestMapping("/restme3")
public String ale(){
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.getForEntity("http://gturnquist-quoters.cfapps.io/api/random", String.class);
return response.getBody();
}
}
and this is the screenshot of the browser making this call and also making the call.
Inserted Username and Password for the Proxy, I get this error instead: