Я сейчас пытаюсь использовать это publi c API :
Проблема в том, что я получаю сообщение об ошибке тайм-аута, но я не выяснил, почему:
Generic exception: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://api.worldoftanks.eu/wot/account/info/": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
Это странно, потому что если я просто добавлю URL-адрес запроса в мой веб-браузер, все будет возвращено правильно.
Итак, вопрос в том, связана ли эта проблема с неправильным пониманием restTemplate или что-то отсутствует в моем запросе, связанном с этим API.
Вот мой код:
public class PlayerWgApi {
private final String apiUri = "https://api.worldoftanks.eu/";
private final String moduleUri = "wot/";
private final String applicationId = "74613ef82f2d90e9c88a8449723936fe";
public ResponseEntity<ApiResponse> getVehicules(String accountId) {
final String methodUri = "account/info/";
final String uri = apiUri + moduleUri + methodUri;
RestTemplate restTemplate = new RestTemplate();
UriComponents builder = UriComponentsBuilder.fromHttpUrl(uri)
.queryParam("application_id", applicationId)
.queryParam("account_id", accountId)
.queryParam("extra", "statistics.random")
.queryParam("fields", "clan_id,client_language,created_at,global_rating,last_battle_time,updated_at")
.build();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(null, headers);
return restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, ApiResponse.class);
}
}
И мой класс ApiResponse:
public class ApiResponse {
String status;
Meta meta;
@JsonProperty("data")
private Map<String, PlayerResponse> player;
getters/setters...
}