<?xml version="1.0" encoding="UTF-8"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This 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 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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 this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

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

<!-- =============================================================== -->
<!-- Configure the Jetty Server                                      -->
<!--                                                                 -->
<!-- Documentation of this file format can be found at:              -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax        -->
<!--                                                                 -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in.  For example:                              -->
<!--   java -jar start.jar etc/jetty-ssl.xml                         -->
<!--                                                                 -->
<!-- See start.ini file for the default configuraton files           -->
<!-- =============================================================== -->


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

  <!-- =========================================================== -->
  <!-- Server Thread Pool                                          -->
  <!-- =========================================================== -->
  <Set name="ThreadPool">
    <!-- Default queued blocking threadpool -->
    <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
      <Set name="minThreads">10</Set>
      <Set name="maxThreads">200</Set>
      <Set name="detailedDump">false</Set>
    </New>
  </Set>

  <!-- =========================================================== -->
  <!-- Set connectors                                              -->
  <!-- =========================================================== -->

  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host">
          <Property name="jetty.host"/>
        </Set>
        <Set name="port">
          <Property name="jetty.port" default="8080"/>
        </Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">2</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
        <Set name="lowResourcesConnections">20000</Set>
        <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
    </Arg>
  </Call>

  <!-- =========================================================== -->
  <!-- Jetty lifecycle listener that prints a message to open a    -->
  <!-- browser when the server is started. This is to provide      -->
  <!-- information to newbies so that they know what to do after   -->
  <!-- the server is started.                                      -->
  <!-- =========================================================== -->
  <Call name="addLifeCycleListener">
    <Arg>
      <New class="org.xwiki.tools.jetty.listener.NotifyListener" />
    </Arg>
  </Call>

  <!-- =========================================================== -->
  <!-- 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"/>
          </Item>
          <Item>
            <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
          </Item>
        </Array>
      </Set>
    </New>
  </Set>

  <!-- =============================================================== -->
  <!-- Create the deployment manager                                   -->
  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <!-- The deployment manager handles the lifecycle of deploying web   -->
  <!-- applications. Apps are provided by instances of the             -->
  <!-- AppProvider interface.  Typically these are provided by         -->
  <!-- one or more of:                                                 -->
  <!--   jetty-webapps.xml       - monitors webapps for wars and dirs  -->
  <!--   jetty-contexts.xml      - monitors contexts for context xml   -->
  <!--   jetty-templates.xml     - monitors contexts and templates     -->
  <!-- =============================================================== -->
  <Call name="addBean">
    <Arg>
      <New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
        <Set name="contexts">
          <Ref id="Contexts"/>
        </Set>
        <!-- Note: We don't need to define a "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" attribute
             since 1) we don't use tlds and 2) starting with Jetty 8.x, jetty employs a Servlet 3.0 way of finding
             tlds, see http://wiki.eclipse.org/Jetty/Howto/Configure_JSP#Jetty_8.x -->
        <!-- Note: Once we start using Servlet 3.0 we'll need to set the attribute named
             "org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern" to not incur too heavy startup times.
             See http://wiki.eclipse.org/Jetty/Howto/Avoid_slow_deployment.

             Example:

               <Call name="setContextAttribute">
                 <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
                 <Arg>.*/.*myPrefixedJarToScan1-[^/]\.jar$|.*/.*myPrefixedJarToScan2-[^/]\.jar$</Arg>
               </Call>
             -->


        <!-- Add a customize step to the deployment lifecycle -->
        <!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
        <Call name="insertLifeCycleNode">
          <Arg>deployed</Arg>
          <Arg>starting</Arg>
          <Arg>customise</Arg>
        </Call>
        <Call name="addLifeCycleBinding">
          <Arg>
            <New class="org.eclipse.jetty.deploy.bindings.DebugBinding">
              <Arg>customise</Arg>
            </New>
          </Arg>
        </Call>
        -->

      </New>
    </Arg>
  </Call>

  <!-- =============================================================== -->
  <!-- Add a ContextProvider to the deployment manager                 -->
  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <!-- This scans the webapps directory for war files and directories  -->
  <!-- to deploy.                                                      -->
  <!-- This configuration must be used with jetty-deploy.xml, which    -->
  <!-- creates the deployment manager instance                         -->
  <!-- =============================================================== -->
  <Ref id="DeploymentManager">
    <Call name="addAppProvider">
      <Arg>
        <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
          <Set name="monitoredDirName"><Property name="jetty.home" default="."/>/contexts
          </Set>
          <Set name="scanInterval">1</Set>
        </New>
      </Arg>
    </Call>
  </Ref>

  <!-- =========================================================== -->
  <!-- Configure Request Log                                       -->
  <!-- =========================================================== -->
  <Ref id="Handlers">
    <Call name="addHandler">
      <Arg>
        <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler">
          <Set name="requestLog">
            <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
              <Set name="filename"><Property name="xwiki.data.dir" default="."/>/logs/yyyy_mm_dd.request.log
              </Set>
              <Set name="filenameDateFormat">yyyy_MM_dd</Set>
              <Set name="retainDays">90</Set>
              <Set name="append">true</Set>
              <Set name="extended">false</Set>
              <Set name="logCookies">false</Set>
              <Set name="LogTimeZone">GMT</Set>
            </New>
          </Set>
        </New>
      </Arg>
    </Call>
  </Ref>

  <!-- =========================================================== -->
  <!-- extra options                                               -->
  <!-- =========================================================== -->
  <Set name="stopAtShutdown">true</Set>
  <Set name="sendServerVersion">true</Set>
  <Set name="sendDateHeader">true</Set>
  <Set name="gracefulShutdown">1000</Set>
  <Set name="dumpAfterStart">false</Set>
  <Set name="dumpBeforeStop">false</Set>

</Configure>
