<?xml version="1.0"?>
<!--
  ~ Artifactory is a binaries repository manager.
  ~ Copyright (C) 2012 JFrog Ltd.
  ~
  ~ Artifactory is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU Lesser General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ Artifactory is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public License
  ~ along with Artifactory.  If not, see <http://www.gnu.org/licenses/>.
  -->

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- =============================================================== -->
<!-- Configure the Jetty Server                                      -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Server Thread Pool                                          -->
    <!-- =========================================================== -->
    <Set name="ThreadPool">
        <!--<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
            <Set name="minThreads">10</Set>
            <Set name="maxThreads">100</Set>
        </New>-->
        <New class="org.eclipse.jetty.util.thread.ExecutorThreadPool"/>
    </Set>

    <!-- =========================================================== -->
    <!-- Set connectors                                              -->
    <!-- =========================================================== -->
    <!-- One of each type!                                           -->
    <!-- =========================================================== -->

    <!-- Use this connector for many frequently idle connections
         and for threadless continuations.
    -->
    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <Set name="host">
                    <SystemProperty name="jetty.host"/>
                </Set>
                <Set name="port">
                    <SystemProperty name="jetty.port" default="8081"/>
                </Set>
                <Set name="forwarded">true</Set>
                <Set name="maxIdleTime">30000</Set>
                <Set name="Acceptors">1</Set>
                <Set name="lowResourceMaxIdleTime">3000</Set>
                <!--
                On Windows uncomment the following line to improve performance.
                See: http://docs.codehaus.org/display/JETTY/Slow+Win2003
                -->
                <!--<Set name="responseBufferSize">512</Set>-->
            </New>
        </Arg>
    </Call>

    <!-- AJP13 Connector configuration -->
    <!--
    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.ajp.Ajp13SocketConnector">
                <Set name="port">8011</Set>
            </New>
        </Arg>
    </Call>
    -->

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <!-- To add a HTTPS SSL listener                                     -->
    <!-- see jetty-ssl.xml to add an ssl connector. use                  -->
    <!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml             -->
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->


    <!-- ======================================================= -->
    <!-- Configure artifactory                                   -->
    <!-- ======================================================= -->
    <New id="artifactory" class="org.eclipse.jetty.webapp.WebAppContext">
        <Call name="setContextPath">
            <Arg>/artifactory</Arg>
        </Call>
        <Call name="setWar">
            <Arg><SystemProperty name="artifactory.home" default=".."/>/webapps/artifactory.war
            </Arg>
        </Call>
        <Get name="SessionHandler">
            <Set name="SessionManager">
                <New class="org.eclipse.jetty.server.session.HashSessionManager">
                    <Set name="maxInactiveInterval">1600</Set>
                </New>
            </Set>
        </Get>
    </New>

    <!-- =========================================================== -->
    <!-- Set handler Collection Structure                            -->
    <!-- =========================================================== -->
    <Set name="handler">
        <New id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
            <Set name="handlers">
                <Array type="org.eclipse.jetty.server.Handler">
                    <Item>
                        <New id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
                            <Call name="addHandler">
                                <Arg>
                                    <Ref id="artifactory">
                                        <Set name="configurationClasses">
                                            <!--
                                            Use a custom list that omits org.eclipse.jetty.webapp.TagLibConfiguration
                                            to save time on redundant TLD scanning.
                                            -->
                                            <Array type="java.lang.String">
                                                <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
                                                <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
                                                <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
                                                <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
                                                <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
                                            </Array>
                                        </Set>
                                    </Ref>
                                </Arg>
                            </Call>
                        </New>
                    </Item>
                    <Item>
                        <New id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
                    </Item>
                    <Item>
                        <New id="requestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
                    </Item>
                </Array>
            </Set>
        </New>
    </Set>

    <!-- =========================================================== -->
    <!-- Configure Request Log                                       -->
    <!-- =========================================================== -->
    <Ref id="requestLog">
        <Set name="requestLog">
            <New id="requestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
                <Arg><SystemProperty name="artifactory.home" default=".."/>/logs/yyyy_mm_dd.request.log
                </Arg>
                <Set name="retainDays">90</Set>
                <Set name="append">true</Set>
                <Set name="extended">false</Set>
                <Set name="LogTimeZone">GMT</Set>
            </New>
        </Set>
    </Ref>

    <!-- =========================================================== -->
    <!-- extra options                                               -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
    <Set name="gracefulShutdown">1000</Set>
    <!-- ensure/prevent Server: header being sent to browsers        -->
    <Set name="sendServerVersion">true</Set>
    <!--<Set name="sendDateHeader">true</Set>-->

</Configure>
