private Server CreateJettyServer() { try { IPAddress localhost = Sharpen.Extensions.GetAddressByName("localhost"); string host = "localhost"; Socket ss = Sharpen.Extensions.CreateServerSocket(0, 50, localhost); int port = ss.GetLocalPort(); ss.Close(); Server server = new Server(0); if (!ssl) { server.GetConnectors()[0].SetHost(host); server.GetConnectors()[0].SetPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.SetHost(host); c.SetPort(port); c.SetNeedClientAuth(false); c.SetKeystore(keyStore); c.SetKeystoreType(keyStoreType); c.SetKeyPassword(keyStorePassword); server.SetConnectors(new Connector[] { c }); } return(server); } catch (Exception ex) { throw new RuntimeException("Could not stop embedded servlet container, " + ex.Message , ex); } }
private static Org.Mortbay.Jetty.Server CreateJettyServer(string keyStore, string password, int inPort) { try { bool ssl = keyStore != null; IPAddress localhost = Extensions.GetAddressByName("localhost"); string host = "localhost"; Socket ss = Extensions.CreateServerSocket((inPort < 0) ? 0 : inPort, 50, localhost); int port = ss.GetLocalPort(); ss.Close(); Org.Mortbay.Jetty.Server server = new Org.Mortbay.Jetty.Server(0); if (!ssl) { server.GetConnectors()[0].SetHost(host); server.GetConnectors()[0].SetPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.SetHost(host); c.SetPort(port); c.SetNeedClientAuth(false); c.SetKeystore(keyStore); c.SetKeystoreType("jks"); c.SetKeyPassword(password); server.SetConnectors(new Connector[] { c }); } return(server); } catch (Exception ex) { throw new RuntimeException("Could not start embedded servlet container, " + ex.Message , ex); } }