From f12c2fc0e37c71b4dfef186485b8294dd6ba347a Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Wed, 27 May 2026 12:46:53 +0900 Subject: [PATCH] refactor(common): extract ConfigDaoHub for config JSON Replace duplicated private DaoHub inner classes in ConfigHttpServer and ConfigIO with a shared ConfigDaoHub DTO type. Co-authored-by: Cursor --- .../core/packetproxy/common/ConfigDaoHub.java | 36 +++++++++++++++++++ .../packetproxy/common/ConfigHttpServer.java | 22 ++---------- .../core/packetproxy/common/ConfigIO.java | 22 ++---------- 3 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 src/main/java/core/packetproxy/common/ConfigDaoHub.java diff --git a/src/main/java/core/packetproxy/common/ConfigDaoHub.java b/src/main/java/core/packetproxy/common/ConfigDaoHub.java new file mode 100644 index 00000000..9c959135 --- /dev/null +++ b/src/main/java/core/packetproxy/common/ConfigDaoHub.java @@ -0,0 +1,36 @@ +/* + * Copyright 2026 DeNA Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package packetproxy.common; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import packetproxy.model.*; + +/** 設定エクスポート/インポート用 JSON の DTO。 */ +public class ConfigDaoHub { + + @SerializedName(value = "listenPorts") + List listenPortList; + + @SerializedName(value = "servers") + List serverList; + + @SerializedName(value = "modifications") + List modificationList; + + @SerializedName(value = "sslPassThroughs") + List sslPassThroughList; +} diff --git a/src/main/java/core/packetproxy/common/ConfigHttpServer.java b/src/main/java/core/packetproxy/common/ConfigHttpServer.java index ca125627..6ddeee29 100644 --- a/src/main/java/core/packetproxy/common/ConfigHttpServer.java +++ b/src/main/java/core/packetproxy/common/ConfigHttpServer.java @@ -2,7 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.annotations.SerializedName; import fi.iki.elonen.NanoHTTPD; import java.util.HashMap; import java.util.List; @@ -15,21 +14,6 @@ public class ConfigHttpServer extends NanoHTTPD { private final String allowedAccessToken; - private static class DaoHub { - - @SerializedName(value = "listenPorts") - List listenPortList; - - @SerializedName(value = "servers") - List serverList; - - @SerializedName(value = "modifications") - List modificationList; - - @SerializedName(value = "sslPassThroughs") - List sslPassThroughList; - } - public ConfigHttpServer(String hostname, int port, String allowedAccessToken) { super(hostname, port); this.allowedAccessToken = allowedAccessToken; @@ -74,7 +58,7 @@ private void fixUpModificationList(Map serverMap, List serverMap = new HashMap<>(); fixUpServerList(serverMap, daoHub.serverList); fixUpListenPortList(serverMap, daoHub.listenPortList); @@ -107,7 +91,7 @@ public Response serve(IHTTPSession session) { try { - DaoHub daoHub = new DaoHub(); + ConfigDaoHub daoHub = new ConfigDaoHub(); daoHub.listenPortList = ListenPorts.getInstance().queryAll(); daoHub.serverList = Servers.getInstance().queryAll(); @@ -153,7 +137,7 @@ public Response serve(IHTTPSession session) { session.parseBody(map); String json = map.get("postData"); - DaoHub daoHub = new Gson().fromJson(json, DaoHub.class); + ConfigDaoHub daoHub = new Gson().fromJson(json, ConfigDaoHub.class); Database.getInstance().dropConfigs(); diff --git a/src/main/java/core/packetproxy/common/ConfigIO.java b/src/main/java/core/packetproxy/common/ConfigIO.java index bb5c10e4..2831ba25 100644 --- a/src/main/java/core/packetproxy/common/ConfigIO.java +++ b/src/main/java/core/packetproxy/common/ConfigIO.java @@ -2,7 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.annotations.SerializedName; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -11,21 +10,6 @@ public class ConfigIO { - private static class DaoHub { - - @SerializedName(value = "listenPorts") - List listenPortList; - - @SerializedName(value = "servers") - List serverList; - - @SerializedName(value = "modifications") - List modificationList; - - @SerializedName(value = "sslPassThroughs") - List sslPassThroughList; - } - public ConfigIO() { } @@ -68,7 +52,7 @@ private void fixUpModificationList(Map serverMap, List serverMap = new HashMap<>(); fixUpServerList(serverMap, daoHub.serverList); fixUpListenPortList(serverMap, daoHub.listenPortList); @@ -76,7 +60,7 @@ private void fixUp(DaoHub daoHub) { } public String getOptions() throws Exception { - DaoHub daoHub = new DaoHub(); + ConfigDaoHub daoHub = new ConfigDaoHub(); daoHub.listenPortList = ListenPorts.getInstance().queryAll(); daoHub.serverList = Servers.getInstance().queryAll(); @@ -92,7 +76,7 @@ public String getOptions() throws Exception { } public void setOptions(String json) throws Exception { - DaoHub daoHub = new Gson().fromJson(json, DaoHub.class); + ConfigDaoHub daoHub = new Gson().fromJson(json, ConfigDaoHub.class); Database.getInstance().dropConfigs();