<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server"       -->
<!-- by adding a SPDY connector.                                   -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- It should not be used with jetty-https.xml as this connector  -->
<!-- can provide both HTTPS and SPDY connections                   -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- =========================================================== -->
  <!-- Setup the SSL Context factory used to establish all TLS     -->
  <!-- Connections and session.                                    -->
  <!--                                                             -->
  <!-- Consult the javadoc of o.e.j.util.ssl.SslContextFactory     -->
  <!-- o.e.j.server.HttpConnectionFactory for all configuration    -->
  <!-- that may be set here.                                       -->
  <!-- =========================================================== -->
  <New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
    <Set name="KeyStorePath"><Property name="jetty.home" default="." />/etc/keystore</Set>
    <Set name="KeyStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
    <Set name="KeyManagerPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
    <Set name="TrustStorePath"><Property name="jetty.home" default="." />/etc/keystore</Set>
    <Set name="TrustStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
  </New>

  <!-- =========================================================== -->
  <!-- Enables NPN debugging on System.err                         -->
  <!-- ===========================================================
  <Set class="org.eclipse.jetty.npn.NextProtoNego" name="debug" type="boolean">true</Set>
  -->

  <!-- =========================================================== -->
  <!-- Create a TLS specific HttpConfiguration based on the        -->
  <!-- common HttpConfiguration defined in jetty.xml               -->
  <!-- Add a SecureRequestCustomizer to extract certificate and    -->
  <!-- session information                                         -->
  <!-- =========================================================== -->
  <New id="tlsHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
    <Arg><Ref refid="httpConfig"/></Arg>
    <Call name="addCustomizer">
      <Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
    </Call>
  </New>

  <!-- =========================================================== -->
  <!-- This is the upstream server connector.                      -->
  <!-- It speaks non-SSL SPDY/3(HTTP) on port 9090.                -->
  <!-- =========================================================== -->
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ServerConnector">
        <Arg name="server">
          <Ref refid="Server"/>
        </Arg>
        <Arg name="factories">
          <Array type="org.eclipse.jetty.server.ConnectionFactory">
            <!-- SPDY/3 Connection factory -->
            <Item>
              <New class="org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory">
                <Arg name="version" type="int">3</Arg>
                <Arg name="config">
                  <Ref refid="tlsHttpConfig"/>
                </Arg>
              </New>
            </Item>
          </Array>
        </Arg>
        <Set name="port">9090</Set>
      </New>
    </Arg>
  </Call>

  <!-- =========================================================== -->
  <!-- This ProxyEngine translates the incoming SPDY/x(HTTP)       -->
  <!-- requests to SPDY/2(HTTP)                                    -->
  <!-- =========================================================== -->
  <New id="spdyProxyEngine" class="org.eclipse.jetty.spdy.server.proxy.SPDYProxyEngine">
    <Arg>
      <New class="org.eclipse.jetty.spdy.client.SPDYClient$Factory">
        <Call name="start"/>
      </New>
    </Arg>
  </New>

  <!-- =========================================================== -->
  <!-- The ProxyEngineSelector receives SPDY/x(HTTP) requests      -->
  <!-- from proxy connectors below and is configured to process    -->
  <!-- requests for host "localhost".                              -->
  <!-- Such requests are converted from SPDY/x(HTTP) to            -->
  <!-- SPDY/3(HTTP) by the configured ProxyEngine and forwarded    -->
  <!-- to 127.0.0.1:9090, where they are served by the upstream    -->
  <!-- server above.                                               -->
  <!-- =========================================================== -->
  <New id="proxyEngineSelector" class="org.eclipse.jetty.spdy.server.proxy.ProxyEngineSelector">
    <Call name="putProxyEngine">
      <Arg>spdy/3</Arg>
      <Arg>
        <Ref refid="spdyProxyEngine"/>
      </Arg>
    </Call>
    <Set name="proxyServerInfos">
      <Map>
        <Entry>
          <Item>localhost</Item>
          <Item>
            <New class="org.eclipse.jetty.spdy.server.proxy.ProxyEngineSelector$ProxyServerInfo">
              <Arg type="String">spdy/3</Arg>
              <Arg>127.0.0.1</Arg>
              <Arg type="int">9090</Arg>
            </New>
          </Item>
        </Entry>
      </Map>
    </Set>
  </New>

  <!-- =========================================================== -->
  <!-- These are the reverse proxy connectors accepting requests   -->
  <!-- from clients.                                               -->
  <!-- They accept non-SSL (on port 8080) and SSL (on port 8443)   -->
  <!-- HTTP, SPDY/2(HTTP) and SPDY/3(HTTP).                        -->
  <!-- Non-SPDY HTTP requests are converted to SPDY internally     -->
  <!-- and passed to the ProxyEngine above.                        -->
  <!-- =========================================================== -->
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.spdy.server.proxy.HTTPSPDYProxyServerConnector">
        <Arg>
          <Ref refid="Server"/>
        </Arg>
        <Arg>
          <Ref refid="proxyEngineSelector"/>
        </Arg>
        <Set name="Port">8080</Set>
      </New>
    </Arg>
  </Call>
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.spdy.server.proxy.HTTPSPDYProxyServerConnector">
        <Arg>
          <Ref refid="Server"/>
        </Arg>
        <Arg>
          <Ref refid="sslContextFactory"/>
        </Arg>
        <Arg>
          <Ref refid="proxyEngineSelector"/>
        </Arg>
        <Set name="Port">8443</Set>
      </New>
    </Arg>
  </Call>

</Configure>
