1 20 package org.apache.mina.example.httpserver.stream; 21 22 import java.net.InetSocketAddress ; 23 24 import org.apache.mina.common.DefaultIoFilterChainBuilder; 25 import org.apache.mina.common.IoAcceptor; 26 import org.apache.mina.common.IoAcceptorConfig; 27 import org.apache.mina.example.echoserver.ssl.BogusSSLContextFactory; 28 import org.apache.mina.filter.SSLFilter; 29 import org.apache.mina.transport.socket.nio.SocketAcceptor; 30 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; 31 import org.apache.mina.transport.socket.nio.SocketSessionConfig; 32 33 39 public class Main { 40 41 private static final int PORT = 8080; 42 43 private static final boolean USE_SSL = false; 44 45 public static void main(String [] args) throws Exception { 46 IoAcceptor acceptor = new SocketAcceptor(); 47 IoAcceptorConfig config = new SocketAcceptorConfig(); 48 DefaultIoFilterChainBuilder chain = config.getFilterChain(); 49 50 ((SocketSessionConfig) config.getSessionConfig()).setReuseAddress(true); 51 if (USE_SSL) { 53 addSSLSupport(chain); 54 } 55 56 acceptor.bind(new InetSocketAddress (PORT), new HttpProtocolHandler(), 58 config); 59 60 System.out.println("Listening on port " + PORT); 61 } 62 63 private static void addSSLSupport(DefaultIoFilterChainBuilder chain) 64 throws Exception { 65 System.out.println("SSL is enabled."); 66 SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory 67 .getInstance(true)); 68 chain.addLast("sslFilter", sslFilter); 69 } 70 } 71 | Popular Tags |