1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.examples.httpserver;
20
21 import org.apache.mina.common.TransportType;
22 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
23 import org.apache.mina.io.IoAcceptor;
24 import org.apache.mina.io.filter.SSLFilter;
25 import org.apache.mina.registry.Service;
26 import org.apache.mina.registry.ServiceRegistry;
27 import org.apache.mina.registry.SimpleServiceRegistry;
28
29 /***
30 * (<b>Entry point</b>) HTTP server
31 *
32 * @author The Apache Directory Project (dev@directory.apache.org)
33 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
34 */
35 public class Main
36 {
37 /*** Choose your favorite port number. */
38 private static final int PORT = 8081;
39
40 private static final boolean USE_SSL = true;
41
42 public static void main( String[] args ) throws Exception
43 {
44 ServiceRegistry registry = new SimpleServiceRegistry();
45
46
47 if( USE_SSL )
48 {
49 addSSLSupport( registry );
50 }
51
52
53 Service service = new Service( "http", TransportType.SOCKET, PORT );
54 registry.bind( service, new HttpProtocolHandler() );
55
56 System.out.println( "Listening on port " + PORT );
57 }
58
59
60 private static void addSSLSupport( ServiceRegistry registry )
61 throws Exception
62 {
63 System.out.println( "SSL is enabled." );
64 SSLFilter sslFilter =
65 new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
66 IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
67 acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
68 }
69 }