From ef030407c00c820ff27d83e37ac1e495566011bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=8D=E7=BC=96=E8=AF=91=E5=B7=A5=E4=BD=9C=E5=8C=BA?= Date: Sat, 25 Apr 2026 00:18:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(v0.11):=20=E7=AC=AC=E4=B8=83=E8=BD=AE?= =?UTF-8?q?=E8=B5=B0=E6=9F=A5=E2=80=94=E2=80=94=E8=BF=87=E6=BB=A4=E5=99=A8?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=80=8F=E4=BC=A0=E3=80=81Kafka=20=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E8=80=85=E6=B3=9B=E5=9E=8B=E4=B8=8E=E5=8F=8D=E5=B0=84?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CloudwalkContextParameterFilter:去掉对 chain.doFilter 的吞异常 catch,仅 finally 清理 Session,避免下游错误被静默吞掉。 - KafkaProducter:KafkaProducer/ProducerRecord 使用 String 泛型;send 遇 InterruptedException 时恢复中断标志。 - BeanCopyUtils、ServerIdStrategyBeanConfig:newInstance 改为 getDeclaredConstructor().newInstance()。 对应 docs/reviews 05 中 P1;maven-cloudwalk-legacy-public 已全量 compile 通过。 Made-with: Cursor --- .../java/cn/cloudwalk/cloud/utils/BeanCopyUtils.java | 4 ++-- .../serial/strategy/ServerIdStrategyBeanConfig.java | 2 +- .../web/filter/CloudwalkContextParameterFilter.java | 7 +------ .../cwos/client/event/producer/KafkaProducter.java | 9 +++++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/maven-cloudwalk-legacy-public/cloudwalk-common-result/src/main/java/cn/cloudwalk/cloud/utils/BeanCopyUtils.java b/maven-cloudwalk-legacy-public/cloudwalk-common-result/src/main/java/cn/cloudwalk/cloud/utils/BeanCopyUtils.java index 2ed923b8..a8e1b861 100644 --- a/maven-cloudwalk-legacy-public/cloudwalk-common-result/src/main/java/cn/cloudwalk/cloud/utils/BeanCopyUtils.java +++ b/maven-cloudwalk-legacy-public/cloudwalk-common-result/src/main/java/cn/cloudwalk/cloud/utils/BeanCopyUtils.java @@ -33,7 +33,7 @@ public class BeanCopyUtils public static T copyProperties(Object source, Class targetClazz) { /* 34 */ T target = null; try { -/* 36 */ target = targetClazz.newInstance(); +/* 36 */ target = targetClazz.getDeclaredConstructor().newInstance(); /* 37 */ BeanUtils.copyProperties(source, target); /* 38 */ } catch (Exception e) { /* 39 */ throw new RuntimeException(e); @@ -101,7 +101,7 @@ if (!CollectionUtils.isEmpty(list)) { for (V source : list) { E target = null; try { -target = clazz.newInstance(); +target = clazz.getDeclaredConstructor().newInstance(); BeanUtils.copyProperties(source, target); } catch (Exception e) { throw new RuntimeException(e); diff --git a/maven-cloudwalk-legacy-public/cloudwalk-common-serial/src/main/java/cn/cloudwalk/serial/strategy/ServerIdStrategyBeanConfig.java b/maven-cloudwalk-legacy-public/cloudwalk-common-serial/src/main/java/cn/cloudwalk/serial/strategy/ServerIdStrategyBeanConfig.java index 321fd1f6..b3b73e6b 100644 --- a/maven-cloudwalk-legacy-public/cloudwalk-common-serial/src/main/java/cn/cloudwalk/serial/strategy/ServerIdStrategyBeanConfig.java +++ b/maven-cloudwalk-legacy-public/cloudwalk-common-serial/src/main/java/cn/cloudwalk/serial/strategy/ServerIdStrategyBeanConfig.java @@ -32,7 +32,7 @@ ServerIdStrategyEnum.getServerIdStrategyEnum(serialProperties.getServerIdStrateg beanClassName = Class.forName(ServerIdStrategyEnum.getServerIdStrategyEnum(serialProperties.getServerIdStrategy().getCode()).getBeanName()); } } -return (ServerIdStrategy)beanClassName.newInstance(); +return (ServerIdStrategy)beanClassName.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/maven-cloudwalk-legacy-public/cloudwalk-common-web/src/main/java/cn/cloudwalk/web/filter/CloudwalkContextParameterFilter.java b/maven-cloudwalk-legacy-public/cloudwalk-common-web/src/main/java/cn/cloudwalk/web/filter/CloudwalkContextParameterFilter.java index 63e08ef2..0a03ea01 100644 --- a/maven-cloudwalk-legacy-public/cloudwalk-common-web/src/main/java/cn/cloudwalk/web/filter/CloudwalkContextParameterFilter.java +++ b/maven-cloudwalk-legacy-public/cloudwalk-common-web/src/main/java/cn/cloudwalk/web/filter/CloudwalkContextParameterFilter.java @@ -9,8 +9,6 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -34,7 +32,6 @@ import org.springframework.web.filter.OncePerRequestFilter; public class CloudwalkContextParameterFilter extends OncePerRequestFilter { -private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -75,11 +72,9 @@ this.cloudwalkSessionContextHolder.putSession(sessionObject); try { chain.doFilter((ServletRequest)request, (ServletResponse)response); -} catch (Exception e) { -this.logger.error("参数注册过滤器失败,原因:", e); } finally { this.cloudwalkSessionContextHolder.clearSession(); -} +} } } diff --git a/maven-cloudwalk-legacy-public/cwos-sdk-event/src/main/java/cn/cloudwalk/cwos/client/event/producer/KafkaProducter.java b/maven-cloudwalk-legacy-public/cwos-sdk-event/src/main/java/cn/cloudwalk/cwos/client/event/producer/KafkaProducter.java index fd85d3e9..24d8fbbe 100644 --- a/maven-cloudwalk-legacy-public/cwos-sdk-event/src/main/java/cn/cloudwalk/cwos/client/event/producer/KafkaProducter.java +++ b/maven-cloudwalk-legacy-public/cwos-sdk-event/src/main/java/cn/cloudwalk/cwos/client/event/producer/KafkaProducter.java @@ -10,7 +10,6 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.apache.kafka.clients.producer.KafkaProducer; -import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; @@ -25,7 +24,7 @@ public class KafkaProducter implements MessageProducer { private KafkaProperties kafkaProperties; -private Producer producer; +private KafkaProducer producer; private KafkaProducter(KafkaProperties kafkaProperties) { Properties properties = new Properties(); @@ -49,7 +48,7 @@ properties.put("buffer.memory", Long.valueOf(kafkaProperties.getBufferMemory())) properties.put("key.serializer", kafkaProperties.getKeySerializer()); properties.put("value.serializer", kafkaProperties.getValueSerializer()); this.kafkaProperties = kafkaProperties; -this.producer = (Producer)new KafkaProducer(properties); +this.producer = new KafkaProducer<>(properties); } public static KafkaProducter getInstance(KafkaProperties kafkaProperties) { @@ -60,13 +59,15 @@ return new KafkaProducter(kafkaProperties); public void send(BaseEvent event, String key, String topic) { Integer deviceIdHashCode = Integer.valueOf((event.getDeviceId() != null) ? event.getDeviceId().hashCode() : 0); Integer partition = Integer.valueOf(deviceIdHashCode.intValue() % this.producer.partitionsFor(topic).size()); -Future send = this.producer.send(new ProducerRecord(topic, partition, key, JSONObject.toJSONString(event))); +Future send = + this.producer.send(new ProducerRecord<>(topic, partition, key, JSONObject.toJSONString(event))); try { send.get(1000L, TimeUnit.MILLISECONDS); if (!send.isDone()) { throw new SendFailedException("failed to send kafka"); } } catch (InterruptedException e) { +Thread.currentThread().interrupt(); throw new SendFailedException("failed to send kafka InterruptedException" + e.getMessage()); } catch (ExecutionException e) { throw new SendFailedException("failed to send kafka ExecutionException" + e.getMessage());