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

<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
        <Set name="keyStorePath">src/main/resources/keystore.jks</Set>
        <Set name="keyStorePassword">storepwd</Set>
        <Set name="trustStorePath">src/main/resources/truststore.jks</Set>
        <Set name="trustStorePassword">storepwd</Set>
        <Set name="protocol">TLSv1</Set>
    </New>

    <!--
    <Set class="org.eclipse.jetty.npn.NextProtoNego" name="debug" type="boolean">true</Set>
    -->

    <New id="tlsHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
        <Arg>
            <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
                <Set name="secureScheme">https</Set>
                <Set name="securePort">
                    <Property name="jetty.tls.port" default="8443"/>
                </Set>
                <Set name="outputBufferSize">32768</Set>
                <Set name="requestHeaderSize">8192</Set>
                <Set name="responseHeaderSize">8192</Set>

                <!-- Uncomment to enable handling of X-Forwarded- style headers
                <Call name="addCustomizer">
                    <Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
                </Call>
                -->
            </New>
        </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) request 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>
