fix(v0.11): 第五轮走查——事件路由 Class 比较、映射只读视图、监听器日志与文件名回退

- EventHandlerMapping / CloudwalkEventInitializing:用 Objects.equals 比较事件原型与入参 Class,避免反编译式链式比较隐患。
- EventHandlerMapping:getHandlerMap 等对外返回 Collections.unmodifiableMap,防止误改内部注册表。
- GroupEventListener:改为实例级 logger(getClass()),子类日志可区分。
- AbstractCloudwalkController:URLEncoder 失败时回退原始文件名,避免 Content-Disposition 收到 null。

Made-with: Cursor

Former-commit-id: b565ce0658
This commit is contained in:
反编译工作区
2026-04-25 00:12:06 +08:00
parent ec020e45b0
commit 9fa7e63396
4 changed files with 13 additions and 10 deletions
@@ -26,6 +26,7 @@ import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.SynchronousQueue; import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@@ -176,7 +177,7 @@ public class CloudwalkEventInitializing implements CommandLineRunner {
private EventType getEventType(Class<? extends BaseEvent> eventClass) { private EventType getEventType(Class<? extends BaseEvent> eventClass) {
for (EventType eventType : EventType.values()) { for (EventType eventType : EventType.values()) {
BaseEvent prototype = eventType.getEventClass(); BaseEvent prototype = eventType.getEventClass();
if (prototype != null && prototype.getClass().equals(eventClass)) { if (prototype != null && Objects.equals(eventClass, prototype.getClass())) {
return eventType; return eventType;
} }
} }
@@ -3,9 +3,11 @@ package cn.cloudwalk.event.handler;
import cn.cloudwalk.cwos.client.event.event.BaseEvent; import cn.cloudwalk.cwos.client.event.event.BaseEvent;
import cn.cloudwalk.cwos.client.event.event.EventType; import cn.cloudwalk.cwos.client.event.event.EventType;
import cn.cloudwalk.cwos.client.event.handler.EventListener; import cn.cloudwalk.cwos.client.event.handler.EventListener;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class EventHandlerMapping { public class EventHandlerMapping {
private final Map<String, Map<EventType, Map<String, List<EventHandler>>>> handlerMap = new HashMap<>(); private final Map<String, Map<EventType, Map<String, List<EventHandler>>>> handlerMap = new HashMap<>();
@@ -27,7 +29,7 @@ public class EventHandlerMapping {
Class<? extends BaseEvent> eventClass) { Class<? extends BaseEvent> eventClass) {
for (EventType eventType : EventType.values()) { for (EventType eventType : EventType.values()) {
BaseEvent prototype = eventType.getEventClass(); BaseEvent prototype = eventType.getEventClass();
if (prototype != null && prototype.getClass().equals(eventClass)) { if (prototype != null && Objects.equals(eventClass, prototype.getClass())) {
return getServiceCodeHandlerListMap(groupId, eventType); return getServiceCodeHandlerListMap(groupId, eventType);
} }
} }
@@ -62,14 +64,14 @@ public class EventHandlerMapping {
} }
public Map<String, Map<EventType, Map<String, List<EventHandler>>>> getHandlerMap() { public Map<String, Map<EventType, Map<String, List<EventHandler>>>> getHandlerMap() {
return this.handlerMap; return Collections.unmodifiableMap(this.handlerMap);
} }
public Map<String, Map<String, Map<String, List<CustomEventHandler>>>> getCustomHandlerMap() { public Map<String, Map<String, Map<String, List<CustomEventHandler>>>> getCustomHandlerMap() {
return this.customHandlerMap; return Collections.unmodifiableMap(this.customHandlerMap);
} }
public Map<Class<? extends EventListener>, String> getListenerClassGroupMap() { public Map<Class<? extends EventListener>, String> getListenerClassGroupMap() {
return this.listenerClassGroupMap; return Collections.unmodifiableMap(this.listenerClassGroupMap);
} }
} }
@@ -10,7 +10,7 @@ import org.springframework.context.ApplicationContext;
public abstract class GroupEventListener implements EventListener { public abstract class GroupEventListener implements EventListener {
public static ApplicationContext applicationContext; public static ApplicationContext applicationContext;
private static final Logger LOGGER = LoggerFactory.getLogger(GroupEventListener.class); protected final Logger logger = LoggerFactory.getLogger(getClass());
public void messageListener(BaseEvent baseEvent) throws RuntimeException { public void messageListener(BaseEvent baseEvent) throws RuntimeException {
try { try {
@@ -18,13 +18,13 @@ public abstract class GroupEventListener implements EventListener {
(CloudwalkEventManager)applicationContext.getBean(CloudwalkEventManager.class); (CloudwalkEventManager)applicationContext.getBean(CloudwalkEventManager.class);
cloudwalkEventManager.handle(getClass(), baseEvent); cloudwalkEventManager.handle(getClass(), baseEvent);
} catch (BeansException e) { } catch (BeansException e) {
LOGGER.error("事件处理出现异常(容器 Bean 解析失败),原因:", e); this.logger.error("事件处理出现异常(容器 Bean 解析失败),原因:", e);
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOGGER.error("事件处理出现异常,原因:", e); this.logger.error("事件处理出现异常,原因:", e);
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("事件处理出现异常,原因:", e); this.logger.error("事件处理出现异常,原因:", e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -76,6 +76,6 @@ public abstract class AbstractCloudwalkController {
} catch (Exception e) { } catch (Exception e) {
this.LOGGER.error("转换文件名字符类型失败,原因:", e); this.LOGGER.error("转换文件名字符类型失败,原因:", e);
} }
return codedFilename; return codedFilename != null ? codedFilename : fileNames;
} }
} }