Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit c021f25

Browse files
authored
Merge pull request #2 from SecureSkyTechnology/201903_https
自己署名証明書でhttpsに対応、--spring.config.locationで切り替え。
2 parents 99cf12d + 4aba592 commit c021f25

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SpringBoot2.x系で非同期メッセージングを使ったチャットアプ
44
内容:
55

66
* 2018-12 : Spring MVC で SseEmitter を使った Server-Sent Events のサンプルを作成。
7-
* 2019-03 : Spring MVC で WebSocket API を使ったデモを作成。
7+
* 2019-03 : Spring MVC で WebSocket API を使ったデモを作成。HTTPS有効化のデモ用設定ファイル/キーストア追加。
88

99
## 実行環境
1010

@@ -30,7 +30,19 @@ cd springboot2-async-chat-demo/
3030
./mvnw package
3131
3232
jarファイルから実行:
33-
java -jar target/springboot2-async-chat-demo-v20181227.1.jar
33+
java -jar target/springboot2-async-chat-demo-v201903.26.1.jar
34+
```
35+
36+
https(自己署名証明書)を有効にして https://localhost:18089/ で起動するには:
37+
38+
```
39+
java -jar target/springboot2-async-chat-demo-v201903.26.1.jar --spring.config.location=application-https.properties
40+
```
41+
42+
`keystore.p12` は AdoptOpenJDK8 の `keytool` で以下のように生成しています。
43+
44+
```
45+
keytool -genkeypair -keyalg RSA -dname "CN=test0, OU=ou0, O=org0, L=loc0, S=s0, C=JP" -alias self-signed-cert-t0 -keypass changeit -keystore keystore.p12 -storepass changeit -storetype PKCS12 -validity 3600
3446
```
3547

3648
2018-12時点で以下のブラウザで動作確認しています。

application-https.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server.port=18089
2+
3+
# https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/htmlsingle/#howto-configure-ssl
4+
server.ssl.key-store=keystore.p12
5+
server.ssl.key-store-password=changeit
6+
server.ssl.key-password=changeit
7+
8+
logging.level.root=INFO
9+
logging.level.org.springframework.web=DEBUG

keystore.p12

2.53 KB
Binary file not shown.

src/main/resources/static/plain-ws-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2>Spring Framework 組み込みのWebSocket APIのデモ</h2>
4141
};
4242
talog('event=' + JSON.stringify(eventInfo));
4343
}
44-
const endpoint = 'ws://' + location.host + '/plain-ws-demo';
44+
const endpoint = (location.protocol.startsWith('https') ? 'wss://' : 'ws://') + location.host + '/plain-ws-demo';
4545
let websocket = null;
4646

4747
document.querySelector('#connect-to-server').addEventListener('click', function(event) {

0 commit comments

Comments
 (0)