[ISSUE-#5182] Remove ConfigController#removeRequestContext method. (#5201)

* fix #5182, After some discussion, 2.0 adopted a long connection approach and decided to remove RemoveRequest Context

* fix #5182, After some discussion, 2.0 adopted a long connection approach and decided to remove RemoveRequest Context

* Removing invalid import
This commit is contained in:
mai.jh 2021-03-26 13:52:56 +08:00 committed by GitHub
parent d5b9b908a0
commit 9cdfd9599d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,11 +48,8 @@ import com.alibaba.nacos.config.server.utils.RequestUtil;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.config.server.utils.ZipUtils;
import com.alibaba.nacos.sys.utils.InetUtils;
import org.apache.catalina.connector.Request;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.http.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -73,14 +70,12 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -300,46 +295,6 @@ public class ConfigController {
return rr;
}
private void removeRequestContext(HttpServletRequest request) {
try {
request.removeAttribute("body");
Map<String, String[]> parameterMap = request.getParameterMap();
Field locked = parameterMap.getClass().getDeclaredField("locked");
locked.setAccessible(true);
locked.set(parameterMap, false);
parameterMap.remove(Constants.PROBE_MODIFY_REQUEST);
Field inneRequestFiled = request.getClass().getDeclaredField("request");
inneRequestFiled.setAccessible(true);
Request innerRequest = (Request) inneRequestFiled.get(request);
Field coyoteRequest = innerRequest.getClass().getDeclaredField("coyoteRequest");
coyoteRequest.setAccessible(true);
org.apache.coyote.Request coyotoRequest = (org.apache.coyote.Request) coyoteRequest.get(innerRequest);
Parameters parameters = coyotoRequest.getParameters();
Field hashMapField = parameters.getClass().getDeclaredField("paramHashValues");
hashMapField.setAccessible(true);
LinkedHashMap hashMaps = (LinkedHashMap) hashMapField.get(parameters);
hashMaps.remove(Constants.PROBE_MODIFY_REQUEST);
Field tmpNameField = parameters.getClass().getDeclaredField("tmpName");
tmpNameField.setAccessible(true);
ByteChunk tmpName = (ByteChunk) tmpNameField.get(parameters);
byte[] bytemp = new byte[0];
tmpName.setBytes(bytemp, 0, 0);
Field tmpValueField = parameters.getClass().getDeclaredField("tmpValue");
tmpValueField.setAccessible(true);
ByteChunk tmpValue = (ByteChunk) tmpValueField.get(parameters);
tmpValue.setBytes(bytemp, 0, 0);
} catch (Exception e) {
LOGGER.warn("remove listen request param error", e);
}
}
/**
* The client listens for configuration changes.
*/
@ -349,8 +304,6 @@ public class ConfigController {
throws ServletException, IOException {
request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
//remove large listen context , reduce request content to optimize cms gc.
removeRequestContext(request);
String probeModify = request.getParameter("Listening-Configs");
if (StringUtils.isBlank(probeModify)) {
LOGGER.warn("invalid probeModify is blank");