Browse Source

路况接口加入重试

develop
王兴琳 5 months ago
parent
commit
d15fa35943
  1. 28
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

28
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -1105,22 +1105,30 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
*/
@Override
public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException {
OkHttp okHttp = new OkHttp();
// 创建OkHttpClient.Builder实例
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
RequestParams requestParams = new RequestParams();
// 添加重试拦截器到OkHttpClient
httpClientBuilder.addInterceptor(new RetryInterceptorUtil());
requestParams.put("sysid", sysid);
// 构建最终的OkHttpClient实例
OkHttpClient okHttpClient = httpClientBuilder.build();
// 现在使用带有重试机制的OkHttpClient发起请求
Map<String, Object> requestParams = new HashMap<>();
requestParams.put("sysid", sysid);
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getAccessToken());
Gson gson = new Gson();
String requestParamsJson = gson.toJson(requestParams);
//todo 获取路况信息
try {
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
Request request = new Request.Builder()
.url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue())
.headers(Headers.of(headers))
.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestParamsJson))
.build();
Response response = okHttpClient.newCall(request).execute();
ResponseBody body = response.body();
if (body != null) {
String jsonString = body.string();

Loading…
Cancel
Save