简体   繁体   中英

Generic exception:Connection timed out while using restTemplate

I am curently trying to use this public API :

Issue is that I get a timeout error but I haven't figured out why:

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

It's weird because if I just put the request URL to my web browser, everything is returned properly.

So the question is: is this problem related to a misunderstanding of restTemplate or is there something missing in my request related to this API.

Here is my code:

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);
    }
}

And my ApiResponse class:

public class ApiResponse {
    String status;
    Meta meta;
    @JsonProperty("data")
    private Map<String, PlayerResponse> player;

    getters/setters...
}

I finaly found why this is was not working, I was using my smartphone datas. There is no proxy configured on it anyway, so I still don't know what parameter is causing this issue. But when I switch to another network, everything is working properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM