Skip to content

refactor(common): decouple ConfigHttpServer from Swing dialogs - #247

Open
toku-sa-n wants to merge 2 commits into
DeNA:masterfrom
toku-sa-n:refactor/config-http-server-decouple
Open

toku-sa-n wants to merge 2 commits into
DeNA:masterfrom
toku-sa-n:refactor/config-http-server-decouple

Conversation

@toku-sa-n

@toku-sa-n toku-sa-n commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

UIとロジックコードの分離の第一歩として、PacketProxyHubから設定をダウンロードする際に使う ConfigHttpServer から、Swingのダイアログ表示とDBへの書き込みを切り離しました。動作は変えないリファクタです。

変更内容

  • ConfigHttpUiActions(packetproxy.common): 設定の上書きをユーザーに確認するためのインタフェース
  • SwingConfigHttpUiActions(packetproxy.gui): 上のインタフェースのSwing実装。これまで ConfigHttpServer の中にあった、ウィンドウの最前面化・Optionsタブへの切り替え・確認ダイアログを移した
  • ConfigSettingsWriter(packetproxy.common): 受け取った設定JSONをDBへ反映する処理を移した
  • ConfigHttpServer: 上の2つをコンストラクタで受け取るようにし、javax.swing と packetproxy.gui への依存をなくした(生成は GUIOptionHubServer で行う)

上書きするかどうかの判定(はっきり「はい」と答えたときだけ上書きする。#277 で入った判定をそのまま移しています)、レスポンス、DBへの書き込み順は変えていません。ひとつだけ、ウィンドウの最前面化(setAlwaysOnTop(true))の解除を finally に移し、ダイアログの表示中に例外が起きても最前面のまま残らないようにしました。

テスト

  • ConfigHttpServerTest を追加しました。serve() をモックのセッションで直接呼び、次を確認しています。

    • アクセストークンが無い・空・誤りの場合は401を返し、確認ダイアログもDBへの書き込みも呼ばれない
    • 確認で拒否された場合は401を返し、DBへ書き込まない
    • 確認で許可された場合は postData をそのまま ConfigSettingsWriter に渡し、200と {"status": "ok"} を返す
  • 最新の master にrebaseし、./gradlew compileJava test と spotlessCheck が通ることを確認しました。

  • By placing an "x" in the box, I hereby understand, accept and agree to be bound by the terms and conditions of the Contribution License Agreement.

🤖 Generated with Claude Code

@toku-sa-n
toku-sa-n marked this pull request as draft May 27, 2026 02:40
@toku-sa-n
toku-sa-n force-pushed the refactor/config-http-server-decouple branch 4 times, most recently from 7d8a334 to f0d292f Compare July 7, 2026 05:50
@toku-sa-n
toku-sa-n force-pushed the refactor/config-http-server-decouple branch from f0d292f to 3b6c621 Compare July 10, 2026 11:36
@toku-sa-n
toku-sa-n force-pushed the refactor/config-http-server-decouple branch from 3b6c621 to 47c6a25 Compare November 5, 2026 10:10
toku-sa-n and others added 2 commits November 9, 2026 11:44
ConfigHttpServer lives in packetproxy.common, yet it drove GUIMain and
JOptionPane directly to confirm a remote config overwrite, and wrote the
received config into the database inline. That tied the HTTP handler to
Swing and made it impossible to exercise without a running GUI.

Move the confirmation behind a ConfigHttpUiActions interface, implemented
by SwingConfigHttpUiActions in packetproxy.gui, and move the database
write into ConfigSettingsWriter. GUIOptionHubServer injects both through
the constructor.

The overwrite decision is unchanged: only NO_OPTION rejects. The window
still stays always-on-top from selecting the Options tab until the dialog
closes. The reset now sits in a finally block, so an exception while the
dialog is up no longer leaves the window pinned on top.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
With the Swing dialog and the database write behind injected
collaborators, ConfigHttpServer.serve() can be called directly with a
mocked session. Pin down the paths that guard a remote config overwrite.
A missing, empty or wrong access token returns 401 without touching the
UI or the database. A declined confirmation returns 401 without writing.
An accepted one passes postData to ConfigSettingsWriter and returns 200.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@toku-sa-n
toku-sa-n force-pushed the refactor/config-http-server-decouple branch from 47c6a25 to a5e0e56 Compare November 9, 2026 02:50
@toku-sa-n
toku-sa-n marked this pull request as ready for review November 9, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant