diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/WebClientUtils.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/WebClientUtils.java index c078cca..2023b11 100644 --- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/WebClientUtils.java +++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/WebClientUtils.java @@ -30,10 +30,18 @@ public class WebClientUtils { public static Mono get(String url, Map headers) { log.info("GET WebClient URL:{} headers:{}", url, headers); + String logId = MDC.get(Log4Constans.PRINT_LOG_ID); if(headers == null || headers.size() == 0) { return webClient.get().uri(url).retrieve().bodyToMono(String.class).flatMap(s-> { - log.info("GET WebClient Respon:{}", s); + log.info("[{}]GET WebClient Respon:{}", logId, s); return Mono.just(JSONObject.parseObject(s)); + }).contextWrite(ctx -> { + if(StringUtils.isNotEmpty(logId)){ + Context contextTmp = ctx.put(Log4Constans.PRINT_LOG_ID, logId); + + return contextTmp; + } + return ctx; }); }else{ return webClient.get().uri(url).headers(httpHeaders -> { @@ -42,20 +50,35 @@ public class WebClientUtils { httpHeaders.set(key, headers.get(key)); } }).retrieve().bodyToMono(String.class).flatMap(s-> { - log.info("GET WebClient Respon:{}", s); + log.info("[{}]GET WebClient Respon:{}", logId, s); return Mono.just(JSONObject.parseObject(s)); + }).contextWrite(ctx -> { + if(StringUtils.isNotEmpty(logId)){ + Context contextTmp = ctx.put(Log4Constans.PRINT_LOG_ID, logId); + + return contextTmp; + } + return ctx; }); } } public static Mono post(String url, JSONObject body, Map headers) { log.info("POST WebClient URL:{} body:{} headers:{}", url, body, headers); - //String logId = MDC.get(Log4Constans.PRINT_LOG_ID); + String logId = MDC.get(Log4Constans.PRINT_LOG_ID); if(headers == null || headers.size() == 0) { return webClient.post().uri(url).bodyValue(body.toString()).retrieve().bodyToMono(String.class).flatMap(s-> { - log.info("POST WebClient Respon:{}", s); + + log.info("[{}]POST WebClient Respon:{}", logId, s); return Mono.just(JSONObject.parseObject(s)); + }).contextWrite(ctx -> { + if(StringUtils.isNotEmpty(logId)){ + Context contextTmp = ctx.put(Log4Constans.PRINT_LOG_ID, logId); + + return contextTmp; + } + return ctx; }); }else{ return webClient.post().uri(url).bodyValue(body.toString()).headers(httpHeaders -> { @@ -64,8 +87,15 @@ public class WebClientUtils { httpHeaders.set(key, headers.get(key)); } }).retrieve().bodyToMono(String.class).flatMap(s-> { - log.info("POST WebClient Respon:{}", s); + log.info("[{}]POST WebClient Respon:{}", logId, s); return Mono.just(JSONObject.parseObject(s)); + }).contextWrite(ctx -> { + if(StringUtils.isNotEmpty(logId)){ + Context contextTmp = ctx.put(Log4Constans.PRINT_LOG_ID, logId); + + return contextTmp; + } + return ctx; }); } diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java index 41a4075..eee3d95 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java @@ -58,7 +58,7 @@ public class BaseWebSocketService { @Autowired private ReactiveStringRedisTemplate reactiveStringRedisTemplate; - protected static int ONE_MAX_TEXT = 30; + protected static int ONE_MAX_TEXT = 50; @@ -257,7 +257,7 @@ public class BaseWebSocketService { builder, text, 0, - text.length() - 1, + text.length(), baseSession.getRequestId()).flatMap(s -> { return Mono.just(true); }); @@ -292,7 +292,7 @@ public class BaseWebSocketService { builder, text, 0, - text.length() - 1, + text.length(), baseSession.getRequestId()).subscribe(); }else{ BoxMessageResp boxMessageResp = new BoxMessageResp();