1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.http.websocketx.sslserver;
17
18 import java.net.InetSocketAddress;
19 import java.util.concurrent.Executors;
20
21 import org.jboss.netty.bootstrap.ServerBootstrap;
22 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class WebSocketSslServer {
43
44 private final int port;
45
46 public WebSocketSslServer(int port) {
47 this.port = port;
48 }
49
50 public void run() {
51
52 ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
53 Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
54
55
56 bootstrap.setPipelineFactory(new WebSocketSslServerPipelineFactory());
57
58
59 bootstrap.bind(new InetSocketAddress(port));
60
61 System.out.println("Web socket server started at port " + port + '.');
62 System.out.println("Open your browser and navigate to https://localhost:" + port + '/');
63 }
64
65 public static void main(String[] args) {
66 int port;
67 if (args.length > 0) {
68 port = Integer.parseInt(args[0]);
69 } else {
70 port = 8443;
71 }
72
73 String keyStoreFilePath = System.getProperty("keystore.file.path");
74 if (keyStoreFilePath == null || keyStoreFilePath.length() == 0) {
75 System.out.println("ERROR: System property keystore.file.path not set. Exiting now!");
76 System.exit(1);
77 }
78
79 String keyStoreFilePassword = System.getProperty("keystore.file.password");
80 if (keyStoreFilePassword == null || keyStoreFilePassword.length() == 0) {
81 System.out.println("ERROR: System property keystore.file.password not set. Exiting now!");
82 System.exit(1);
83 }
84
85 new WebSocketSslServer(port).run();
86 }
87 }