View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.embedded;
20  
21  import org.eclipse.jetty.server.Connector;
22  import org.eclipse.jetty.server.Server;
23  import org.eclipse.jetty.server.nio.SelectChannelConnector;
24  import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
25  import org.eclipse.jetty.util.ssl.SslContextFactory;
26  import org.eclipse.jetty.util.thread.QueuedThreadPool;
27  
28  /* ------------------------------------------------------------ */
29  /**
30   * A Jetty server with multiple connectors.
31   * 
32   */
33  public class ManyConnectors
34  {
35      public static void main(String[] args) throws Exception
36      {
37          Server server = new Server();
38  
39          SelectChannelConnector connector0 = new SelectChannelConnector();
40          connector0.setPort(8080);
41          connector0.setMaxIdleTime(30000);
42          connector0.setRequestHeaderSize(8192);
43  
44          SelectChannelConnector connector1 = new SelectChannelConnector();
45          connector1.setHost("127.0.0.1");
46          connector1.setPort(8888);
47          connector1.setThreadPool(new QueuedThreadPool(20));
48          connector1.setName("admin");
49  
50          SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();
51          String jetty_home = System.getProperty("jetty.home","../jetty-distribution/target/distribution");
52          System.setProperty("jetty.home",jetty_home);
53          ssl_connector.setPort(8443);
54          SslContextFactory cf = ssl_connector.getSslContextFactory();
55          cf.setKeyStorePath(jetty_home + "/etc/keystore");
56          cf.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
57          cf.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
58  
59          server.setConnectors(new Connector[]
60          { connector0, connector1, ssl_connector });
61  
62          server.setHandler(new HelloHandler());
63  
64          server.start();
65          server.join();
66      }
67  }