fix : To solve RestTemplate Missing parameter (#775)

pull/779/head
pizihao 3 years ago
parent f4c8f535f7
commit b82c995c2d

@ -30,7 +30,6 @@ import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO;
import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@ -38,7 +37,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT;
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
/**
@ -49,7 +47,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
public class ThreadPoolAdapterService {
/**
* Map<mark, Map<tenantItem, Map<threadPoolKey, List<ThreadPoolAdapterState>>>>
* Map&lt;mark, Map&lt;tenantItem, Map&lt;threadPoolKey, List&lt;ThreadPoolAdapterState&gt;&gt;&gt;&gt;
*/
private static final Map<String, Map<String, Map<String, List<ThreadPoolAdapterState>>>> THREAD_POOL_ADAPTER_MAP = new ConcurrentHashMap<>();
@ -98,18 +96,23 @@ public class ThreadPoolAdapterService {
List<String> addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList());
List<ThreadPoolAdapterRespDTO> result = new ArrayList<>(addressList.size());
addressList.forEach(each -> {
String urlString = new StringBuilder()
.append("http://")
.append(each)
.append("/adapter/thread-pool/info")
.toString();
StringBuilder builder = StringUtil.createBuilder("http://", each, "/adapter/thread-pool/info");
Map<String, Object> param = new HashMap<>();
param.put("mark", requestParameter.getMark());
param.put("threadPoolKey", requestParameter.getThreadPoolKey());
List<String> paramKey = new ArrayList<>(param.keySet());
for (int i = 0; i < paramKey.size(); i++) {
if (i == 0) {
builder.append("?");
} else {
builder.append("&");
}
String s = paramKey.get(i);
builder.append(StringUtil.newBuilder(s, "={", s, "}"));
}
try {
RestTemplate template = new RestTemplate();
String resultStr = template.getForObject(urlString, String.class, param);
String resultStr = template.getForObject(builder.toString(), String.class, param);
if (StringUtil.isNotBlank(resultStr)) {
Result<ThreadPoolAdapterRespDTO> restResult = JSONUtil.parseObject(resultStr, new TypeReference<Result<ThreadPoolAdapterRespDTO>>() {
});
@ -131,22 +134,16 @@ public class ThreadPoolAdapterService {
return actual.keySet();
}
}
return new HashSet();
return new HashSet<>();
}
public static void remove(String identify) {
synchronized (ThreadPoolAdapterService.class) {
THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) -> {
val.forEach((threadPoolKey, states) -> {
Iterator<ThreadPoolAdapterState> iterator = states.iterator();
while (iterator.hasNext()) {
ThreadPoolAdapterState adapterState = iterator.next();
if (Objects.equals(adapterState.getIdentify(), identify)) {
iterator.remove();
}
}
});
}));
THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) ->
val.forEach((threadPoolKey, states) ->
states.removeIf(adapterState -> Objects.equals(adapterState.getIdentify(), identify))
)
));
}
}

@ -26,7 +26,6 @@ import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.*;

Loading…
Cancel
Save