diff --git a/client/src/main/java/com/jd/platform/jlog/client/cache/ExtParamFactory.java b/client/src/main/java/com/jd/platform/jlog/client/cache/ExtParamFactory.java deleted file mode 100644 index e911b25..0000000 --- a/client/src/main/java/com/jd/platform/jlog/client/cache/ExtParamFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.jd.platform.jlog.client.cache; - -import org.reflections.Reflections; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletRequest; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author tangbohu - * @version 1.0.0 - * @ClassName ExtParamFactory.java - * @Description TODO - * @createTime 2022年03月21日 20:10:00 - */ -public class ExtParamFactory { - - - private static Logger LOGGER = LoggerFactory.getLogger(ExtParamFactory.class); - - private static volatile ReqMap reqMap = null; - - private static volatile RespMap respMap = null; - - private static AtomicBoolean reqHasLoad = new AtomicBoolean(false); - - private static AtomicBoolean respHasLoad = new AtomicBoolean(false); - - - public static Map getReqMap(ServletRequest request) { - try { - if(!reqHasLoad.get() && reqMap == null){ - synchronized (ExtParamFactory.class){ - if(reqMap == null){ - Reflections reflections = new Reflections(); - Set> subTypes = reflections.getSubTypesOf(ReqMap.class); - for (Class subType : subTypes) { - reqMap = subType.newInstance(); - break; - } - } - } - reqHasLoad.set(true); - } - return reqMap == null ? new HashMap<>(0) : reqMap.appendResMap(request); - }catch (Exception e){ - LOGGER.error("反射获取入参异常",e); - } - return new HashMap<>(0); - } - - public static Map getRespMap(String cnt) { - - try { - if(!respHasLoad.get() && respMap == null){ - synchronized (ExtParamFactory.class){ - if(respMap == null){ - Reflections reflections = new Reflections(); - Set> subTypes = reflections.getSubTypesOf(RespMap.class); - for (Class subType : subTypes) { - respMap = subType.newInstance(); - break; - } - } - } - respHasLoad.set(true); - } - return respMap == null ? new HashMap<>(0) : respMap.appendRespMap(cnt); - }catch (Exception e){ - LOGGER.error("反射获取出参异常",e); - } - return new HashMap<>(0); - } - -} diff --git a/client/src/main/java/com/jd/platform/jlog/client/cache/ReqMap.java b/client/src/main/java/com/jd/platform/jlog/client/cache/ReqMap.java deleted file mode 100644 index 1819c09..0000000 --- a/client/src/main/java/com/jd/platform/jlog/client/cache/ReqMap.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.jd.platform.jlog.client.cache; - -import javax.servlet.ServletRequest; -import java.util.Map; - -/** - * @author tangbohu - * @version 1.0.0 - * @ClassName ReqMap.java - * @Description TODO - * @createTime 2022年03月21日 19:18:00 - */ -public interface ReqMap { - - - /** - * @param request - * @return - */ - Map appendResMap(ServletRequest request); - -} diff --git a/client/src/main/java/com/jd/platform/jlog/client/cache/RespMap.java b/client/src/main/java/com/jd/platform/jlog/client/cache/RespMap.java deleted file mode 100644 index d9e4628..0000000 --- a/client/src/main/java/com/jd/platform/jlog/client/cache/RespMap.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.jd.platform.jlog.client.cache; - -import javax.servlet.ServletResponse; -import java.util.Map; - - -/** - * @author tangbohu - * @version 1.0.0 - * @ClassName RespMap.java - * @Description TODO - * @createTime 2022年03月21日 19:18:00 - */ -public interface RespMap { - - - /** - * - * @param cnt - * @return - */ - Map appendRespMap(String cnt); -} diff --git a/client/src/main/java/com/jd/platform/jlog/client/filter/HttpFilter.java b/client/src/main/java/com/jd/platform/jlog/client/filter/HttpFilter.java index 04945d6..bacc131 100644 --- a/client/src/main/java/com/jd/platform/jlog/client/filter/HttpFilter.java +++ b/client/src/main/java/com/jd/platform/jlog/client/filter/HttpFilter.java @@ -1,7 +1,6 @@ package com.jd.platform.jlog.client.filter; import com.jd.platform.jlog.client.Context; -import com.jd.platform.jlog.client.cache.ExtParamFactory; import com.jd.platform.jlog.client.log.LogExceptionStackTrace; import com.jd.platform.jlog.client.percent.DefaultTracerPercentImpl; import com.jd.platform.jlog.client.percent.ITracerPercent; @@ -9,8 +8,9 @@ import com.jd.platform.jlog.client.tracerholder.TracerHolder; import com.jd.platform.jlog.client.udp.UdpSender; import com.jd.platform.jlog.common.model.TracerBean; import com.jd.platform.jlog.common.handler.CompressHandler.Outcome; +import com.jd.platform.jlog.common.utils.FastJsonUtils; import com.jd.platform.jlog.common.utils.IdWorker; -import com.jd.platform.jlog.common.utils.IpUtils; +import com.jd.platform.jlog.common.utils.StringUtil; import com.jd.platform.jlog.core.ClientHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,7 +18,6 @@ import org.slf4j.LoggerFactory; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; import java.util.*; @@ -26,7 +25,7 @@ import java.util.*; /** * HttpFilter - * http://blog.chinaunix.net/uid-20783755-id-4729930.html + * .参考. * * @author wuweifeng * @version 1.0 @@ -99,7 +98,7 @@ public class HttpFilter implements Filter { //异常信息 tracerBean.setErrmsg(LogExceptionStackTrace.erroStackTrace(e).toString()); filterChain.doFilter(requestWrapper, servletResponse); - }finally { + } finally { //设置耗时 tracerBean.setCostTime((System.currentTimeMillis() - tracerBean.getCreateTimeLong())); //udp发送 @@ -118,7 +117,8 @@ public class HttpFilter implements Filter { byte[] contentBytes = mResp.getContent(); String content = new String(contentBytes); - Map map = ExtParamFactory.getRespMap(content); + Map map = FastJsonUtils.toMap(content); + Outcome outcome = ClientHandler.processResp(contentBytes, map); //此处可以对content做处理,然后再把content写回到输出流中 @@ -134,7 +134,7 @@ public class HttpFilter implements Filter { /** * 处理入参相关信息 */ - private void parseRequestMap(RequestWrapper requestWrapper, TracerBean tracerBean) { + private void parseRequestMap(RequestWrapper requestWrapper, TracerBean tracerBean) { //request的各个入参 Map params = requestWrapper.getParameterMap(); Map requestMap = new HashMap<>(params.size()); @@ -142,8 +142,16 @@ public class HttpFilter implements Filter { requestMap.put(key, params.get(key)[0]); } tracerBean.setUid((String) requestMap.get("uid")); - // 自定义的其他的参数对 - requestMap.putAll(ExtParamFactory.getReqMap(requestWrapper)); + + //对于@RequestBody类型的,可以通过该方法读取字符串。是个json串 + String body = requestWrapper.getBody(); + if (StringUtil.isNotBlank(body)) { + //将json转成map + Map jsonMap = FastJsonUtils.toMap(body); + // 自定义的其他的参数对 + requestMap.putAll(jsonMap); + } + Outcome out = ClientHandler.processReq(requestMap); tracerBean.setRequestContent((byte[]) out.getContent()); } diff --git a/client/src/main/java/com/jd/platform/jlog/client/udp/UdpClient.java b/client/src/main/java/com/jd/platform/jlog/client/udp/UdpClient.java index 15881a7..8d246f8 100644 --- a/client/src/main/java/com/jd/platform/jlog/client/udp/UdpClient.java +++ b/client/src/main/java/com/jd/platform/jlog/client/udp/UdpClient.java @@ -101,7 +101,7 @@ public class UdpClient { } String[] ipPort = workerIpPort.split(Constant.SPLITER); //发往worker的ip - remoteAddress= new InetSocketAddress(ipPort[0], Integer.valueOf(ipPort[1])); + remoteAddress= new InetSocketAddress(ipPort[0], Integer.parseInt(ipPort[1])); }else{ remoteAddress=tracerData.getAddress(); } diff --git a/client/src/main/java/com/jd/platform/jlog/client/udp/UdpSender.java b/client/src/main/java/com/jd/platform/jlog/client/udp/UdpSender.java index a04fe0a..c4b21fe 100644 --- a/client/src/main/java/com/jd/platform/jlog/client/udp/UdpSender.java +++ b/client/src/main/java/com/jd/platform/jlog/client/udp/UdpSender.java @@ -35,23 +35,23 @@ public class UdpSender { /** * 本地队列满了后丢弃的数量 */ - private static AtomicLong FAIL_OFFER_COUNT = new AtomicLong(); + private static final AtomicLong FAIL_OFFER_COUNT = new AtomicLong(); /** * 本地队列,已写入的总数量 */ - private static AtomicLong SUCCESS_OFFER_COUNT = new AtomicLong(); + private static final AtomicLong SUCCESS_OFFER_COUNT = new AtomicLong(); /** * 本地logger日志队列,已写入的总数量 */ - private static AtomicLong SUCCESS_LOGGER_OFFER_COUNT = new AtomicLong(); + private static final AtomicLong SUCCESS_LOGGER_OFFER_COUNT = new AtomicLong(); /** * 出入参集中营,最多积压5万条 */ - private static LinkedBlockingQueue tracerBeanQueue = new LinkedBlockingQueue<>(50000); + private static final LinkedBlockingQueue tracerBeanQueue = new LinkedBlockingQueue<>(50000); /** * 日志集中营,最多积压5万条 */ - private static LinkedBlockingQueue logBeanQueue = new LinkedBlockingQueue<>(50000); + private static final LinkedBlockingQueue logBeanQueue = new LinkedBlockingQueue<>(50000); /** diff --git a/config/config-etcd/src/main/java/com/jd/platform/jlog/etcd/EtcdListener.java b/config/config-etcd/src/main/java/com/jd/platform/jlog/etcd/EtcdListener.java index b6c172b..2fe5eac 100644 --- a/config/config-etcd/src/main/java/com/jd/platform/jlog/etcd/EtcdListener.java +++ b/config/config-etcd/src/main/java/com/jd/platform/jlog/etcd/EtcdListener.java @@ -4,7 +4,6 @@ import com.google.protobuf.ByteString; import com.ibm.etcd.api.Event; import com.ibm.etcd.api.KeyValue; import com.ibm.etcd.api.RangeResponse; -import com.ibm.etcd.client.EtcdClient; import com.ibm.etcd.client.kv.KvClient; import com.ibm.etcd.client.kv.WatchUpdate; import com.jd.platform.jlog.common.handler.JcProperties; @@ -14,20 +13,14 @@ import com.jd.platform.jlog.core.ClientHandlerBuilder; import com.jd.platform.jlog.core.ConfigChangeEvent; import com.jd.platform.jlog.core.ConfigChangeListener; import com.jd.platform.jlog.core.ConfigChangeType; -import io.netty.util.concurrent.DefaultThreadFactory; import java.io.IOException; import java.io.StringReader; import java.util.List; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import static com.jd.platform.jlog.etcd.EtcdConfigurator.PROPERTIES; import static com.jd.platform.jlog.etcd.EtcdConfigurator.PROPERTIES_PATH; -import static com.jd.platform.jlog.etcd.EtcdConfigurator.ROOT; /** * @author tangbohu