<?xml version='1.0' encoding='utf-8'?>
<!--
  Dynamically generated by Chef on <%= node["fqdn"] %>
  Local modifications will be overwritten by Chef.
-->
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="<%= @shutdown_port %>" shutdown="SHUTDOWN">

  <% if @jmx_port -%>
    <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"
      rmiRegistryPortPlatform="<%= @jmx_port %>" rmiServerPortPlatform="<%= @jmx_port %>" />
  <% end -%>

  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <% if node['tomcat']['base_version'].to_i < 7 -%>
    <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <% end -%>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">
    <!-- @TODO - make it configurable -->
    <Executor name="tomcatThreadPool" maxThreads="200" minSpareThreads="25" />

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port <%= node["tomcat"]["port"] %>
    -->

    <% if @port -%>
      <Connector port="<%= @port %>"
        <% if @max_threads -%>
          maxThreads="<%= @max_threads %>"
        <% end -%>
        executor="tomcatThreadPool"
        protocol="org.apache.coyote.http11.Http11AprProtocol"
        URIEncoding="UTF-8"
        enableLookups="false"
        acceptCount="100"
        maxKeepAliveRequests="1"
        connectionTimeout="60000"
        disableUploadTimeout="true"
        server=" "
        <% if node["tomcat"]["maxHttpHeaderSize"] -%>
        maxHttpHeaderSize="<%= node["tomcat"]["maxHttpHeaderSize"] %>"
        <% end -%>
        <% if node["alfresco"]["ssl_enabled"] -%>
        secure="true"
        <% end -%>
      />
    <% end -%>

    <!-- Define a SSL HTTP/1.1 Connector on port <%= node["tomcat"]["ssl_port"] %>
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <% if @ssl_port -%>
      <Connector port="<%= @ssl_port %>" SSLEnabled="true"
               <% if @ssl_proxy_port -%>
                 proxyPort="<%= @ssl_proxy_port %>"
               <% end -%>
               protocol="org.apache.coyote.http11.Http11AprProtocol"
               keystoreFile="<%= node["alfresco"]["keystore_file"] %>"
               keystorePass="<%= node["alfresco"]["keystore_password"] %>"
               keystoreType="<%= node["alfresco"]["keystore_type"] %>"
               truststoreFile="<%= node["alfresco"]["truststore_file"] %>"
               truststoreType="<%= node["alfresco"]["truststore_type"] %>"
               truststorePass="<%= node["alfresco"]["truststore_password"] %>"
               maxThreads="<%= node["tomcat"]["ssl_max_threads"] %>" scheme="https" secure="true"
               clientAuth="<%= node["tomcat"]["client_auth"] %>" sslProtocol="TLS" />
    <% end -%>

    <!-- Define an AJP 1.3 Connector on port <%= node["tomcat"]["ajp_port"] %> -->
    <% if @ajp_port -%>
      <Connector port="<%= @ajp_port %>"
                 protocol="AJP/1.3"
                 tomcatAuthentication="<%= @tomcat_auth %>"
                 redirectPort="<%= @ssl_port %>" />
    <% end -%>
    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <Engine name="Catalina" defaultHost="localhost" <% unless node['tomcat']['jvm_route'].nil? %>jvmRoute="<%= node['tomcat']['jvm_route'] %>"<% end %>>

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            <% if node['tomcat']['base_version'].to_i < 7 -%>
            xmlValidation="false" xmlNamespaceAware="false"
            <% end -%>
            >
      </Host>
    </Engine>
  </Service>
</Server>
