1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.http.upload;
17
18 import org.jboss.netty.bootstrap.ServerBootstrap;
19 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
20 import org.jboss.netty.handler.ssl.SslContext;
21 import org.jboss.netty.handler.ssl.util.SelfSignedCertificate;
22
23 import java.net.InetSocketAddress;
24 import java.util.concurrent.Executors;
25
26 public final class HttpUploadServer {
27
28 static final boolean SSL = System.getProperty("ssl") != null;
29 static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));
30
31 public static void main(String[] args) throws Exception {
32
33 final SslContext sslCtx;
34 if (SSL) {
35 SelfSignedCertificate ssc = new SelfSignedCertificate();
36 sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
37 } else {
38 sslCtx = null;
39 }
40
41
42 ServerBootstrap bootstrap = new ServerBootstrap(
43 new NioServerSocketChannelFactory(
44 Executors.newCachedThreadPool(),
45 Executors.newCachedThreadPool()));
46
47
48 bootstrap.setPipelineFactory(new HttpUploadServerPipelineFactory(sslCtx));
49
50
51 bootstrap.bind(new InetSocketAddress(PORT));
52 }
53 }