1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.embedded;
20
21 import org.eclipse.jetty.server.Connector;
22 import org.eclipse.jetty.server.HttpConfiguration;
23 import org.eclipse.jetty.server.HttpConnectionFactory;
24 import org.eclipse.jetty.server.SecureRequestCustomizer;
25 import org.eclipse.jetty.server.Server;
26 import org.eclipse.jetty.server.ServerConnector;
27 import org.eclipse.jetty.server.SslConnectionFactory;
28 import org.eclipse.jetty.util.ssl.SslContextFactory;
29
30
31
32
33
34 public class ManyConnectors
35 {
36 public static void main(String[] args) throws Exception
37 {
38 String jetty_home = System.getProperty("jetty.home","../../jetty-distribution/target/distribution");
39 System.setProperty("jetty.home", jetty_home);
40
41
42 Server server = new Server();
43
44
45 HttpConfiguration http_config = new HttpConfiguration();
46 http_config.setSecureScheme("https");
47 http_config.setSecurePort(8443);
48 http_config.setOutputBufferSize(32768);
49
50
51 ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(http_config));
52 http.setPort(8080);
53 http.setIdleTimeout(30000);
54
55
56 SslContextFactory sslContextFactory = new SslContextFactory();
57 sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore");
58 sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
59 sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
60
61
62 HttpConfiguration https_config = new HttpConfiguration(http_config);
63 https_config.addCustomizer(new SecureRequestCustomizer());
64
65
66 ServerConnector https = new ServerConnector(server,
67 new SslConnectionFactory(sslContextFactory,"http/1.1"),
68 new HttpConnectionFactory(https_config));
69 https.setPort(8443);
70
71
72 server.setConnectors(new Connector[] { http, https });
73
74
75 server.setHandler(new HelloHandler());
76
77
78 server.start();
79 server.join();
80 }
81 }