title: SPDY "Hello server" with Jetty
body: <p>I'm trying to setup a minimal HTTP over SPDY server with <a href="http://www.eclipse.org/jetty/" rel="nofollow noreferrer">Jetty</a>, for testing purposes.  I'm working on this code:</p>
  
  <pre><code>import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.eclipse.jetty.server.Connector;
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.spdy.http.HTTPSPDYServerConnector;
  import org.eclipse.jetty.util.ssl.SslContextFactory;
  
  import org.eclipse.jetty.server.Request;
  import org.eclipse.jetty.server.handler.AbstractHandler;
  
  public class MySPDYHelloServer {
      public static void main(String[] args) throws Exception {
          Server server = new Server();
  
          SslContextFactory sslFactory = new SslContextFactory();
          sslFactory.setKeyStorePath("dummy_keystore.jks");
          sslFactory.setKeyStorePassword("password");
          sslFactory.setProtocol("TLSv1");
  
          Connector connector = new HTTPSPDYServerConnector(sslFactory);
          connector.setPort(8443);
          server.addConnector(connector);
  
          server.setHandler( new AbstractHandler(){
              public void handle(String target, Request baseRequest,
                      HttpServletRequest request, HttpServletResponse response)
                      throws IOException, ServletException {
                  response.setContentType("text/html;charset=utf-8");
                  response.setStatus(HttpServletResponse.SC_OK);
                  baseRequest.setHandled(true);
                  response.getWriter().println("&lt;h1&gt;Hello World&lt;/h1&gt;");
              }
          } );
  
          server.start();
          server.join();
      }
  }
  </code></pre>
  
  <p>I've generated the keystore with:</p>
  
  <pre><code>keytool -genkey -keystore dummy_keystore.jks
  </code></pre>
  
  <p>When I point Google Chrome (SPDY enabled) to <code>https://localhost:8443</code> it warns me about the untrusted certificate then loads <em>forever</em>.</p>
  
  <p>The pure SPDY client-server examples (from <a href="http://www.smartjava.org/content/how-use-spdy-jetty" rel="nofollow noreferrer">here</a>) work and a simple HTTPS server work too; the issue seems related to the <a href="http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/spdy/http/HTTPSPDYServerConnector.html" rel="nofollow noreferrer">HTTPSPDYServerConnector</a> class.</p>
  
  <p>Here's the list of the JARs that I'm using:</p>
  
  <pre><code>jetty-all-7.6.7.v20120910.jar
  npn-boot-7.6.2.v20120308.jar
  servlet-api-2.5.jar
  spdy-core-7.6.7.v20120910.jar
  spdy-jetty-7.6.7.v20120910.jar
  spdy-jetty-http-7.6.7.v20120910.jar
  </code></pre>
  
  <p>And for what concerns my Java environment:</p>
  
  <pre><code>$ cat /opt/jdk1.7.0_07/release 
  JAVA_VERSION="1.7.0"
  OS_NAME="Linux"
  OS_VERSION="2.6"
  OS_ARCH="i586"
  </code></pre>
  
  <h1>Solution addendum</h1>
  
  <p><a href="https://stackoverflow.com/users/1185262/jesse-mcconnell">jesse mcconnell</a> provided the <a href="https://stackoverflow.com/a/12689770/477168">answer</a>, anyway those who use Eclipse may find the following useful.</p>
  
  <p>The JAR <code>npn-boot-7.6.2.v20120308.jar</code> must (also) be placed in:</p>
  
  <pre><code>Run Configurations... -&gt; Classpath -&gt; Bootstrap Entries -&gt; Add External JARs
  </code></pre>
  
  <p>Note that since <strong>order matters</strong>, that entry must appear <strong>before</strong> the <code>JRE System Library</code>.</p>