<!--
   - Resin 4.0 configuration file for a clustered/load-balance environment
  -->
<resin xmlns="http://caucho.com/ns/resin"
       xmlns:resin="urn:java:com.caucho.resin">

  <!-- adds all .jar files under the resin/lib directory -->
  <class-loader>
    <tree-loader path="${resin.home}/ext-lib"/>
    <tree-loader path="${resin.root}/ext-lib"/>

    <tree-loader path="${resin.home}/lib"/>
    <tree-loader path="${resin.root}/lib"/>
  </class-loader>

  <!--
     - jars with maven dependencies can be placed in project-jars to be used
     - by web-apps
    -->
  <resin:ProjectJarRepository path="${resin.root}/project-jars"/>

  <!--
     - Resin-managed data, including sessions, administration, and clustering
    -->
  <resin-data-directory>${resin.root}/resin-data</resin-data-directory>
  
  <!--
     - Remote management requires at least one enabled admin user.
    -->
  <resin:AdminAuthenticator>
    <resin:import path="${__DIR__}/admin-users.xml" optional="true"/>
  </resin:AdminAuthenticator>

  <!--
     - Logging configuration for the JDK logging API.
    -->
  <log-handler name="" level="all" path="stdout:"
               timestamp="[%H:%M:%S.%s] {%{thread}} "/>

  <!--
     - 'info' for production
     - 'fine' or 'finer' for development and troubleshooting
    -->
  <logger name="com.caucho" level="info"/>

  <logger name="com.caucho.java" level="config"/>
  <logger name="com.caucho.loader" level="config"/>

  <!--
     - For production sites, change dependency-check-interval to something
     - like 600s, so it only checks for updates every 10 minutes.
    -->
  <dependency-check-interval>2s</dependency-check-interval>

  <!--
     - SMTP server for sending mail notifications
    -->
  <system-property mail.smtp.host="127.0.0.1"/>
  <system-property mail.smtp.port="25"/>

  <!--
     - Sets the default character encoding to utf-8
     -
     - <character-encoding>utf-8</character-encoding>
    -->

  <!--
     - You can change the compiler to "javac", "eclipse" or "internal".
    -->
  <javac compiler="internal" args="-source 1.5"/>

  <cluster-default>
    <!-- standard servlet behavior, including .jsp, .php, and WEB-INF -->
    <resin:import path="${__DIR__}/app-default.xml"/>
    
    <!--
       - Admin services
      -->
    <resin:DeployService/>
    
    <resin:if test="${resin.professional}">
      <resin:JmxService/>
      <resin:LogService/>
      <resin:StatService/>
      <resin:XaLogService/>
    </resin:if>
    
    <!--
       - Configuration for the health monitoring system
      -->
    <resin:if test="${resin.professional}">
      <resin:import path="${__DIR__}/health.xml"/>
    </resin:if>
  </cluster-default>

  <cluster id="app-tier">
    <!-- sets the content root for the cluster, relative to resin.root -->
    <root-directory>.</root-directory>

    <!-- enables development error pages -->
    <development-mode-error-page/>

    <server-default>
      <!-- The http port -->
      <http address="*" port="8080"/>

      <!-- SSL port configuration: -->
      <http address="*" port="8443">
        <openssl>
          <certificate-file>keys/gryffindor.crt</certificate-file>
          <certificate-key-file>keys/gryffindor.key</certificate-key-file>
          <password>my-password</password>
        </openssl>
      </http>

      <!--
         - The JVM arguments
        -->
      <jvm-arg>-Xmx256m</jvm-arg>
      <jvm-arg>-Xss1m</jvm-arg>
      <jvm-arg>-Xdebug</jvm-arg>
      <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

      <!--
         - Uncomment to enable admin heap dumps
         - <jvm-arg>-agentlib:resin</jvm-arg>
	 -
	 - Uncomment for low-memory overhead
         - <jvm-arg>-Dcaucho.smallmem</jvm-arg>
        -->

      <!--
         - arguments for the watchdog process
        -->
      <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>

      <!--
         - Configures the minimum free memory allowed before Resin
         - will force a restart.
        -->
      <memory-free-min>1M</memory-free-min>

      <!-- Maximum number of threads. -->
      <thread-max>256</thread-max>

      <!-- Configures the socket timeout -->
      <socket-timeout>65s</socket-timeout>

      <!-- Configures the keepalive -->
      <keepalive-timeout>15s</keepalive-timeout>

      <!--
         - If starting Resin as root on Unix, specify the user name
         - and group name for the web server user.
        -->
      <resin:if test="${resin.userName == 'root'}">
        <user-name>resin</user-name>
        <group-name>resin</group-name>
      </resin:if>
    </server-default>

    <!-- define the servers in the cluster -->
    <server id="" address="127.0.0.1" port="6800"/>

    <!--
       - For security, use a different cookie for SSL sessions.
       - <ssl-session-cookie>SSL_JSESSIONID</ssl-session-cookie>
      -->

    <!--
       - Enables the cache (available in Resin Professional) 
      -->
    <resin:if test="${resin.professional}">
    <cache path="cache" memory-size="64M">
      <!-- Vary header rewriting for IE -->
      <rewrite-vary-as-private/>
    </cache>
    </resin:if>

    <!--
       - Enables periodic checking of the server status and
       - check for deadlocks..
       -
       - All servers can add <url>s to be checked.
      -->
    <resin:if test="${resin.professional}">
      <resin:PingThread>
        <!-- <url>http://localhost:8080/test-ping.jsp</url> -->
      </resin:PingThread>
    </resin:if>

    <!--
       - Defaults applied to each web-app.
      -->
    <web-app-default>
      <prologue>
        <!--
           - Enable EL expressions in Servlet and Filter init-param
          -->
        <allow-servlet-el/>
      </prologue>
      
      <!--
         - Sets timeout values for cacheable pages, e.g. static pages.
        -->
      <cache-mapping url-pattern="/" expires="5s"/>
      <cache-mapping url-pattern="*.gif" expires="60s"/>
      <cache-mapping url-pattern="*.jpg" expires="60s"/>
      <cache-mapping url-pattern="*.png" expires="60s"/>

      <!--
         - for security, disable session URLs by default.
        -->
      <session-config>
        <enable-url-rewriting>false</enable-url-rewriting>
      </session-config>

      <!--
         - For security, set the HttpOnly flag in cookies.
         - <cookie-http-only/>
        -->

      <!--
         - Some JSP packages have incorrect .tld files.  It's possible to
         - set validate-taglib-schema to false to work around these packages.
        -->
      <jsp>
        <validate-taglib-schema>true</validate-taglib-schema>
        <fast-jstl>true</fast-jstl>
      </jsp>
      <jsf fast-jsf='false'/>
    </web-app-default>

    <!--
       - Sample database pool configuration
       -
       - The JDBC name is java:comp/env/jdbc/test
         <database>
           <jndi-name>jdbc/mysql</jndi-name>
           <driver type="org.mysql.jdbc.Driver">
             <url>jdbc:mysql://localhost:3306/test</url>
             <user></user>
             <password></password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>
      -->

    <!--
       - Default host configuration applied to all virtual hosts.
      -->
    <host-default>
      <!--
         - With another web server, like Apache, this can be commented out
         - because the web server will log this information.
        -->
      <access-log path="log/access.log" 
            format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
            rollover-period="1W"/>

      <!-- creates the webapps directory for .war expansion -->
      <web-app-deploy path="webapps"/>
    </host-default>

    <!-- configures a deployment directory for virtual hosts -->
    <host-deploy path="hosts">
      <host-default>
        <resin:import path="host.xml" optional="true"/>
      </host-default>
    </host-deploy>

    <!-- configures the default host, matching any host name -->
    <host id="" root-directory=".">
      <!--
         - configures an explicit root web-app matching the
         - webapp's ROOT
        -->
      <web-app id="/" root-directory="webapps/ROOT"/>

      <web-app id="/resin-admin" root-directory="${resin.root}/doc/admin">
        <!--
           - Administration application /resin-admin
          -->
        <prologue>
          <resin:set var="resin_admin_external" value="false"/>
          <resin:set var="resin_admin_insecure" value="true"/>
        </prologue>
      </web-app>

      <!--
      <web-app id="/resin-config" root-directory="${resin.root}/doc/config"/>
      -->
      
      <web-app id="/resin-doc" root-directory="${resin.root}/doc/resin-doc"/>
    </host>
  </cluster>

  <!--
     - Configuration for the web-tier/load-balancer
    -->
  <resin:if test="${resin.professional}">
    <cluster id="web-tier" root-directory="web-tier">
      <server-default>
        <!-- The http port -->
        <http address="*" port="9080"/>
      </server-default>

      <server id="web-a" address="127.0.0.1" port="6700"/>

      <cache path="cache" memory-size="64M"/>

      <development-mode-error-page/>

      <host id="">
        <web-app id="/">

           <resin:LoadBalance regexp="" cluster="app-tier"/>
	   
        </web-app>
	
        <web-app id="/resin-admin" root-directory="${resin.root}/doc/admin"/>
      </host>
    </cluster>
  </resin:if>
</resin>

