1

I have this function that GETs an object through RestTemplate.exchange()...

private MatchList getRankedHistoryFromAccountId(long accountId) {

    String url = HTTPS + Region.valueOf(region.toUpperCase()).getServerURL() + URL_PREFIX + RiotAPIEndpoint.values()[6].getServiceURL(accountId) + API_KEY;
    RestTemplate template = new RestTemplate();
    try {
        System.out.println("Exchanging!");
        MatchList matchList = template.exchange(url, HttpMethod.GET, null, MatchList.class).getBody();
        return matchList;
    }
    catch (HttpClientErrorException hcee) {
        switch (hcee.getRawStatusCode()) {
            case 404:
                return null;
            default:
                try {
                    hcee.printStackTrace();
                    Thread.sleep(1000);
                    return getRankedHistoryFromAccountId(accountId);
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
    }
    return null;
}

This works, about 99% of the time. I'd say about 1/100 calls to this function cause "Exchanging!" to be printed out and then the program just hangs. I've been stuck on this problem for a week and can't find anything online to help me resolve the issue.

edit: here are debugging messages for the last 2 GET requests:

(162/200) Found challenger player RB KaSing's ranked stats.
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] o.a.h.client.protocol.RequestAddCookies  : CookieSpec selected: default
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] o.a.h.client.protocol.RequestAuthCache   : Auth cache not set in the context
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection request: [route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection leased: [id: 0][route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Executing request GET /lol/league/v3/positions/by-summoner/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Target auth state: UNCHALLENGED
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Proxy auth state: UNCHALLENGED
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> GET /lol/league/v3/positions/by-summoner/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Accept: application/json, application/*+json
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Host: EUW1.api.riotgames.com
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Connection: Keep-Alive
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Accept-Encoding: gzip,deflate
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "GET /lol/league/v3/positions/by-summoner/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1[\r][\n]"
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept: application/json, application/*+json[\r][\n]"
2017-08-16 00:01:30.251 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Host: EUW1.api.riotgames.com[\r][\n]"
2017-08-16 00:01:30.254 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2017-08-16 00:01:30.254 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)[\r][\n]"
2017-08-16 00:01:30.254 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-08-16 00:01:30.254 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Access-Control-Allow-Headers: Content-Type[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Access-Control-Allow-Methods: GET, POST, DELETE, PUT[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Access-Control-Allow-Origin: *[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Encoding: gzip[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Type: application/json;charset=utf-8[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Date: Wed, 16 Aug 2017 04:01:36 GMT[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Vary: Accept-Encoding[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "X-App-Rate-Limit: 100:120,20:1[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "X-App-Rate-Limit-Count: 54:120,1:1[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "X-Method-Rate-Limit: 20000:10,1200000:600[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "X-Method-Rate-Limit-Count: 2:10,43:600[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "X-NewRelic-App-Data: PxQFWFFSDwQTUlBSDgkOVEYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOA0dYa0kIXlpvTR0RB1cLVwxFZBtEAUsMPR4NVgMDQ1I9SQFBHkMRDA9YX1IUOB5NQBcLDg1eB0orXEsOGmhVFFhsShtKSEoSUyVKYwMdXTxJHhseGzgeU10WFBpCGCV9NhEaGAIdVRVRH1EDW1MHA1NRUBQeAUhDUg5TAlJSUA4BAwNQBAFRD0AUXlVeQABk[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "transfer-encoding: chunked[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Connection: keep-alive[\r][\n]"
2017-08-16 00:01:30.414 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "[\r][\n]"
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "a[\r][\n]"
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0][\r][\n]"
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << HTTP/1.1 200 OK
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Access-Control-Allow-Headers: Content-Type
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Access-Control-Allow-Methods: GET, POST, DELETE, PUT
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Access-Control-Allow-Origin: *
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Content-Encoding: gzip
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Content-Type: application/json;charset=utf-8
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Date: Wed, 16 Aug 2017 04:01:36 GMT
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Vary: Accept-Encoding
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << X-App-Rate-Limit: 100:120,20:1
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << X-App-Rate-Limit-Count: 54:120,1:1
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << X-Method-Rate-Limit: 20000:10,1200000:600
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << X-Method-Rate-Limit-Count: 2:10,43:600
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << X-NewRelic-App-Data: PxQFWFFSDwQTUlBSDgkOVEYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOA0dYa0kIXlpvTR0RB1cLVwxFZBtEAUsMPR4NVgMDQ1I9SQFBHkMRDA9YX1IUOB5NQBcLDg1eB0orXEsOGmhVFFhsShtKSEoSUyVKYwMdXTxJHhseGzgeU10WFBpCGCV9NhEaGAIdVRVRH1EDW1MHA1NRUBQeAUhDUg5TAlJSUA4BAwNQBAFRD0AUXlVeQABk
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << transfer-encoding: chunked
2017-08-16 00:01:30.416 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Connection: keep-alive
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Connection can be kept alive indefinitely
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "d3[\r][\n]"
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "][0x8e][0xb1]N[0xc3]@[0xc][0x86]_[0x5]ya[0xc9][0x90][0xb]-[0x95][0xb2][0x15][0x88] "J[0xaa][0xb6]S[0x11][0xaa],[0xe2][0xd0]S/w[0xad][0xcf])D[0x88]w[0xc7][0xa8][0x15][0x3][0x9b][0xfd]}[0xfa][0xed][0xff][0xe5][0xb][0x1c][0xe1][0xfb]@5[0xf6][0x4]9lF[0xc6][0xeb]xU[0xfa][0xce]:a[0x94][0xc0][0x11][0x12][0x10]K[0xac][0xf2][0xfe]i^UE[0xfd]X,[0x95][0x1d][0x7][0x1a]h=[0x1e]~S[0xcb]y[0xfd]\<lWM[0xd5]l[0xa7][0x9f]S[0xb5][0x8c]~[0xaf][0xa2][0xd4][0xf1][0xe0]p$nxM[0xd8][0x97][0xad][0xc2][0xcc][0xa4][0xa9]17[0xe9]?wi[0xd0][0xb4][0x1]{O*[0xcf][0xc5][0x16][0xc1]z[0x89][0x90][0xcf]f[0x93][0x4]>[0xac][0xd7]13[0x99][0xda][0x10]#[0xe9]b&[0xb7][0x9][0x9c]HH_B.<P[0x2][0xd6][0xe3][0x9b][0xd8][0x93][0x9e][0xeb][0xd0]E[0x5][0x1d]S[0xdc][0xdd][0xb9][0x10][0xda]?[0xb4][0xb][0xb2][0x12]&[0xdc][0x9f]C[0xdf][0xaf]?nv}[0xfa][0xb][0x1][0x0][0x0][\r][\n]"
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "0[\r][\n]"
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "[\r][\n]"
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection [id: 0][route: {s}->https://EUW1.api.riotgames.com:443] can be kept alive indefinitely
2017-08-16 00:01:30.417 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection released: [id: 0][route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] o.a.h.client.protocol.RequestAddCookies  : CookieSpec selected: default
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] o.a.h.client.protocol.RequestAuthCache   : Auth cache not set in the context
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection request: [route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection leased: [id: 0][route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Executing request GET /lol/summoner/v3/summoners/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Target auth state: UNCHALLENGED
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Proxy auth state: UNCHALLENGED
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> GET /lol/summoner/v3/summoners/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Accept: application/json, application/*+json
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Host: EUW1.api.riotgames.com
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Connection: Keep-Alive
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 >> Accept-Encoding: gzip,deflate
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "GET /lol/summoner/v3/summoners/21001130?api_key=RGAPI-1a878616-c46b-4945-bd22-5d626d7686b2 HTTP/1.1[\r][\n]"
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept: application/json, application/*+json[\r][\n]"
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Host: EUW1.api.riotgames.com[\r][\n]"
2017-08-16 00:01:31.917 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2017-08-16 00:01:31.919 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)[\r][\n]"
2017-08-16 00:01:31.919 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-08-16 00:01:31.919 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 >> "[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "HTTP/1.1 500 Server Error[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Type: application/json;charset=utf-8[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Date: Wed, 16 Aug 2017  04:01:38 GMT[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Content-Length: 64[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "Connection: keep-alive[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "[\r][\n]"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.wire                     : http-outgoing-0 << "{"status":{"message":"Internal server error","status_code":500}}"
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << HTTP/1.1 500 Server Error
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Content-Type: application/json;charset=utf-8
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Date: Wed, 16 Aug 2017  04:01:38 GMT
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Content-Length: 64
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] org.apache.http.headers                  : http-outgoing-0 << Connection: keep-alive
2017-08-16 00:01:32.102 DEBUG 10988 --- [cTaskExecutor-1] o.a.http.impl.execchain.MainClientExec   : Connection can be kept alive indefinitely
2017-08-16 00:01:32.105 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection [id: 0][route: {s}->https://EUW1.api.riotgames.com:443] can be kept alive indefinitely
2017-08-16 00:01:32.105 DEBUG 10988 --- [cTaskExecutor-1] h.i.c.PoolingHttpClientConnectionManager : Connection released: [id: 0][route: {s}->https://EUW1.api.riotgames.com:443][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
Nuradin
  • 280
  • 1
  • 4
  • 16
  • 1
    Is the endpoint local or on the internet? If you hit the url with curl or with your browser, does it ever hang? If you want it to gracefully fail rather than hanging then perhaps set a timeout. https://stackoverflow.com/questions/32983328/setting-timeouts-in-spring-rest-template – Matt R Aug 15 '17 at 23:37
  • @MattR, wow I didn't know it had an infinite timeout by default... I'll try that and see if it works. Thank you. – Nuradin Aug 15 '17 at 23:51
  • Looks like it didn't work. The same issue persists. – Nuradin Aug 16 '17 at 00:22
  • What's the need of the `Thread.sleep()`? – Edwin Dalorzo Aug 16 '17 at 00:52
  • GET requests to the API I'm using have a calls per hour limit. The thread.sleep(1000) is used to respect that limit between retries – Nuradin Aug 16 '17 at 00:59
  • Try with a different interface. Perhaps use HttpUrlConnection and see if you get the same problem. If you do have the same issue, perhaps jump onto a mobile hotspot to see if it's a problem in your network. For example, I used to have major lag issues with Plex Media Server that would lag my entire network for up to 30 seconds every 5 to 10 minutes. – Matt R Aug 16 '17 at 01:31
  • "program just hangs" - may be the server is throttling you. Other than the horrible URL construction, doesn't look like you're doing anything wrong. You can enable debug logs and see what point the code hangs. [Here](https://stackoverflow.com/questions/7952154/spring-resttemplate-how-to-enable-full-debugging-logging-of-requests-responses) is how. – Abhijit Sarkar Aug 16 '17 at 02:57
  • I have a feeling it's something to do with getting a null response. If I set a timeout, I should eventually get null or the response as the value of my variable. But that thread simply stops working. No exception thrown, nothing. – Nuradin Aug 16 '17 at 02:57
  • Debug the `RestTemplate`, that's why IDEs exist. – Abhijit Sarkar Aug 16 '17 at 02:58
  • @AbhijitSarkar, doing that right now. Just waiting for it to fail. Will edit this comment when it does. Thank you (and everyone else) for your help. – Nuradin Aug 16 '17 at 03:19
  • Can't edit comments apparently. I've updated the OP with the debugging messages. I received a 500 error from the remote server. I'll try and fix my code so that it'll retry after a while. Hopefully it helps. – Nuradin Aug 16 '17 at 04:25

1 Answers1

0

I figured it out thanks to help from @AbhijitSarkar.

After debugging the status code, I found out I was being returned 5xx status codes every now and then. As you can see in the OP, only client exceptions were being caught. 5xx status codes are not caught here because they are server exceptions.

    catch (HttpServerErrorException hsee) {
        switch(hsee.getRawStatusCode()) {
            default:
                try {
                    hsee.printStackTrace();
                    Thread.sleep(1000);
                    return getSummonerInformationFromAccountId(accountId);
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
    }

Another catch block with HttpServerErrorException remedies the issue. Obviously you'll want to add more cases to the switch though, and have a good strategy to deal with at least the most common ones (500, 503, etc)

Nuradin
  • 280
  • 1
  • 4
  • 16