예제 #1
0
        private static Uri GetJettyURL(Org.Mortbay.Jetty.Server server)
        {
            bool ssl = server.GetConnectors()[0].GetType() == typeof(SslSocketConnectorSecure
                                                                     );

            try
            {
                string scheme = (ssl) ? "https" : "http";
                return(new Uri(scheme + "://" + server.GetConnectors()[0].GetHost() + ":" + server
                               .GetConnectors()[0].GetPort()));
            }
            catch (UriFormatException ex)
            {
                throw new RuntimeException("It should never happen, " + ex.Message, ex);
            }
        }
예제 #2
0
 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);
     }
 }