dropwizardのadminとapplicationのcontextRootを切り替えたくなって、
調べた結果、いろいろ勉強なったので、その道程をメモします。
1.参考サイト
How to set context path with Default server? Dropwizard 0.7.1 Configuration Reference | Dropwizard Dropwizard 0.9.1 Configuration Reference | Dropwizard
2.やり方
2.1 SimpleServerFactoryを使用する場合
ymlファイルのserverのtypeをsimpleにすると、
applicationContextPath、adminContextPathの設定が可能で、
1ポートにapplicationと、adminにurlをマッピングすることができます。
server:
type: simple
applicationContextPath: /application
adminContextPath: /admin
connector:
type: http
port: 8080
example.ymlに以下が記載されていますが、
server typeがsimpleだと複数ポートでlistenすることができません。
“use the simple server factory if you only want to run on a single port”
※connectorとして1つのconnectorしか割り当てることができません。
2.2 DefaultServerFactoryを使用する場合
ymlファイルのserverのtypeをdefaultにすると、
1ポートにapplicationContextPath、adminContextPathを
割り当てることができなくなります。
代わり?に、admin,applicationともに複数ポートでlistenできるようになります。
※applicationConnectorsでconnectorが複数系になっている。
server:
type: default
adminMinThreads: 1
adminMaxThreads: 64
applicationContextPath: /
applicationConnectors:
- type: http
port: 8080
- type: https
port: 8443
keyStorePath: example.keystore
keyStorePassword: example
validateCerts: false
adminContextPath: /admin
adminConnectors:
- type: http
port: 8081
- type: https
port: 8444
keyStorePath: example.keystore
keyStorePassword: example
validateCerts: false
type: default
のversionのdropwizardからです。 0.7.1のドキュメント上はその記述がありませんでした。
3. SimpleServerFactoryで複数ポートでlistenできない理由
実装を見た感じ複数ポートを定義することがすげー簡単にできるのになんでやってくれないんだ。
で、一瞬実装しようかと思いましたが、Websphere、Weblogic、GlassFish等でも、
そういえば、admin(管理コンソール)とapplicationのポートは違うのを思い出してやめました。
ポートが違えば、ポート塞いで、管理ポートはLAN内でのみアクセス可能で、
アプリのポートはPublic公開する等、セキュリティ的なところで融通きくってゆう話なのかと。
開発環境での動作確認はsimpleで、production環境では、default
(もっと真面目に作り込んだほうがいいのかもしれませんが..)
と思い、不勉強ながら勉強なりました。
以上です。
コメント