0
我有這個功能,通過RestTemplate.exchange()獲取的對象...RestTemplate交換法導致彈簧啓動應用程序現在掛每個然後
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;
}
這工作,時間約99% 。我會說這個功能的1/100調用導致「交換!」打印出來然後程序就掛起來了。我一直在這個問題上停留了一週,在網上找不到任何東西來幫助我解決問題。
編輯:這裏是爲最後 2 GET請求調試消息:
(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]
是端點本地還是在互聯網上?如果你使用curl或瀏覽器打開url,它是否掛起?如果你想讓它優雅地失敗而不是懸掛,那麼可能會設置超時。 https://stackoverflow.com/questions/32983328/setting-timeouts-in-spring-rest-template –
@MattR,哇我不知道它默認情況下有無限的超時...我會嘗試看看如果它有效。謝謝。 – Nuradin
看起來沒有用。同樣的問題仍然存在。 – Nuradin