View | Details | Raw Unified | Return to bug 55383
Collapse All | Expand All

(-)modules/jdbc-pool/doc/jdbc-pool.xml (-91 / +75 lines)
Lines 41-47 Link Here
41
41
42
  <p>So why do we need a new connection pool?</p>
42
  <p>So why do we need a new connection pool?</p>
43
43
44
  <p>Here are a few of the reasons:
44
  <p>Here are a few of the reasons:</p>
45
    <ol>
45
    <ol>
46
      <li>commons-dbcp is single threaded, in order to be thread safe commons-dbcp locks the entire pool, even during query validation.</li>
46
      <li>commons-dbcp is single threaded, in order to be thread safe commons-dbcp locks the entire pool, even during query validation.</li>
47
      <li>commons-dbcp is slow - as the number of logical CPUs grow, the performance suffers, the above point shows that there is not support for high concurrency
47
      <li>commons-dbcp is slow - as the number of logical CPUs grow, the performance suffers, the above point shows that there is not support for high concurrency
Lines 59-67 Link Here
59
      <li>Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned,
59
      <li>Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned,
60
          the pool will awake the correct thread waiting. Most pools will simply starve.</li>
60
          the pool will awake the correct thread waiting. Most pools will simply starve.</li>
61
    </ol>
61
    </ol>
62
  </p>
63
62
64
  <p>Features added over other connection pool implementations
63
  <p>Features added over other connection pool implementations</p>
65
    <ol>
64
    <ol>
66
      <li>Support for highly concurrent environments and multi core/cpu systems.</li>
65
      <li>Support for highly concurrent environments and multi core/cpu systems.</li>
67
      <li>Dynamic implementation of interface, will support <code>java.sql</code> and <code>javax.sql</code> interfaces for
66
      <li>Dynamic implementation of interface, will support <code>java.sql</code> and <code>javax.sql</code> interfaces for
Lines 96-102 Link Here
96
          This is achieved using the <code>dataSource</code> and <code>dataSourceJNDI</code> attributes.</li>
95
          This is achieved using the <code>dataSource</code> and <code>dataSourceJNDI</code> attributes.</li>
97
      <li>XA connection support</li>
96
      <li>XA connection support</li>
98
    </ol>
97
    </ol>
99
  </p>
100
98
101
99
102
</section>
100
</section>
Lines 173-179 Link Here
173
    </attribute>
171
    </attribute>
174
172
175
    <attribute name="defaultTransactionIsolation" required="false">
173
    <attribute name="defaultTransactionIsolation" required="false">
176
      <p>(String) The default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc )
174
      <p>(String) The default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc )</p>
177
         <ul>
175
         <ul>
178
           <li><code>NONE</code></li>
176
           <li><code>NONE</code></li>
179
           <li><code>READ_COMMITTED</code></li>
177
           <li><code>READ_COMMITTED</code></li>
Lines 181-188 Link Here
181
           <li><code>REPEATABLE_READ</code></li>
179
           <li><code>REPEATABLE_READ</code></li>
182
           <li><code>SERIALIZABLE</code></li>
180
           <li><code>SERIALIZABLE</code></li>
183
         </ul>
181
         </ul>
184
         If not set, the method will not be called and it defaults to the JDBC driver.
182
         <p>If not set, the method will not be called and it defaults to the JDBC driver.</p>
185
      </p>
186
    </attribute>
183
    </attribute>
187
184
188
    <attribute name="defaultCatalog" required="false">
185
    <attribute name="defaultCatalog" required="false">
Lines 673-680 Link Here
673
  <p>Other examples of Tomcat configuration for JDBC usage can be found <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html">in the Tomcat documentation</a>. </p>
670
  <p>Other examples of Tomcat configuration for JDBC usage can be found <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html">in the Tomcat documentation</a>. </p>
674
  <subsection name="Plain Ol' Java">
671
  <subsection name="Plain Ol' Java">
675
    <p>Here is a simple example of how to create and use a data source.</p>
672
    <p>Here is a simple example of how to create and use a data source.</p>
676
<source>
673
<source><![CDATA[  import java.sql.Connection;
677
  import java.sql.Connection;
678
  import java.sql.ResultSet;
674
  import java.sql.ResultSet;
679
  import java.sql.Statement;
675
  import java.sql.Statement;
680
676
Lines 705-712 Link Here
705
          p.setLogAbandoned(true);
701
          p.setLogAbandoned(true);
706
          p.setRemoveAbandoned(true);
702
          p.setRemoveAbandoned(true);
707
          p.setJdbcInterceptors(
703
          p.setJdbcInterceptors(
708
            &quot;org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;&quot;+
704
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
709
            &quot;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer&quot;);
705
            "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
710
          DataSource datasource = new DataSource();
706
          DataSource datasource = new DataSource();
711
          datasource.setPoolProperties(p);
707
          datasource.setPoolProperties(p);
712
708
Lines 727-764 Link Here
727
          }
723
          }
728
      }
724
      }
729
725
730
  }
726
  }]]></source>
731
</source>
732
  </subsection>
727
  </subsection>
733
  <subsection name="As a Resource">
728
  <subsection name="As a Resource">
734
    <p>And here is an example on how to configure a resource for JNDI lookups</p>
729
    <p>And here is an example on how to configure a resource for JNDI lookups</p>
735
<source>
730
<source><![CDATA[<Resource name="jdbc/TestDB"
736
&lt;Resource name=&quot;jdbc/TestDB&quot;
731
          auth="Container"
737
          auth=&quot;Container&quot;
732
          type="javax.sql.DataSource"
738
          type=&quot;javax.sql.DataSource&quot;
733
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
739
          factory=&quot;org.apache.tomcat.jdbc.pool.DataSourceFactory&quot;
734
          testWhileIdle="true"
740
          testWhileIdle=&quot;true&quot;
735
          testOnBorrow="true"
741
          testOnBorrow=&quot;true&quot;
736
          testOnReturn="false"
742
          testOnReturn=&quot;false&quot;
737
          validationQuery="SELECT 1"
743
          validationQuery=&quot;SELECT 1&quot;
738
          validationInterval="30000"
744
          validationInterval=&quot;30000&quot;
739
          timeBetweenEvictionRunsMillis="30000"
745
          timeBetweenEvictionRunsMillis=&quot;30000&quot;
740
          maxActive="100"
746
          maxActive=&quot;100&quot;
741
          minIdle="10"
747
          minIdle=&quot;10&quot;
742
          maxWait="10000"
748
          maxWait=&quot;10000&quot;
743
          initialSize="10"
749
          initialSize=&quot;10&quot;
744
          removeAbandonedTimeout="60"
750
          removeAbandonedTimeout=&quot;60&quot;
745
          removeAbandoned="true"
751
          removeAbandoned=&quot;true&quot;
746
          logAbandoned="true"
752
          logAbandoned=&quot;true&quot;
747
          minEvictableIdleTimeMillis="30000"
753
          minEvictableIdleTimeMillis=&quot;30000&quot;
748
          jmxEnabled="true"
754
          jmxEnabled=&quot;true&quot;
749
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
755
          jdbcInterceptors=&quot;org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
750
            org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
756
            org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer&quot;
751
          username="root"
757
          username=&quot;root&quot;
752
          password="password"
758
          password=&quot;password&quot;
753
          driverClassName="com.mysql.jdbc.Driver"
759
          driverClassName=&quot;com.mysql.jdbc.Driver&quot;
754
          url="jdbc:mysql://localhost:3306/mysql"/>]]></source>
760
          url=&quot;jdbc:mysql://localhost:3306/mysql&quot;/&gt;
761
</source>
762
755
763
  </subsection>
756
  </subsection>
764
  <subsection name="Asynchronous Connection Retrieval">
757
  <subsection name="Asynchronous Connection Retrieval">
Lines 765-779 Link Here
765
    <p> The Tomcat JDBC connection pool supports asynchronous connection retrieval without adding additional threads to the
758
    <p> The Tomcat JDBC connection pool supports asynchronous connection retrieval without adding additional threads to the
766
        pool library. It does this by adding a method to the data source called <code>Future&lt;Connection&gt; getConnectionAsync()</code>.
759
        pool library. It does this by adding a method to the data source called <code>Future&lt;Connection&gt; getConnectionAsync()</code>.
767
        In order to use the async retrieval, two conditions must be met:
760
        In order to use the async retrieval, two conditions must be met:
761
    </p>
768
        <ol>
762
        <ol>
769
          <li>You must configure the <code>fairQueue</code> property to be <code>true</code>.</li>
763
          <li>You must configure the <code>fairQueue</code> property to be <code>true</code>.</li>
770
          <li>You will have to cast the data source to <code>org.apache.tomcat.jdbc.pool.DataSource</code></li>
764
          <li>You will have to cast the data source to <code>org.apache.tomcat.jdbc.pool.DataSource</code></li>
771
        </ol>
765
        </ol>
772
        An example of using the async feature is show below.
766
        An example of using the async feature is show below.
773
<source>
767
<source><![CDATA[  Connection con = null;
774
  Connection con = null;
775
  try {
768
  try {
776
    Future&lt;Connection&gt; future = datasource.getConnectionAsync();
769
    Future<Connection> future = datasource.getConnectionAsync();
777
    while (!future.isDone()) {
770
    while (!future.isDone()) {
778
      System.out.println("Connection is not yet available. Do some background work");
771
      System.out.println("Connection is not yet available. Do some background work");
779
      try {
772
      try {
Lines 784-792 Link Here
784
    }
777
    }
785
    con = future.get(); //should return instantly
778
    con = future.get(); //should return instantly
786
    Statement st = con.createStatement();
779
    Statement st = con.createStatement();
787
    ResultSet rs = st.executeQuery("select * from user");
780
    ResultSet rs = st.executeQuery("select * from user");]]></source>
788
</source>
781
789
    </p>
790
  </subsection>
782
  </subsection>
791
  <subsection name="Interceptors">
783
  <subsection name="Interceptors">
792
    <p>Interceptors are a powerful way to enable, disable or modify functionality on a specific connection or its sub components.
784
    <p>Interceptors are a powerful way to enable, disable or modify functionality on a specific connection or its sub components.
Lines 796-838 Link Here
796
       the pool itself will not reset them.</p>
788
       the pool itself will not reset them.</p>
797
    <p>An interceptor has to extend the <code>org.apache.tomcat.jdbc.pool.JdbcInterceptor</code> class. This class is fairly simple,
789
    <p>An interceptor has to extend the <code>org.apache.tomcat.jdbc.pool.JdbcInterceptor</code> class. This class is fairly simple,
798
       You will need to have a no arg constructor</p>
790
       You will need to have a no arg constructor</p>
799
<source>
791
<source><![CDATA[  public JdbcInterceptor() {
800
  public JdbcInterceptor() {
792
  }]]></source>
801
  }
802
</source>
803
    <p>
793
    <p>
804
       When a connection is borrowed from the pool, the interceptor can initialize or in some other way react to the event by implementing the
794
       When a connection is borrowed from the pool, the interceptor can initialize or in some other way react to the event by implementing the
805
<source>
795
    </p>
806
  public abstract void reset(ConnectionPool parent, PooledConnection con);
796
<source><![CDATA[  public abstract void reset(ConnectionPool parent, PooledConnection con);]]></source>
807
</source>
797
    <p>
808
       method. This method gets called with two parameters, a reference to the connection pool itself <code>ConnectionPool parent</code>
798
       method. This method gets called with two parameters, a reference to the connection pool itself <code>ConnectionPool parent</code>
809
       and a reference to the underlying connection <code>PooledConnection con</code>.
799
       and a reference to the underlying connection <code>PooledConnection con</code>.
810
    </p>
800
    </p>
811
    <p>
801
    <p>
812
       When a method on the <code>java.sql.Connection</code> object is invoked, it will cause the
802
       When a method on the <code>java.sql.Connection</code> object is invoked, it will cause the
813
<source>
803
    </p>
814
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
804
<source><![CDATA[  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable]]></source>
815
</source>
805
    <p>
816
       method to get invoked. The <code>Method method</code> is the actual method invoked, and <code>Object[] args</code> are the arguments.
806
       method to get invoked. The <code>Method method</code> is the actual method invoked, and <code>Object[] args</code> are the arguments.
817
       To look at a very simple example, where we demonstrate how to make the invokation to <code>java.sql.Connection.close()</code> a noop
807
       To look at a very simple example, where we demonstrate how to make the invokation to <code>java.sql.Connection.close()</code> a noop
818
       if the connection has been closed
808
       if the connection has been closed
819
<source>
809
    </p>
820
  if (CLOSE_VAL==method.getName()) {
810
<source><![CDATA[  if (CLOSE_VAL==method.getName()) {
821
      if (isClosed()) return null; //noop for already closed.
811
      if (isClosed()) return null; //noop for already closed.
822
  }
812
  }
823
  return super.invoke(proxy,method,args);
813
  return super.invoke(proxy,method,args);]]></source>
824
</source>
814
    <p>
825
        There is an observation being made. It is the comparison of the method name. One way to do this would be to do
815
        There is an observation being made. It is the comparison of the method name. One way to do this would be to do
826
        <code>&quot;close&quot;.equals(method.getName())</code>.
816
        <code>&quot;close&quot;.equals(method.getName())</code>.
827
        Above we see a direct reference comparison between the method name and <code>static final String</code> reference.
817
        Above we see a direct reference comparison between the method name and <code>static final String</code> reference.
828
        According to the JVM spec, method names and static final String end up in a shared constant pool, so the reference comparison should work.
818
        According to the JVM spec, method names and static final String end up in a shared constant pool, so the reference comparison should work.
829
        One could of course do this as well:
819
        One could of course do this as well:
830
<source>
820
    </p>
831
  if (compare(CLOSE_VAL,method)) {
821
<source><![CDATA[  if (compare(CLOSE_VAL,method)) {
832
      if (isClosed()) return null; //noop for already closed.
822
      if (isClosed()) return null; //noop for already closed.
833
  }
823
  }
834
  return super.invoke(proxy,method,args);
824
  return super.invoke(proxy,method,args);]]></source>
835
</source>
825
    <p>
836
        The <code>compare(String,Method)</code> will use the <code>useEquals</code> flag on an interceptor and do either reference comparison or
826
        The <code>compare(String,Method)</code> will use the <code>useEquals</code> flag on an interceptor and do either reference comparison or
837
        a string value comparison when the <code>useEquals=true</code> flag is set.
827
        a string value comparison when the <code>useEquals=true</code> flag is set.
838
    </p>
828
    </p>
Lines 839-875 Link Here
839
    <p>Pool start/stop<br/>
829
    <p>Pool start/stop<br/>
840
       When the connection pool is started or closed, you can be notifed. You will only be notified once per interceptor class
830
       When the connection pool is started or closed, you can be notifed. You will only be notified once per interceptor class
841
       even though it is an instance method. and you will be notified using an interceptor currently not attached to a pool.
831
       even though it is an instance method. and you will be notified using an interceptor currently not attached to a pool.
842
<source>
832
    </p>
843
  public void poolStarted(ConnectionPool pool) {
833
<source><![CDATA[  public void poolStarted(ConnectionPool pool) {
844
  }
834
  }
845
835
846
  public void poolClosed(ConnectionPool pool) {
836
  public void poolClosed(ConnectionPool pool) {
847
  }
837
  }]]></source>
848
</source>
838
    <p>
849
       When overriding these methods, don't forget to call super if you are extending a class other than <code>JdbcInterceptor</code>
839
       When overriding these methods, don't forget to call super if you are extending a class other than <code>JdbcInterceptor</code>
850
    </p>
840
    </p>
851
    <p>Configuring interceptors<br/>
841
    <p>Configuring interceptors<br/>
852
       Interceptors are configured using the <code>jdbcInterceptors</code> property or the <code>setJdbcInterceptors</code> method.
842
       Interceptors are configured using the <code>jdbcInterceptors</code> property or the <code>setJdbcInterceptors</code> method.
853
       An interceptor can have properties, and would be configured like this
843
       An interceptor can have properties, and would be configured like this
854
<source>
855
  String jdbcInterceptors=
856
    &quot;org.apache.tomcat.jdbc.pool.interceptor.ConnectionState(useEquals=true,fast=yes)&quot;
857
</source>
858
    </p>
844
    </p>
845
<source><![CDATA[  String jdbcInterceptors=
846
    "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState(useEquals=true,fast=yes)"]]></source>
847
859
    <p>Interceptor properties<br/>
848
    <p>Interceptor properties<br/>
860
       Since interceptors can have properties, you need to be able to read the values of these properties within your
849
       Since interceptors can have properties, you need to be able to read the values of these properties within your
861
       interceptor. Taking an example like the one above, you can override the <code>setProperties</code> method.
850
       interceptor. Taking an example like the one above, you can override the <code>setProperties</code> method.
862
<source>
851
    </p>
863
  public void setProperties(Map&lt;String, InterceptorProperty&gt; properties) {
852
<source><![CDATA[  public void setProperties(Map<String, InterceptorProperty> properties) {
864
     super.setProperties(properties);
853
     super.setProperties(properties);
865
     final String myprop = &quot;myprop&quot;;
854
     final String myprop = "myprop";
866
     InterceptorProperty p1 = properties.get(myprop);
855
     InterceptorProperty p1 = properties.get(myprop);
867
     if (p1!=null) {
856
     if (p1!=null) {
868
         setMyprop(Long.parseLong(p1.getValue()));
857
         setMyprop(Long.parseLong(p1.getValue()));
869
     }
858
     }
870
  }
859
  }]]></source>
871
</source>
860
872
    </p>
873
  </subsection>
861
  </subsection>
874
  <subsection name="Getting the actual JDBC connection">
862
  <subsection name="Getting the actual JDBC connection">
875
    <p>Connection pools create wrappers around the actual connection in order to properly pool them.
863
    <p>Connection pools create wrappers around the actual connection in order to properly pool them.
Lines 876-886 Link Here
876
       We also create interceptors in these wrappers to be able to perform certain functions.
864
       We also create interceptors in these wrappers to be able to perform certain functions.
877
       If there is a need to retrieve the actual connection, one can do so using the <code>javax.sql.PooledConnection</code>
865
       If there is a need to retrieve the actual connection, one can do so using the <code>javax.sql.PooledConnection</code>
878
       interface.
866
       interface.
879
<source>
880
  Connection con = datasource.getConnection();
881
  Connection actual = ((javax.sql.PooledConnection)con).getConnection();
882
</source>
883
    </p>
867
    </p>
868
<source><![CDATA[  Connection con = datasource.getConnection();
869
  Connection actual = ((javax.sql.PooledConnection)con).getConnection();]]></source>
870
884
  </subsection>
871
  </subsection>
885
872
886
</section>
873
</section>
Lines 890-914 Link Here
890
  <p>Other examples of Tomcat configuration for JDBC usage can be found <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html">in the Tomcat documentation</a>. </p>
877
  <p>Other examples of Tomcat configuration for JDBC usage can be found <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html">in the Tomcat documentation</a>. </p>
891
  <subsection name="Building from source">
878
  <subsection name="Building from source">
892
    <p>Building is pretty simple. The pool has a dependency on <code>tomcat-juli.jar</code> and in case you want the <code>SlowQueryReportJmx</code></p>
879
    <p>Building is pretty simple. The pool has a dependency on <code>tomcat-juli.jar</code> and in case you want the <code>SlowQueryReportJmx</code></p>
893
<source>
880
<source><![CDATA[  javac -classpath tomcat-juli.jar \
894
  javac -classpath tomcat-juli.jar \
895
        -d . \
881
        -d . \
896
        org/apache/tomcat/jdbc/pool/*.java \
882
        org/apache/tomcat/jdbc/pool/*.java \
897
        org/apache/tomcat/jdbc/pool/interceptor/*.java \
883
        org/apache/tomcat/jdbc/pool/interceptor/*.java \
898
        org/apache/tomcat/jdbc/pool/jmx/*.java
884
        org/apache/tomcat/jdbc/pool/jmx/*.java]]></source>
899
</source>
900
    <p>
885
    <p>
901
       A build file can be found in the Tomcat <a href="http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/">source repository</a>.
886
       A build file can be found in the Tomcat <a href="http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/">source repository</a>.
902
    </p>
887
    </p>
903
    <p>
888
    <p>
904
      As a convenience, a build file is also included where a simple build command will generate all files needed.
889
      As a convenience, a build file is also included where a simple build command will generate all files needed.
905
<source>
890
    </p>
906
  ant download  (downloads dependencies)
891
<source>  ant download  (downloads dependencies)
907
  ant build     (compiles and generates .jar files)
892
  ant build     (compiles and generates .jar files)
908
  ant dist      (creates a release package)
893
  ant dist      (creates a release package)
909
  ant test      (runs tests, expects a test database to be setup)
894
  ant test      (runs tests, expects a test database to be setup)</source>
910
</source>
895
911
    </p>
912
    <p>
896
    <p>
913
      The system is structured for a Maven build, but does generate release artifacts. Just the library itself.
897
      The system is structured for a Maven build, but does generate release artifacts. Just the library itself.
914
    </p>
898
    </p>
(-)webapps/docs/aio.xml (-19 / +19 lines)
Lines 161-172 Link Here
161
    described above:
161
    described above:
162
  </p>
162
  </p>
163
163
164
  <source>
164
  <source><![CDATA[public class ChatServlet
165
public class ChatServlet
166
    extends HttpServlet implements CometProcessor {
165
    extends HttpServlet implements CometProcessor {
167
166
168
    protected ArrayList&lt;HttpServletResponse> connections =
167
    protected ArrayList<HttpServletResponse> connections =
169
        new ArrayList&lt;HttpServletResponse>();
168
        new ArrayList<HttpServletResponse>();
170
    protected MessageSender messageSender = null;
169
    protected MessageSender messageSender = null;
171
170
172
    public void init() throws ServletException {
171
    public void init() throws ServletException {
Lines 197-204 Link Here
197
        if (event.getEventType() == CometEvent.EventType.BEGIN) {
196
        if (event.getEventType() == CometEvent.EventType.BEGIN) {
198
            log("Begin for session: " + request.getSession(true).getId());
197
            log("Begin for session: " + request.getSession(true).getId());
199
            PrintWriter writer = response.getWriter();
198
            PrintWriter writer = response.getWriter();
200
            writer.println("&lt;!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">");
199
            writer.println("<!DOCTYPE html>");
201
            writer.println("&lt;head>&lt;title>JSP Chat&lt;/title>&lt;/head>&lt;body bgcolor=\"#FFFFFF\">");
200
            writer.println("<head><title>JSP Chat</title></head><body>");
202
            writer.flush();
201
            writer.flush();
203
            synchronized(connections) {
202
            synchronized(connections) {
204
                connections.add(response);
203
                connections.add(response);
Lines 215-221 Link Here
215
                connections.remove(response);
214
                connections.remove(response);
216
            }
215
            }
217
            PrintWriter writer = response.getWriter();
216
            PrintWriter writer = response.getWriter();
218
            writer.println("&lt;/body>&lt;/html>");
217
            writer.println("</body></html>");
219
            event.close();
218
            event.close();
220
        } else if (event.getEventType() == CometEvent.EventType.READ) {
219
        } else if (event.getEventType() == CometEvent.EventType.READ) {
221
            InputStream is = request.getInputStream();
220
            InputStream is = request.getInputStream();
Lines 222-231 Link Here
222
            byte[] buf = new byte[512];
221
            byte[] buf = new byte[512];
223
            do {
222
            do {
224
                int n = is.read(buf); //can throw an IOException
223
                int n = is.read(buf); //can throw an IOException
225
                if (n &gt; 0) {
224
                if (n > 0) {
226
                    log("Read " + n + " bytes: " + new String(buf, 0, n)
225
                    log("Read " + n + " bytes: " + new String(buf, 0, n)
227
                            + " for session: " + request.getSession(true).getId());
226
                            + " for session: " + request.getSession(true).getId());
228
                } else if (n &lt; 0) {
227
                } else if (n < 0) {
229
                    error(event, request, response);
228
                    error(event, request, response);
230
                    return;
229
                    return;
231
                }
230
                }
Lines 236-242 Link Here
236
    public class MessageSender implements Runnable {
235
    public class MessageSender implements Runnable {
237
236
238
        protected boolean running = true;
237
        protected boolean running = true;
239
        protected ArrayList&lt;String> messages = new ArrayList&lt;String>();
238
        protected ArrayList<String> messages = new ArrayList<String>();
240
239
241
        public MessageSender() {
240
        public MessageSender() {
242
        }
241
        }
Lines 276-286 Link Here
276
                        messages.clear();
275
                        messages.clear();
277
                    }
276
                    }
278
                    // Send any pending message on all the open connections
277
                    // Send any pending message on all the open connections
279
                    for (int i = 0; i &lt; connections.size(); i++) {
278
                    for (int i = 0; i < connections.size(); i++) {
280
                        try {
279
                        try {
281
                            PrintWriter writer = connections.get(i).getWriter();
280
                            PrintWriter writer = connections.get(i).getWriter();
282
                            for (int j = 0; j &lt; pendingMessages.length; j++) {
281
                            for (int j = 0; j < pendingMessages.length; j++) {
283
                                writer.println(pendingMessages[j] + "&lt;br>");
282
                                writer.println(pendingMessages[j] + "<br>");
284
                            }
283
                            }
285
                            writer.flush();
284
                            writer.flush();
286
                        } catch (IOException e) {
285
                        } catch (IOException e) {
Lines 295-310 Link Here
295
294
296
    }
295
    }
297
296
298
}
297
}]]></source>
299
  </source>
300
298
301
  </subsection>
299
  </subsection>
302
  <subsection name="Comet timeouts">
300
  <subsection name="Comet timeouts">
303
    <p>If you are using the NIO connector, you can set individual timeouts for your different comet connections.
301
    <p>If you are using the NIO connector, you can set individual timeouts for your different comet connections.
304
       To set a timeout, simply set a request attribute like the following code shows:
302
       To set a timeout, simply set a request attribute like the following code shows:</p>
305
       <source>CometEvent event.... event.setTimeout(30*1000);</source> or
303
    <source>CometEvent event.... event.setTimeout(30*1000);</source>
306
       <source>event.getHttpServletRequest().setAttribute("org.apache.tomcat.comet.timeout", new Integer(30 * 1000));</source>
304
	<p>or</p>
307
       This sets the timeout to 30 seconds.
305
    <source>event.getHttpServletRequest().setAttribute("org.apache.tomcat.comet.timeout", new Integer(30 * 1000));</source>
306
    <p>
307
	   This sets the timeout to 30 seconds.
308
       Important note: in order to set this timeout, it has to be done on the <code>BEGIN</code> event.
308
       Important note: in order to set this timeout, it has to be done on the <code>BEGIN</code> event.
309
       The default value is <code>soTimeout</code>
309
       The default value is <code>soTimeout</code>
310
    </p>
310
    </p>
(-)webapps/docs/apr.xml (-28 / +28 lines)
Lines 57-68 Link Here
57
57
58
    <p>
58
    <p>
59
      APR support requires three main native components to be installed:
59
      APR support requires three main native components to be installed:
60
      <ul>
61
        <li>APR library</li>
62
        <li>JNI wrappers for APR used by Tomcat (libtcnative)</li>
63
        <li>OpenSSL libraries</li>
64
      </ul>
65
    </p>
60
    </p>
61
    <ul>
62
      <li>APR library</li>
63
      <li>JNI wrappers for APR used by Tomcat (libtcnative)</li>
64
      <li>OpenSSL libraries</li>
65
    </ul>
66
66
67
    <subsection name="Windows">
67
    <subsection name="Windows">
68
68
Lines 87-99 Link Here
87
87
88
    <p>
88
    <p>
89
      Requirements:
89
      Requirements:
90
      <ul>
91
        <li>APR 1.2+ development headers (libapr1-dev package)</li>
92
        <li>OpenSSL 0.9.7+ development headers (libssl-dev package)</li>
93
        <li>JNI headers from Java compatible JDK 1.4+</li>
94
        <li>GNU development environment (gcc, make)</li>
95
      </ul>
96
    </p>
90
    </p>
91
    <ul>
92
      <li>APR 1.2+ development headers (libapr1-dev package)</li>
93
      <li>OpenSSL 0.9.7+ development headers (libssl-dev package)</li>
94
      <li>JNI headers from Java compatible JDK 1.4+</li>
95
      <li>GNU development environment (gcc, make)</li>
96
    </ul>
97
97
98
    <p>
98
    <p>
99
      The wrapper library sources are located in the Tomcat binary bundle, in the
99
      The wrapper library sources are located in the Tomcat binary bundle, in the
Lines 100-107 Link Here
100
      <code>bin/tomcat-native.tar.gz</code> archive.
100
      <code>bin/tomcat-native.tar.gz</code> archive.
101
      Once the build environment is installed and the source archive is extracted, the wrapper library
101
      Once the build environment is installed and the source archive is extracted, the wrapper library
102
      can be compiled using (from the folder containing the configure script):
102
      can be compiled using (from the folder containing the configure script):
103
      <source>./configure &amp;&amp; make &amp;&amp; make install</source>
104
    </p>
103
    </p>
104
    <source>./configure &amp;&amp; make &amp;&amp; make install</source>
105
105
106
    </subsection>
106
    </subsection>
107
107
Lines 119-136 Link Here
119
119
120
  <p>
120
  <p>
121
    When APR is enabled, the following features are also enabled in Tomcat:
121
    When APR is enabled, the following features are also enabled in Tomcat:
122
    <ul>
123
      <li>Secure session ID generation by default on all platforms (platforms other than Linux required
124
          random number generation using a configured entropy)</li>
125
      <li>OS level statistics on memory usage and CPU usage by the Tomcat process are displayed by
126
          the status servlet</li>
127
    </ul>
128
  </p>
122
  </p>
123
  <ul>
124
    <li>Secure session ID generation by default on all platforms (platforms other than Linux required
125
        random number generation using a configured entropy)</li>
126
    <li>OS level statistics on memory usage and CPU usage by the Tomcat process are displayed by
127
        the status servlet</li>
128
  </ul>
129
129
130
  </section>
130
  </section>
131
131
132
  <section name="APR Lifecycle Listener Configuration">
132
  <section name="APR Lifecycle Listener Configuration">
133
    <subsection name="AprLifecycleListener">
133
    <subsection name="AprLifecycleListener">
134
	<attributes>
134
    <attribute name="SSLEngine" required="false">
135
    <attribute name="SSLEngine" required="false">
135
    <p>
136
    <p>
136
      Name of the SSLEngine to use. off: Do not use SSL, on: Use SSL but no specific ENGINE.
137
      Name of the SSLEngine to use. off: Do not use SSL, on: Use SSL but no specific ENGINE.
Lines 137-150 Link Here
137
      The default value is <b>on</b>.
138
      The default value is <b>on</b>.
138
      This initializes the native SSL engine, then enable the use of this engine in the connector
139
      This initializes the native SSL engine, then enable the use of this engine in the connector
139
      using the <code>SSLEnabled</code> attribute. Example:
140
      using the <code>SSLEnabled</code> attribute. Example:
140
      <source>
141
	</p>
141
&lt;Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /&gt;
142
      <source><![CDATA[<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />]]></source>
142
      </source>
143
    
143
    </p>
144
    <p>See the <a href="http://www.openssl.org">Official OpenSSL
144
    <p>See the <a href="http://www.openssl.org">Official OpenSSL
145
       website</a> for more details on SSL hardware engines and manufacturers.
145
       website</a> for more details on SSL hardware engines and manufacturers.
146
    </p>
146
    </p>
147
    </attribute>
147
    </attribute>
148
	</attributes>
148
    </subsection>
149
    </subsection>
149
  </section>
150
  </section>
150
151
Lines 156-174 Link Here
156
      connector configuration documentation.</p>
157
      connector configuration documentation.</p>
157
158
158
      <p>For HTTPS configuration, see the
159
      <p>For HTTPS configuration, see the
159
      <a href="config/http.html#SSL%20Support">HTTPS</a> connector configuration
160
      <a href="config/http.html#SSL_Support">HTTPS</a> connector configuration
160
      documentation.</p>
161
      documentation.</p>
161
162
162
      <p>An example SSL Connector declaration is:
163
      <p>An example SSL Connector declaration is:</p>
163
      <source>
164
      <source><![CDATA[<Connector port="443" maxHttpHeaderSize="8192"
164
      &lt;Connector port="443" maxHttpHeaderSize="8192"
165
                 maxThreads="150"
165
                 maxThreads="150"
166
                 enableLookups="false" disableUploadTimeout="true"
166
                 enableLookups="false" disableUploadTimeout="true"
167
                 acceptCount="100" scheme="https" secure="true"
167
                 acceptCount="100" scheme="https" secure="true"
168
                 SSLEnabled="true"
168
                 SSLEnabled="true"
169
                 SSLCertificateFile="${catalina.base}/conf/localhost.crt"
169
                 SSLCertificateFile="${catalina.base}/conf/localhost.crt"
170
                 SSLCertificateKeyFile="${catalina.base}/conf/localhost.key" /&gt;</source>
170
                 SSLCertificateKeyFile="${catalina.base}/conf/localhost.key" />]]></source>
171
      </p>
171
      
172
172
173
    </subsection>
173
    </subsection>
174
174
(-)webapps/docs/building.xml (-22 / +20 lines)
Lines 107-116 Link Here
107
107
108
<p>
108
<p>
109
Use the following commands to build Tomcat:
109
Use the following commands to build Tomcat:
110
<br/>
110
<br/><br/>
111
<code><br/>
111
<code>
112
    cd ${tomcat.source}<br/>
112
    cd ${tomcat.source}<br/>
113
    ant<br/>
113
    ant
114
</code>
114
</code>
115
</p>
115
</p>
116
116
Lines 133-153 Link Here
133
<p>
133
<p>
134
  The build can be controlled by creating a <code>${tomcat.source}/build.properties</code>
134
  The build can be controlled by creating a <code>${tomcat.source}/build.properties</code>
135
  file and adding the following content to it:
135
  file and adding the following content to it:
136
<br/>
137
<code><br/>
138
    # ----- Proxy setup -----<br/>
139
    # Uncomment if using a proxy server.<br/>
140
    #proxy.host=proxy.domain<br/>
141
    #proxy.port=8080<br/>
142
    #proxy.use=on<br/>
143
<br/>
144
    # ----- Default Base Path for Dependent Packages -----<br/>
145
    # Replace this path with the directory path where<br/>
146
    # dependencies binaries should be downloaded.<br/>
147
    base.path=/home/me/some-place-to-download-to<br/>
148
</code>
149
</p>
136
</p>
137
<source># ----- Proxy setup -----
138
# Uncomment if using a proxy server.
139
#proxy.host=proxy.domain
140
#proxy.port=8080
141
#proxy.use=on
150
142
143
# ----- Default Base Path for Dependent Packages -----
144
# Replace this path with the directory path where
145
# dependencies binaries should be downloaded.
146
base.path=/home/me/some-place-to-download-to</source>
147
148
151
<p>
149
<p>
152
Once the build has completed successfully, a usable Tomcat installation will have been
150
Once the build has completed successfully, a usable Tomcat installation will have been
153
produced in the <code>${tomcat.source}/output/build</code> directory, and can be started
151
produced in the <code>${tomcat.source}/output/build</code> directory, and can be started
Lines 204-217 Link Here
204
Variables</em> to add two new <em>Classpath Variables</em>:
202
Variables</em> to add two new <em>Classpath Variables</em>:
205
</p>
203
</p>
206
204
207
<p>
205
208
<table border="1">
206
<table class="defaultTable">
209
 <tr><td>TOMCAT_LIBS_BASE</td><td>The same location as the <code>base.path</code>
207
 <tr><td>TOMCAT_LIBS_BASE</td><td>The same location as the <code>base.path</code>
210
  setting in <code>build.properties</code>, where the binary dependencies have been downloaded</td></tr>
208
  setting in <code>build.properties</code>, where the binary dependencies have been downloaded</td></tr>
211
 <tr><td>ANT_HOME</td><td>the base path of Ant 1.8.1 or later</td></tr>
209
 <tr><td>ANT_HOME</td><td>the base path of Ant 1.8.1 or later</td></tr>
212
</table>
210
</table>
213
</p>
214
211
212
215
<p>
213
<p>
216
Use <em>File-&gt;Import</em> and choose <em>Existing Projects into Workspace</em>.
214
Use <em>File-&gt;Import</em> and choose <em>Existing Projects into Workspace</em>.
217
From there choose the root directory of the Tomcat source tree (<code>${tomcat.source}</code>)
215
From there choose the root directory of the Tomcat source tree (<code>${tomcat.source}</code>)
Lines 232-239 Link Here
232
Tweaking a few formatting preferences will make it much easier to keep consistent with Tomcat
230
Tweaking a few formatting preferences will make it much easier to keep consistent with Tomcat
233
coding conventions (and have your contributions accepted):
231
coding conventions (and have your contributions accepted):
234
</p>
232
</p>
235
<p>
233
236
<table border="1">
234
<table class="defaultTable">
237
  <tr><td>Java -&gt; Code Style -> Formatter -&gt; Edit...</td>
235
  <tr><td>Java -&gt; Code Style -> Formatter -&gt; Edit...</td>
238
  <td>Tab policy: Spaces only<br/>Tab and Indentation size: 4</td></tr>
236
  <td>Tab policy: Spaces only<br/>Tab and Indentation size: 4</td></tr>
239
  <tr><td>General -&gt; Editors -> Text Editors</td>
237
  <tr><td>General -&gt; Editors -> Text Editors</td>
Lines 241-248 Link Here
241
  <tr><td>XML -&gt; XML Files -> Editor</td><td>Indent using spaces<br/>Indentation size: 2</td></tr>
239
  <tr><td>XML -&gt; XML Files -> Editor</td><td>Indent using spaces<br/>Indentation size: 2</td></tr>
242
  <tr><td>Ant -&gt; Editor -> Formatter</td><td>Tab size: 2<br/>Use tab character instead of spaces: unchecked</td></tr>
240
  <tr><td>Ant -&gt; Editor -> Formatter</td><td>Tab size: 2<br/>Use tab character instead of spaces: unchecked</td></tr>
243
</table>
241
</table>
244
</p>
245
242
243
246
</section>
244
</section>
247
245
248
<section name="Building with other IDEs">
246
<section name="Building with other IDEs">
(-)webapps/docs/cgi-howto.xml (-2 / +2 lines)
Lines 72-78 Link Here
72
<section name="Configuration">
72
<section name="Configuration">
73
73
74
<p>There are several servlet init parameters which can be used to
74
<p>There are several servlet init parameters which can be used to
75
configure the behaviour of the CGI servlet.
75
configure the behaviour of the CGI servlet.</p>
76
<ul>
76
<ul>
77
<li><strong>cgiPathPrefix</strong> - The CGI search path will start at
77
<li><strong>cgiPathPrefix</strong> - The CGI search path will start at
78
the web application root directory + File.separator + this prefix.
78
the web application root directory + File.separator + this prefix.
Lines 96-103 Link Here
96
the reading of stderr to complete before terminating the CGI process. Default
96
the reading of stderr to complete before terminating the CGI process. Default
97
is 2000.</li>
97
is 2000.</li>
98
</ul>
98
</ul>
99
</p>
100
99
100
101
</section>
101
</section>
102
102
103
</body>
103
</body>
(-)webapps/docs/class-loader-howto.xml (-4 / +2 lines)
Lines 56-70 Link Here
56
organized into the following parent-child relationships, where the parent
56
organized into the following parent-child relationships, where the parent
57
class loader is above the child class loader:</p>
57
class loader is above the child class loader:</p>
58
58
59
<source>
59
<source>      Bootstrap
60
      Bootstrap
61
          |
60
          |
62
       System
61
       System
63
          |
62
          |
64
       Common
63
       Common
65
       /     \
64
       /     \
66
  Webapp1   Webapp2 ...
65
  Webapp1   Webapp2 ...</source>
67
</source>
68
66
69
<p>The characteristics of each of these class loaders, including the source
67
<p>The characteristics of each of these class loaders, including the source
70
of classes and resources that they make visible, are discussed in detail in
68
of classes and resources that they make visible, are discussed in detail in
(-)webapps/docs/cluster-howto.xml (-177 / +154 lines)
Lines 41-47 Link Here
41
41
42
<section name="For the impatient">
42
<section name="For the impatient">
43
  <p>
43
  <p>
44
    Simply add <source>&lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;/&gt;</source>
44
    Simply add
45
  </p>
46
  <source>&lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;/&gt;</source>
47
  <p>
45
    to your <code>&lt;Engine&gt;</code> or your <code>&lt;Host&gt;</code> element to enable clustering.
48
    to your <code>&lt;Engine&gt;</code> or your <code>&lt;Host&gt;</code> element to enable clustering.
46
  </p>
49
  </p>
47
  <p>
50
  <p>
Lines 51-107 Link Here
51
    Also when using the delta manager it will replicate to all nodes, even nodes that don't have the application deployed.<br/>
54
    Also when using the delta manager it will replicate to all nodes, even nodes that don't have the application deployed.<br/>
52
    To get around this problem, you'll want to use the BackupManager. This manager only replicates the session data to one backup
55
    To get around this problem, you'll want to use the BackupManager. This manager only replicates the session data to one backup
53
    node, and only to nodes that have the application deployed. Downside of the BackupManager: not quite as battle tested as the delta manager.
56
    node, and only to nodes that have the application deployed. Downside of the BackupManager: not quite as battle tested as the delta manager.
54
    <br/>
57
  </p>
55
    Here are some of the important default values:<br/>
58
  <p>
56
    1. Multicast address is 228.0.0.4<br/>
59
    Here are some of the important default values:
57
    2. Multicast port is 45564 (the port and the address together determine cluster membership.<br/>
60
  </p>
58
    3. The IP broadcasted is <code>java.net.InetAddress.getLocalHost().getHostAddress()</code> (make sure you don't broadcast 127.0.0.1, this is a common error)<br/>
61
  <ol>
59
    4. The TCP port listening for replication messages is the first available server socket in range <code>4000-4100</code><br/>
62
    <li>Multicast address is 228.0.0.4</li>
60
    5. Two listeners are configured <code>ClusterSessionListener</code><br/>
63
    <li>Multicast port is 45564 (the port and the address together determine cluster membership.</li>
61
    6. Two interceptors are configured <code>TcpFailureDetector</code> and <code>MessageDispatch15Interceptor</code><br/>
64
    <li>The IP broadcasted is <code>java.net.InetAddress.getLocalHost().getHostAddress()</code> (make sure you don't broadcast 127.0.0.1, this is a common error)</li>
62
    The following is the default cluster configuration:<br/>
65
    <li>The TCP port listening for replication messages is the first available server socket in range <code>4000-4100</code></li>
63
    <source>
66
    <li>Two listeners are configured <code>ClusterSessionListener</code></li>
64
        &lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;
67
    <li>Two interceptors are configured <code>TcpFailureDetector</code> and <code>MessageDispatch15Interceptor</code></li>
65
                 channelSendOptions=&quot;8&quot;&gt;
68
  </ol>
69
  <p>
70
    The following is the default cluster configuration:
71
  </p>
72
  <source><![CDATA[        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
73
                 channelSendOptions="8">
66
74
67
          &lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;
75
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
68
                   expireSessionsOnShutdown=&quot;false&quot;
76
                   expireSessionsOnShutdown="false"
69
                   notifyListenersOnReplication=&quot;true&quot;/&gt;
77
                   notifyListenersOnReplication="true"/>
70
78
71
          &lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&gt;
79
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
72
            &lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;
80
            <Membership className="org.apache.catalina.tribes.membership.McastService"
73
                        address=&quot;228.0.0.4&quot;
81
                        address="228.0.0.4"
74
                        port=&quot;45564&quot;
82
                        port="45564"
75
                        frequency=&quot;500&quot;
83
                        frequency="500"
76
                        dropTime=&quot;3000&quot;/&gt;
84
                        dropTime="3000"/>
77
            &lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;
85
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
78
                      address=&quot;auto&quot;
86
                      address="auto"
79
                      port=&quot;4000&quot;
87
                      port="4000"
80
                      autoBind=&quot;100&quot;
88
                      autoBind="100"
81
                      selectorTimeout=&quot;5000&quot;
89
                      selectorTimeout="5000"
82
                      maxThreads=&quot;6&quot;/&gt;
90
                      maxThreads="6"/>
83
91
84
            &lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&gt;
92
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
85
              &lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&gt;
93
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
86
            &lt;/Sender&gt;
94
            </Sender>
87
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&gt;
95
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
88
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&gt;
96
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
89
          &lt;/Channel&gt;
97
          </Channel>
90
98
91
          &lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot;
99
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
92
                 filter=&quot;&quot;/&gt;
100
                 filter=""/>
93
          &lt;Valve className=&quot;org.apache.catalina.ha.session.JvmRouteBinderValve&quot;/&gt;
101
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
94
102
95
          &lt;Deployer className=&quot;org.apache.catalina.ha.deploy.FarmWarDeployer&quot;
103
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
96
                    tempDir=&quot;/tmp/war-temp/&quot;
104
                    tempDir="/tmp/war-temp/"
97
                    deployDir=&quot;/tmp/war-deploy/&quot;
105
                    deployDir="/tmp/war-deploy/"
98
                    watchDir=&quot;/tmp/war-listen/&quot;
106
                    watchDir="/tmp/war-listen/"
99
                    watchEnabled=&quot;false&quot;/&gt;
107
                    watchEnabled="false"/>
100
108
101
          &lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&gt;
109
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
102
        &lt;/Cluster&gt;
110
        </Cluster>]]></source>
103
    </source>
104
  </p>
105
  <p>Will cover this section in more detail later in this document.</p>
111
  <p>Will cover this section in more detail later in this document.</p>
106
</section>
112
</section>
107
113
Lines 128-134 Link Here
128
   side otherwise, a new session will be created.</p>
134
   side otherwise, a new session will be created.</p>
129
<p>Note: Clustering support currently requires the JDK version 1.5 or later.</p>
135
<p>Note: Clustering support currently requires the JDK version 1.5 or later.</p>
130
<p>The Cluster module uses the Tomcat JULI logging framework, so you can configure logging
136
<p>The Cluster module uses the Tomcat JULI logging framework, so you can configure logging
131
   through the regular logging.properties file. To track messages, you can enable logging on the key:<code>org.apache.catalina.tribes.MESSAGES</code></p>
137
   through the regular logging.properties file. To track messages, you can enable logging on the key: <code>org.apache.catalina.tribes.MESSAGES</code></p>
132
</section>
138
</section>
133
139
134
140
Lines 152-166 Link Here
152
   A very simple setup would look like this:
158
   A very simple setup would look like this:
153
   </p>
159
   </p>
154
160
155
<source>
161
<source>        DNS Round Robin
156
        DNS Round Robin
157
               |
162
               |
158
         Load Balancer
163
         Load Balancer
159
          /           \
164
          /           \
160
      Cluster1      Cluster2
165
      Cluster1      Cluster2
161
      /     \        /     \
166
      /     \        /     \
162
  Tomcat1 Tomcat2  Tomcat3 Tomcat4
167
  Tomcat1 Tomcat2  Tomcat3 Tomcat4</source>
163
</source>
164
168
165
<p>What is important to mention here, is that session replication is only the beginning of clustering.
169
<p>What is important to mention here, is that session replication is only the beginning of clustering.
166
   Another popular concept used to implement clusters is farming, i.e., you deploy your apps only to one
170
   Another popular concept used to implement clusters is farming, i.e., you deploy your apps only to one
Lines 231-288 Link Here
231
</section>
235
</section>
232
236
233
<section name="Configuration Example">
237
<section name="Configuration Example">
234
    <source>
238
    <source><![CDATA[        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
235
        &lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;
239
                 channelSendOptions="6">
236
                 channelSendOptions=&quot;6&quot;&gt;
237
240
238
          &lt;Manager className=&quot;org.apache.catalina.ha.session.BackupManager&quot;
241
          <Manager className="org.apache.catalina.ha.session.BackupManager"
239
                   expireSessionsOnShutdown=&quot;false&quot;
242
                   expireSessionsOnShutdown="false"
240
                   notifyListenersOnReplication=&quot;true&quot;
243
                   notifyListenersOnReplication="true"
241
                   mapSendOptions=&quot;6&quot;/&gt;
244
                   mapSendOptions="6"/>
242
          &lt;!--
245
          <!--
243
          &lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;
246
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
244
                   expireSessionsOnShutdown=&quot;false&quot;
247
                   expireSessionsOnShutdown="false"
245
                   notifyListenersOnReplication=&quot;true&quot;/&gt;
248
                   notifyListenersOnReplication="true"/>
246
          --&gt;
249
          -->
247
          &lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&gt;
250
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
248
            &lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;
251
            <Membership className="org.apache.catalina.tribes.membership.McastService"
249
                        address=&quot;228.0.0.4&quot;
252
                        address="228.0.0.4"
250
                        port=&quot;45564&quot;
253
                        port="45564"
251
                        frequency=&quot;500&quot;
254
                        frequency="500"
252
                        dropTime=&quot;3000&quot;/&gt;
255
                        dropTime="3000"/>
253
            &lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;
256
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
254
                      address=&quot;auto&quot;
257
                      address="auto"
255
                      port=&quot;5000&quot;
258
                      port="5000"
256
                      selectorTimeout=&quot;100&quot;
259
                      selectorTimeout="100"
257
                      maxThreads=&quot;6&quot;/&gt;
260
                      maxThreads="6"/>
258
261
259
            &lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&gt;
262
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
260
              &lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&gt;
263
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
261
            &lt;/Sender&gt;
264
            </Sender>
262
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&gt;
265
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
263
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&gt;
266
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
264
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor&quot;/&gt;
267
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
265
          &lt;/Channel&gt;
268
          </Channel>
266
269
267
          &lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot;
270
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
268
                 filter=&quot;.*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt&quot;/&gt;
271
                 filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/>
269
272
270
          &lt;Deployer className=&quot;org.apache.catalina.ha.deploy.FarmWarDeployer&quot;
273
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
271
                    tempDir=&quot;/tmp/war-temp/&quot;
274
                    tempDir="/tmp/war-temp/"
272
                    deployDir=&quot;/tmp/war-deploy/&quot;
275
                    deployDir="/tmp/war-deploy/"
273
                    watchDir=&quot;/tmp/war-listen/&quot;
276
                    watchDir="/tmp/war-listen/"
274
                    watchEnabled=&quot;false&quot;/&gt;
277
                    watchEnabled="false"/>
275
278
276
          &lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&gt;
279
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
277
        &lt;/Cluster&gt;
280
        </Cluster>]]></source>
278
    </source>
279
    <p>
281
    <p>
280
      Break it down!!
282
      Break it down!!
281
    </p>
283
    </p>
282
    <source>
284
    <source><![CDATA[        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
283
        &lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;
285
                 channelSendOptions="6">]]></source>
284
                 channelSendOptions=&quot;6&quot;&gt;
285
    </source>
286
    <p>
286
    <p>
287
      The main element, inside this element all cluster details can be configured.
287
      The main element, inside this element all cluster details can be configured.
288
      The <code>channelSendOptions</code> is the flag that is attached to each message sent by the
288
      The <code>channelSendOptions</code> is the flag that is attached to each message sent by the
Lines 293-309 Link Here
293
      sends it itself directly through the channel.
293
      sends it itself directly through the channel.
294
      <br/>For more info, Please visit the <a href="config/cluster.html">reference documentation</a>
294
      <br/>For more info, Please visit the <a href="config/cluster.html">reference documentation</a>
295
    </p>
295
    </p>
296
    <source>
296
    <source><![CDATA[          <Manager className="org.apache.catalina.ha.session.BackupManager"
297
          &lt;Manager className=&quot;org.apache.catalina.ha.session.BackupManager&quot;
297
                   expireSessionsOnShutdown="false"
298
                   expireSessionsOnShutdown=&quot;false&quot;
298
                   notifyListenersOnReplication="true"
299
                   notifyListenersOnReplication=&quot;true&quot;
299
                   mapSendOptions="6"/>
300
                   mapSendOptions=&quot;6&quot;/&gt;
300
          <!--
301
          &lt;!--
301
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
302
          &lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;
302
                   expireSessionsOnShutdown="false"
303
                   expireSessionsOnShutdown=&quot;false&quot;
303
                   notifyListenersOnReplication="true"/>
304
                   notifyListenersOnReplication=&quot;true&quot;/&gt;
304
          -->]]></source>
305
          --&gt;
306
    </source>
307
    <p>
305
    <p>
308
        This is a template for the manager configuration that will be used if no manager is defined in the &lt;Context&gt;
306
        This is a template for the manager configuration that will be used if no manager is defined in the &lt;Context&gt;
309
        element. In Tomcat 5.x each webapp marked distributable had to use the same manager, this is no longer the case
307
        element. In Tomcat 5.x each webapp marked distributable had to use the same manager, this is no longer the case
Lines 313-333 Link Here
313
        and create a manager instance cloning this configuration.
311
        and create a manager instance cloning this configuration.
314
        <br/>For more info, Please visit the <a href="config/cluster-manager.html">reference documentation</a>
312
        <br/>For more info, Please visit the <a href="config/cluster-manager.html">reference documentation</a>
315
    </p>
313
    </p>
316
    <source>
314
    <source><![CDATA[          <Channel className="org.apache.catalina.tribes.group.GroupChannel">]]></source>
317
          &lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&gt;
318
    </source>
319
    <p>
315
    <p>
320
        The channel element is <a href="tribes/introduction.html">Tribes</a>, the group communication framework
316
        The channel element is <a href="tribes/introduction.html">Tribes</a>, the group communication framework
321
        used inside Tomcat. This element encapsulates everything that has to do with communication and membership logic.
317
        used inside Tomcat. This element encapsulates everything that has to do with communication and membership logic.
322
        <br/>For more info, Please visit the <a href="config/cluster-channel.html">reference documentation</a>
318
        <br/>For more info, Please visit the <a href="config/cluster-channel.html">reference documentation</a>
323
    </p>
319
    </p>
324
    <source>
320
    <source><![CDATA[            <Membership className="org.apache.catalina.tribes.membership.McastService"
325
            &lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;
321
                        address="228.0.0.4"
326
                        address=&quot;228.0.0.4&quot;
322
                        port="45564"
327
                        port=&quot;45564&quot;
323
                        frequency="500"
328
                        frequency=&quot;500&quot;
324
                        dropTime="3000"/>]]></source>
329
                        dropTime=&quot;3000&quot;/&gt;
330
    </source>
331
    <p>
325
    <p>
332
        Membership is done using multicasting. Please note that Tribes also supports static memberships using the
326
        Membership is done using multicasting. Please note that Tribes also supports static memberships using the
333
        <code>StaticMembershipInterceptor</code> if you want to extend your membership to points beyond multicasting.
327
        <code>StaticMembershipInterceptor</code> if you want to extend your membership to points beyond multicasting.
Lines 339-351 Link Here
339
        <code>Receiver.address</code> attribute.
333
        <code>Receiver.address</code> attribute.
340
        <br/>For more info, Please visit the <a href="config/cluster-membership.html">reference documentation</a>
334
        <br/>For more info, Please visit the <a href="config/cluster-membership.html">reference documentation</a>
341
    </p>
335
    </p>
342
    <source>
336
    <source><![CDATA[            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
343
            &lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;
337
                      address="auto"
344
                      address=&quot;auto&quot;
338
                      port="5000"
345
                      port=&quot;5000&quot;
339
                      selectorTimeout="100"
346
                      selectorTimeout=&quot;100&quot;
340
                      maxThreads="6"/>]]></source>
347
                      maxThreads=&quot;6&quot;/&gt;
348
    </source>
349
    <p>
341
    <p>
350
        In tribes the logic of sending and receiving data has been broken into two functional components. The Receiver, as the name suggests
342
        In tribes the logic of sending and receiving data has been broken into two functional components. The Receiver, as the name suggests
351
        is responsible for receiving messages. Since the Tribes stack is thread less, (a popular improvement now adopted by other frameworks as well),
343
        is responsible for receiving messages. Since the Tribes stack is thread less, (a popular improvement now adopted by other frameworks as well),
Lines 353-364 Link Here
353
        The address attribute is the host address that will be broadcasted by the membership component to the other nodes.
345
        The address attribute is the host address that will be broadcasted by the membership component to the other nodes.
354
        <br/>For more info, Please visit the <a href="config/cluster-receiver.html">reference documentation</a>
346
        <br/>For more info, Please visit the <a href="config/cluster-receiver.html">reference documentation</a>
355
    </p>
347
    </p>
356
    <source>
348
    <source><![CDATA[            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
357
349
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
358
            &lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&gt;
350
            </Sender>]]></source>
359
              &lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&gt;
360
            &lt;/Sender&gt;
361
    </source>
362
    <p>
351
    <p>
363
        The sender component, as the name indicates is responsible for sending messages to other nodes.
352
        The sender component, as the name indicates is responsible for sending messages to other nodes.
364
        The sender has a shell component, the <code>ReplicationTransmitter</code> but the real stuff done is done in the
353
        The sender has a shell component, the <code>ReplicationTransmitter</code> but the real stuff done is done in the
Lines 369-380 Link Here
369
        at the same time.
358
        at the same time.
370
        <br/>For more info, Please visit the <a href="config/cluster-sender.html">reference documentation</a>
359
        <br/>For more info, Please visit the <a href="config/cluster-sender.html">reference documentation</a>
371
    </p>
360
    </p>
372
    <source>
361
    <source><![CDATA[            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
373
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&gt;
362
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
374
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&gt;
363
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
375
            &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor&quot;/&gt;
364
          </Channel>]]></source>
376
          &lt;/Channel&gt;
377
    </source>
378
    <p>
365
    <p>
379
        Tribes uses a stack to send messages through. Each element in the stack is called an interceptor, and works much like the valves do
366
        Tribes uses a stack to send messages through. Each element in the stack is called an interceptor, and works much like the valves do
380
        in the Tomcat servlet container.
367
        in the Tomcat servlet container.
Lines 387-396 Link Here
387
        channel stack. Think of it as a linked list, with the head being the first most interceptor and the tail the last.
374
        channel stack. Think of it as a linked list, with the head being the first most interceptor and the tail the last.
388
        <br/>For more info, Please visit the <a href="config/cluster-interceptor.html">reference documentation</a>
375
        <br/>For more info, Please visit the <a href="config/cluster-interceptor.html">reference documentation</a>
389
    </p>
376
    </p>
390
    <source>
377
    <source><![CDATA[          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
391
          &lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot;
378
                 filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/>]]></source>
392
                 filter=&quot;.*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt&quot;/&gt;
393
    </source>
394
    <p>
379
    <p>
395
        The cluster uses valves to track requests to web applications, we've mentioned the ReplicationValve and the JvmRouteBinderValve above.
380
        The cluster uses valves to track requests to web applications, we've mentioned the ReplicationValve and the JvmRouteBinderValve above.
396
        The &lt;Cluster&gt; element itself is not part of the pipeline in Tomcat, instead the cluster adds the valve to its parent container.
381
        The &lt;Cluster&gt; element itself is not part of the pipeline in Tomcat, instead the cluster adds the valve to its parent container.
Lines 397-409 Link Here
397
        If the &lt;Cluster&gt; elements is configured in the &lt;Engine&gt; element, the valves get added to the engine and so on.
382
        If the &lt;Cluster&gt; elements is configured in the &lt;Engine&gt; element, the valves get added to the engine and so on.
398
        <br/>For more info, Please visit the <a href="config/cluster-valve.html">reference documentation</a>
383
        <br/>For more info, Please visit the <a href="config/cluster-valve.html">reference documentation</a>
399
    </p>
384
    </p>
400
    <source>
385
    <source><![CDATA[          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
401
          &lt;Deployer className=&quot;org.apache.catalina.ha.deploy.FarmWarDeployer&quot;
386
                    tempDir="/tmp/war-temp/"
402
                    tempDir=&quot;/tmp/war-temp/&quot;
387
                    deployDir="/tmp/war-deploy/"
403
                    deployDir=&quot;/tmp/war-deploy/&quot;
388
                    watchDir="/tmp/war-listen/"
404
                    watchDir=&quot;/tmp/war-listen/&quot;
389
                    watchEnabled="false"/>]]></source>
405
                    watchEnabled=&quot;false&quot;/&gt;
406
    </source>
407
    <p>
390
    <p>
408
        The default tomcat cluster supports farmed deployment, ie, the cluster can deploy and undeploy applications on the other nodes.
391
        The default tomcat cluster supports farmed deployment, ie, the cluster can deploy and undeploy applications on the other nodes.
409
        The state of this component is currently in flux but will be addressed soon. There was a change in the deployment algorithm
392
        The state of this component is currently in flux but will be addressed soon. There was a change in the deployment algorithm
Lines 411-420 Link Here
411
        webapps directory.
394
        webapps directory.
412
        <br/>For more info, Please visit the <a href="config/cluster-deployer.html">reference documentation</a>
395
        <br/>For more info, Please visit the <a href="config/cluster-deployer.html">reference documentation</a>
413
    </p>
396
    </p>
414
    <source>
397
    <source><![CDATA[          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
415
          &lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&gt;
398
        </Cluster>]]></source>
416
        &lt;/Cluster&gt;
417
    </source>
418
    <p>
399
    <p>
419
        Since the SimpleTcpCluster itself is a sender and receiver of the Channel object, components can register themselves as listeners to
400
        Since the SimpleTcpCluster itself is a sender and receiver of the Channel object, components can register themselves as listeners to
420
        the SimpleTcpCluster. The listener above <code>ClusterSessionListener</code> listens for DeltaManager replication messages
401
        the SimpleTcpCluster. The listener above <code>ClusterSessionListener</code> listens for DeltaManager replication messages
Lines 426-434 Link Here
426
407
427
<section name="Cluster Architecture">
408
<section name="Cluster Architecture">
428
409
429
<p><b>Component Levels:</b>
410
<p><b>Component Levels:</b></p>
430
<source>
411
<source>         Server
431
         Server
432
           |
412
           |
433
         Service
413
         Service
434
           |
414
           |
Lines 473-482 Link Here
473
                                                \
453
                                                \
474
                                                 -- FarmWarDeployer
454
                                                 -- FarmWarDeployer
475
455
476
477
</source>
456
</source>
478
</p>
479
457
458
480
</section>
459
</section>
481
<section name="How it Works">
460
<section name="How it Works">
482
<p>To make it easy to understand how clustering works, We are gonna take you through a series of scenarios.
461
<p>To make it easy to understand how clustering works, We are gonna take you through a series of scenarios.
Lines 507-513 Link Here
507
        Tomcat will create a <code>DeltaManager</code> for that context instead of a <code>StandardManager</code>.
486
        Tomcat will create a <code>DeltaManager</code> for that context instead of a <code>StandardManager</code>.
508
        The cluster class will start up a membership service (multicast) and a replication service (tcp unicast).
487
        The cluster class will start up a membership service (multicast) and a replication service (tcp unicast).
509
        More on the architecture further down in this document.
488
        More on the architecture further down in this document.
510
    </p><p></p>
489
    </p>
511
</li>
490
</li>
512
<li><b><code>TomcatB</code> starts up</b>
491
<li><b><code>TomcatB</code> starts up</b>
513
    <p>
492
    <p>
Lines 520-526 Link Here
520
        entry. The session state gets transferred for each web application that has distributable in
499
        entry. The session state gets transferred for each web application that has distributable in
521
        its web.xml. Note: To use session replication efficiently, all your tomcat instances should be
500
        its web.xml. Note: To use session replication efficiently, all your tomcat instances should be
522
        configured the same.
501
        configured the same.
523
    </p><p></p>
502
    </p>
524
</li>
503
</li>
525
<li><B><code>TomcatA</code> receives a request, a session <code>S1</code> is created.</B>
504
<li><B><code>TomcatA</code> receives a request, a session <code>S1</code> is created.</B>
526
    <p>
505
    <p>
Lines 534-540 Link Here
534
        in the session without calling setAttribute or removeAttribute to be replicated.
513
        in the session without calling setAttribute or removeAttribute to be replicated.
535
        a useDirtyFlag configuration parameter can be used to optimize the number of times
514
        a useDirtyFlag configuration parameter can be used to optimize the number of times
536
        a session is replicated.
515
        a session is replicated.
537
    </p><p></p>
516
    </p>
538
517
539
</li>
518
</li>
540
<li><b><code>TomcatA</code> crashes</b>
519
<li><b><code>TomcatA</code> crashes</b>
Lines 544-554 Link Here
544
        be notified of any changes that occurs in TomcatB.
523
        be notified of any changes that occurs in TomcatB.
545
        The load balancer will redirect the requests from TomcatA to TomcatB and all the sessions
524
        The load balancer will redirect the requests from TomcatA to TomcatB and all the sessions
546
        are current.
525
        are current.
547
    </p><p></p>
526
    </p>
548
</li>
527
</li>
549
<li><b><code>TomcatB</code> receives a request for session <code>S1</code></b>
528
<li><b><code>TomcatB</code> receives a request for session <code>S1</code></b>
550
    <p>Nothing exciting, TomcatB will process the request as any other request.
529
    <p>Nothing exciting, TomcatB will process the request as any other request.
551
    </p><p></p>
530
    </p>
552
</li>
531
</li>
553
<li><b><code>TomcatA</code> starts up</b>
532
<li><b><code>TomcatA</code> starts up</b>
554
    <p>Upon start up, before TomcatA starts taking new request and making itself
533
    <p>Upon start up, before TomcatA starts taking new request and making itself
Lines 556-573 Link Here
556
    It will join the cluster, contact TomcatB for the current state of all the sessions.
535
    It will join the cluster, contact TomcatB for the current state of all the sessions.
557
    And once it receives the session state, it finishes loading and opens its HTTP/mod_jk ports.
536
    And once it receives the session state, it finishes loading and opens its HTTP/mod_jk ports.
558
    So no requests will make it to TomcatA until it has received the session state from TomcatB.
537
    So no requests will make it to TomcatA until it has received the session state from TomcatB.
559
    </p><p></p>
538
    </p>
560
</li>
539
</li>
561
<li><b><code>TomcatA</code> receives a request, invalidate is called on the session (<code>S1</code>)</b>
540
<li><b><code>TomcatA</code> receives a request, invalidate is called on the session (<code>S1</code>)</b>
562
    <p>The invalidate is call is intercepted, and the session is queued with invalidated sessions.
541
    <p>The invalidate is call is intercepted, and the session is queued with invalidated sessions.
563
        When the request is complete, instead of sending out the session that has changed, it sends out
542
        When the request is complete, instead of sending out the session that has changed, it sends out
564
        an "expire" message to TomcatB and TomcatB will invalidate the session as well.
543
        an "expire" message to TomcatB and TomcatB will invalidate the session as well.
565
    </p><p></p>
544
    </p>
566
545
567
</li>
546
</li>
568
<li><b><code>TomcatB</code> receives a request, for a new session (<code>S2</code>)</b>
547
<li><b><code>TomcatB</code> receives a request, for a new session (<code>S2</code>)</b>
569
    <p>Same scenario as in step 3)
548
    <p>Same scenario as in step 3)
570
    </p><p></p>
549
    </p>
571
550
572
551
573
</li>
552
</li>
Lines 576-582 Link Here
576
       and the session is queued with invalidated sessions.
555
       and the session is queued with invalidated sessions.
577
       At this point, the invalidet session will not be replicated across until
556
       At this point, the invalidet session will not be replicated across until
578
       another request comes through the system and checks the invalid queue.
557
       another request comes through the system and checks the invalid queue.
579
    </p><p></p>
558
    </p>
580
</li>
559
</li>
581
</ol>
560
</ol>
582
561
Lines 613-636 Link Here
613
592
614
<section name="Monitoring your Cluster with JMX">
593
<section name="Monitoring your Cluster with JMX">
615
<p>Monitoring is a very important question when you use a cluster. Some of the cluster objects are JMX MBeans </p>
594
<p>Monitoring is a very important question when you use a cluster. Some of the cluster objects are JMX MBeans </p>
616
<p>Add the following parameter to your startup script with Java 5:
595
<p>Add the following parameter to your startup script with Java 5:</p>
617
<source>
596
<source>set CATALINA_OPTS=\
618
set CATALINA_OPTS=\
619
-Dcom.sun.management.jmxremote \
597
-Dcom.sun.management.jmxremote \
620
-Dcom.sun.management.jmxremote.port=%my.jmx.port% \
598
-Dcom.sun.management.jmxremote.port=%my.jmx.port% \
621
-Dcom.sun.management.jmxremote.ssl=false \
599
-Dcom.sun.management.jmxremote.ssl=false \
622
-Dcom.sun.management.jmxremote.authenticate=false
600
-Dcom.sun.management.jmxremote.authenticate=false</source>
623
</source>
601
602
<p>
603
  List of Cluster Mbeans
624
</p>
604
</p>
625
<p>
605
<table class="defaultTable">
626
List of Cluster Mbeans<br/>
627
<table border="1" cellpadding="5">
628
606
629
  <tr>
607
  <tr>
630
    <th align="center" bgcolor="aqua">Name</th>
608
    <th>Name</th>
631
    <th align="center" bgcolor="aqua">Description</th>
609
    <th>Description</th>
632
    <th align="center" bgcolor="aqua">MBean ObjectName - Engine</th>
610
    <th>MBean ObjectName - Engine</th>
633
    <th align="center" bgcolor="aqua">MBean ObjectName - Host</th>
611
    <th>MBean ObjectName - Host</th>
634
  </tr>
612
  </tr>
635
613
636
  <tr>
614
  <tr>
Lines 678-684 Link Here
678
  </tr>
656
  </tr>
679
657
680
</table>
658
</table>
681
</p>
682
</section>
659
</section>
683
660
684
<section name="FAQ">
661
<section name="FAQ">
(-)webapps/docs/connectors.xml (-2 / +1 lines)
Lines 64-76 Link Here
64
proxied HTTP. AJP clustering is the most efficient from the Tomcat perspective.
64
proxied HTTP. AJP clustering is the most efficient from the Tomcat perspective.
65
It is otherwise functionally equivalent to HTTP clustering.</p>
65
It is otherwise functionally equivalent to HTTP clustering.</p>
66
66
67
<p>The native connectors supported with this Tomcat release are:
67
<p>The native connectors supported with this Tomcat release are:</p>
68
<ul>
68
<ul>
69
<li>JK 1.2.x with any of the supported servers</li>
69
<li>JK 1.2.x with any of the supported servers</li>
70
<li>mod_proxy on Apache HTTP Server 2.x (included by default in Apache HTTP Server 2.2),
70
<li>mod_proxy on Apache HTTP Server 2.x (included by default in Apache HTTP Server 2.2),
71
with AJP enabled</li>
71
with AJP enabled</li>
72
</ul>
72
</ul>
73
</p>
74
73
75
<p><b>Other native connectors supporting AJP may work, but are no longer supported.</b></p>
74
<p><b>Other native connectors supporting AJP may work, but are no longer supported.</b></p>
76
75
(-)webapps/docs/default-servlet.xml (-164 / +128 lines)
Lines 34-92 Link Here
34
</section>
34
</section>
35
35
36
<section anchor="what" name="What is the DefaultServlet">
36
<section anchor="what" name="What is the DefaultServlet">
37
<p>
37
The default servlet is the servlet which serves static resources as well
38
The default servlet is the servlet which serves static resources as well
38
as serves the directory listings (if directory listings are enabled).
39
as serves the directory listings (if directory listings are enabled).
39
40
</p>
40
</section>
41
</section>
41
42
42
<section anchor="where" name="Where is it declared?">
43
<section anchor="where" name="Where is it declared?">
44
<p>
43
It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>.
45
It is declared globally in <i>$CATALINA_BASE/conf/web.xml</i>.
44
By default here is it's declaration:
46
By default here is it's declaration:
45
<source>
47
</p>
46
    &lt;servlet&gt;
48
<source><![CDATA[    <servlet>
47
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
49
        <servlet-name>default</servlet-name>
48
        &lt;servlet-class&gt;
50
        <servlet-class>
49
          org.apache.catalina.servlets.DefaultServlet
51
          org.apache.catalina.servlets.DefaultServlet
50
        &lt;/servlet-class&gt;
52
        </servlet-class>
51
        &lt;init-param&gt;
53
        <init-param>
52
            &lt;param-name&gt;debug&lt;/param-name&gt;
54
            <param-name>debug</param-name>
53
            &lt;param-value&gt;0&lt;/param-value&gt;
55
            <param-value>0</param-value>
54
        &lt;/init-param&gt;
56
        </init-param>
55
        &lt;init-param&gt;
57
        <init-param>
56
            &lt;param-name&gt;listings&lt;/param-name&gt;
58
            <param-name>listings</param-name>
57
            &lt;param-value&gt;false&lt;/param-value&gt;
59
            <param-value>false</param-value>
58
        &lt;/init-param&gt;
60
        </init-param>
59
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
61
        <load-on-startup>1</load-on-startup>
60
    &lt;/servlet&gt;
62
    </servlet>
61
63
62
...
64
...
63
65
64
    &lt;servlet-mapping&gt;
66
    <servlet-mapping>
65
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
67
        <servlet-name>default</servlet-name>
66
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
68
        <url-pattern>/</url-pattern>
67
    &lt;/servlet-mapping&gt;
69
    </servlet-mapping>]]></source>
68
70
69
</source>
70
71
So by default, the default servlet is loaded at webapp startup and
71
So by default, the default servlet is loaded at webapp startup and
72
directory listings are disabled and debugging is turned off.
72
directory listings are disabled and debugging is turned off.
73
</section>
73
</section>
74
74
75
<section anchor="change" name="What can I change?">
75
<section anchor="change" name="What can I change?">
76
The DefaultServlet allows the following initParamters:
76
<p>
77
  The DefaultServlet allows the following initParamters:
78
</p>
77
79
78
<table border="1">
80
<properties>
79
  <tr>
81
  <property name="debug">
80
    <th valign='top'>debug</th>
81
    <td valign='top'>
82
        Debugging level. It is not very useful unless you are a tomcat
82
        Debugging level. It is not very useful unless you are a tomcat
83
        developer. As
83
        developer. As
84
        of this writing, useful values are 0, 1, 11, 1000. [0]
84
        of this writing, useful values are 0, 1, 11, 1000. [0]
85
    </td>
85
  </property>
86
  </tr>
86
  <property name="listings">
87
  <tr>
88
    <th valign='top'>listings</th>
89
    <td valign='top'>
90
        If no welcome file is present, can a directory listing be
87
        If no welcome file is present, can a directory listing be
91
        shown?
88
        shown?
92
        value may be <b>true</b> or <b>false</b> [false]
89
        value may be <b>true</b> or <b>false</b> [false]
Lines 96-114 Link Here
96
        <b>WARNING:</b> Listings of directories containing many entries are
93
        <b>WARNING:</b> Listings of directories containing many entries are
97
        expensive. Multiple requests for large directory listings can consume
94
        expensive. Multiple requests for large directory listings can consume
98
        significant proportions of server resources.
95
        significant proportions of server resources.
99
    </td>
96
  </property>
100
  </tr>
97
  <property name="readmeFile">
101
  <tr>
102
    <th valign='top'>readmeFile</th>
103
    <td valign='top'>
104
        If a directory listing is presented, a readme file may also
98
        If a directory listing is presented, a readme file may also
105
        be presented with the listing. This file is inserted as is
99
        be presented with the listing. This file is inserted as is
106
        so it may contain HTML.
100
        so it may contain HTML.
107
    </td>
101
  </property>
108
  </tr>
102
  <property name="globalXsltFile">
109
  <tr>
110
    <th valign='top'>globalXsltFile</th>
111
    <td valign='top'>
112
        If you wish to customize your directory listing, you
103
        If you wish to customize your directory listing, you
113
        can use an XSL transformation. This value is an absolute
104
        can use an XSL transformation. This value is an absolute
114
        file name which be used for all directory listings.
105
        file name which be used for all directory listings.
Lines 115-125 Link Here
115
        This can be overridden per context and/or per directory. See
106
        This can be overridden per context and/or per directory. See
116
        <strong>contextXsltFile</strong> and <strong>localXsltFile</strong>
107
        <strong>contextXsltFile</strong> and <strong>localXsltFile</strong>
117
        below. The format of the xml is shown below.
108
        below. The format of the xml is shown below.
118
    </td>
109
  </property>
119
  </tr>
110
  <property name="contextXsltFile">
120
  <tr>
121
    <th valign='top'>contextXsltFile</th>
122
    <td valign='top'>
123
        You may also customize your directory listing by context by
111
        You may also customize your directory listing by context by
124
        configuring <code>contextXsltFile</code>. This should be a context
112
        configuring <code>contextXsltFile</code>. This should be a context
125
        relative path (e.g.: <code>/path/to/context.xslt</code>). This
113
        relative path (e.g.: <code>/path/to/context.xslt</code>). This
Lines 127-137 Link Here
127
        file does not exist, then <code>globalXsltFile</code> will be used. If
115
        file does not exist, then <code>globalXsltFile</code> will be used. If
128
        <code>globalXsltFile</code> does not exist, then the default
116
        <code>globalXsltFile</code> does not exist, then the default
129
        directory listing will be shown.
117
        directory listing will be shown.
130
    </td>
118
  </property>
131
  </tr>
119
  <property name="localXsltFile">
132
  <tr>
133
    <th valign='top'>localXsltFile</th>
134
    <td valign='top'>
135
        You may also customize your directory listing by directory by
120
        You may also customize your directory listing by directory by
136
        configuring <code>localXsltFile</code>. This should be a relative
121
        configuring <code>localXsltFile</code>. This should be a relative
137
        file name in the directory where the listing will take place.
122
        file name in the directory where the listing will take place.
Lines 142-194 Link Here
142
        <code>globalXsltFile</code> will be used. If
127
        <code>globalXsltFile</code> will be used. If
143
        <code>globalXsltFile</code> does not exist, then the default
128
        <code>globalXsltFile</code> does not exist, then the default
144
        directory listing will be shown.
129
        directory listing will be shown.
145
    </td>
130
  </property>
146
  </tr>
131
  <property name="input">
147
  <tr>
148
    <th valign='top'>input</th>
149
    <td valign='top'>
150
        Input buffer size (in bytes) when reading
132
        Input buffer size (in bytes) when reading
151
        resources to be served.  [2048]
133
        resources to be served.  [2048]
152
    </td>
134
  </property>
153
  </tr>
135
  <property name="output">
154
  <tr>
155
    <th valign='top'>output</th>
156
    <td valign='top'>
157
        Output buffer size (in bytes) when writing
136
        Output buffer size (in bytes) when writing
158
        resources to be served.  [2048]
137
        resources to be served.  [2048]
159
    </td>
138
  </property>
160
  </tr>
139
  <property name="readonly">
161
  <tr>
162
    <th valign='top'>readonly</th>
163
    <td valign='top'>
164
        Is this context "read only", so HTTP commands like PUT and
140
        Is this context "read only", so HTTP commands like PUT and
165
        DELETE are rejected?  [true]
141
        DELETE are rejected?  [true]
166
    </td>
142
  </property>
167
  </tr>
143
  <property name="fileEncoding">
168
  <tr>
169
    <th valign='top'>fileEncoding</th>
170
    <td valign='top'>
171
        File encoding to be used when reading static resources.
144
        File encoding to be used when reading static resources.
172
        [platform default]
145
        [platform default]
173
    </td>
146
  </property>
174
  </tr>
147
  <property name="sendfileSize">
175
  <tr>
176
    <th valign='top'>sendfileSize</th>
177
    <td valign='top'>
178
        If the connector used supports sendfile, this represents the minimal
148
        If the connector used supports sendfile, this represents the minimal
179
        file size in KB for which sendfile will be used. Use a negative value
149
        file size in KB for which sendfile will be used. Use a negative value
180
        to always disable sendfile. [48]
150
        to always disable sendfile. [48]
181
    </td>
151
  </property>
182
  </tr>
152
  <property name="useAcceptRanges">
183
  <tr>
184
    <th valign='top'>useAcceptRanges</th>
185
    <td valign='top'>
186
        If true, the Accept-Ranges header will be set when appropriate for the
153
        If true, the Accept-Ranges header will be set when appropriate for the
187
        response. [true]
154
        response. [true]
188
    </td>
155
  </property>
189
  </tr>
156
</properties>
190
191
</table>
192
</section>
157
</section>
193
158
194
<section anchor="dir" name="How do I customize directory listings?">
159
<section anchor="dir" name="How do I customize directory listings?">
Lines 210-311 Link Here
210
175
211
<p>
176
<p>
212
Format:
177
Format:
213
<source>
178
</p>
214
    &lt;listing&gt;
179
<source><![CDATA[    <listing>
215
     &lt;entries&gt;
180
     <entries>
216
      &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
181
      <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
217
        fileName1
182
        fileName1
218
      &lt;/entry&gt;
183
      </entry>
219
      &lt;entry type='file|dir' urlPath='aPath' size='###' date='gmt date'&gt;
184
      <entry type='file|dir' urlPath='aPath' size='###' date='gmt date'>
220
        fileName2
185
        fileName2
221
      &lt;/entry&gt;
186
      </entry>
222
      ...
187
      ...
223
     &lt;/entries&gt;
188
     </entries>
224
     &lt;readme&gt;&lt;/readme&gt;
189
     <readme></readme>
225
    &lt;/listing&gt;
190
    </listing>]]></source>
226
</source>
227
<ul>
191
<ul>
228
  <li>size will be missing if <code>type='dir'</code></li>
192
  <li>size will be missing if <code>type='dir'</code></li>
229
  <li>Readme is a CDATA entry</li>
193
  <li>Readme is a CDATA entry</li>
230
</ul>
194
</ul>
195
196
<p>
197
  The following is a sample xsl file which mimics the default tomcat behavior:
231
</p>
198
</p>
232
The following is a sample xsl file which mimics the default tomcat behavior:
199
<source><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
233
<source>
234
&lt;?xml version="1.0"?&gt;
235
200
236
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
201
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
237
  version="1.0"&gt;
202
  version="3.0">
238
203
239
  &lt;xsl:output method="xhtml" encoding="iso-8859-1" indent="no"/&gt;
204
  <xsl:output method="html" html-version="5.0"
205
    encoding="UTF-8" indent="no"
206
    doctype-system="about:legacy-compat"/>
240
207
241
  &lt;xsl:template match="listing"&gt;
208
  <xsl:template match="listing">
242
   &lt;html&gt;
209
   <html>
243
    &lt;head&gt;
210
    <head>
244
      &lt;title&gt;
211
      <title>
245
        Sample Directory Listing For
212
        Sample Directory Listing For
246
        &lt;xsl:value-of select="@directory"/&gt;
213
        <xsl:value-of select="@directory"/>
247
      &lt;/title&gt;
214
      </title>
248
      &lt;style&gt;
215
      <style>
249
        h1{color : white;background-color : #0086b2;}
216
        h1 {color : white;background-color : #0086b2;}
250
        h3{color : white;background-color : #0086b2;}
217
        h3 {color : white;background-color : #0086b2;}
251
        body{font-family : sans-serif,Arial,Tahoma;
218
        body {font-family : sans-serif,Arial,Tahoma;
252
             color : black;background-color : white;}
219
             color : black;background-color : white;}
253
        b{color : white;background-color : #0086b2;}
220
        b {color : white;background-color : #0086b2;}
254
        a{color : black;} HR{color : #0086b2;}
221
        a {color : black;} HR{color : #0086b2;}
255
      &lt;/style&gt;
222
        table td { padding: 5px; }
256
    &lt;/head&gt;
223
      </style>
257
    &lt;body&gt;
224
    </head>
258
      &lt;h1&gt;Sample Directory Listing For
225
    <body>
259
            &lt;xsl:value-of select="@directory"/&gt;
226
      <h1>Sample Directory Listing For
260
      &lt;/h1&gt;
227
            <xsl:value-of select="@directory"/>
261
      &lt;hr size="1" /&gt;
228
      </h1>
262
      &lt;table cellspacing="0"
229
      <hr style="height: 1px;" />
263
                  width="100%"
230
      <table style="width: 100%;">
264
            cellpadding="5"
231
        <tr>
265
                  align="center"&gt;
232
          <th style="text-align: left;">Filename</th>
266
        &lt;tr&gt;
233
          <th style="text-align: center;">Size</th>
267
          &lt;th align="left"&gt;Filename&lt;/th&gt;
234
          <th style="text-align: right;">Last Modified</th>
268
          &lt;th align="center"&gt;Size&lt;/th&gt;
235
        </tr>
269
          &lt;th align="right"&gt;Last Modified&lt;/th&gt;
236
        <xsl:apply-templates select="entries"/>
270
        &lt;/tr&gt;
237
        </table>
271
        &lt;xsl:apply-templates select="entries"/&gt;
238
      <xsl:apply-templates select="readme"/>
272
        &lt;/table&gt;
239
      <hr style="height: 1px;" />
273
      &lt;xsl:apply-templates select="readme"/&gt;
240
      <h3>Apache Tomcat/8.0</h3>
274
      &lt;hr size="1" /&gt;
241
    </body>
275
      &lt;h3&gt;Apache Tomcat/7.0&lt;/h3&gt;
242
   </html>
276
    &lt;/body&gt;
243
  </xsl:template>
277
   &lt;/html&gt;
278
  &lt;/xsl:template&gt;
279
244
280
245
281
  &lt;xsl:template match="entries"&gt;
246
  <xsl:template match="entries">
282
    &lt;xsl:apply-templates select="entry"/&gt;
247
    <xsl:apply-templates select="entry"/>
283
  &lt;/xsl:template&gt;
248
  </xsl:template>
284
249
285
  &lt;xsl:template match="readme"&gt;
250
  <xsl:template match="readme">
286
    &lt;hr size="1" /&gt;
251
    <hr style="height: 1px;" />
287
    &lt;pre&gt;&lt;xsl:apply-templates/&gt;&lt;/pre&gt;
252
    <pre><xsl:apply-templates/></pre>
288
  &lt;/xsl:template&gt;
253
  </xsl:template>
289
254
290
  &lt;xsl:template match="entry"&gt;
255
  <xsl:template match="entry">
291
    &lt;tr&gt;
256
    <tr>
292
      &lt;td align="left"&gt;
257
      <td style="text-align: left;">
293
        &lt;xsl:variable name="urlPath" select="@urlPath"/&gt;
258
        <xsl:variable name="urlPath" select="@urlPath"/>
294
        &lt;a href="{$urlPath}"&gt;
259
        <a href="{$urlPath}">
295
          &lt;tt&gt;&lt;xsl:apply-templates/&gt;&lt;/tt&gt;
260
          <pre><xsl:apply-templates/></pre>
296
        &lt;/a&gt;
261
        </a>
297
      &lt;/td&gt;
262
      </td>
298
      &lt;td align="right"&gt;
263
      <td style="text-align: right;">
299
        &lt;tt&gt;&lt;xsl:value-of select="@size"/&gt;&lt;/tt&gt;
264
        <pre><xsl:value-of select="@size"/></pre>
300
      &lt;/td&gt;
265
      </td>
301
      &lt;td align="right"&gt;
266
      <td style="text-align: right;">
302
        &lt;tt&gt;&lt;xsl:value-of select="@date"/&gt;&lt;/tt&gt;
267
        <pre><xsl:value-of select="@date"/></pre>
303
      &lt;/td&gt;
268
      </td>
304
    &lt;/tr&gt;
269
    </tr>
305
  &lt;/xsl:template&gt;
270
  </xsl:template>
306
271
307
&lt;/xsl:stylesheet&gt;
272
</xsl:stylesheet>]]></source>
308
</source>
309
273
310
</section>
274
</section>
311
275
(-)webapps/docs/deployer-howto.xml (-1 / +2 lines)
Lines 41-47 Link Here
41
        </p>
41
        </p>
42
        <p>
42
        <p>
43
            Web application deployment may be accomplished in a number of ways
43
            Web application deployment may be accomplished in a number of ways
44
            within the Tomcat server.</p>
44
            within the Tomcat server.
45
        </p>
45
        <ul>
46
        <ul>
46
                <li>Statically; the web application is setup before Tomcat is started</li>
47
                <li>Statically; the web application is setup before Tomcat is started</li>
47
                <li>
48
                <li>
(-)webapps/docs/html-manager-howto.xml (-98 / +55 lines)
Lines 125-157 Link Here
125
users continuously encounter database exceptions.</p>
125
users continuously encounter database exceptions.</p>
126
126
127
<p>If this command succeeds, you will see a Message like this:</p>
127
<p>If this command succeeds, you will see a Message like this:</p>
128
<source>
128
<source>OK - Started application at context path /examples</source>
129
OK - Started application at context path /examples
130
</source>
131
129
132
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
130
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
133
error message.  Possible causes for problems include:</p>
131
error message.  Possible causes for problems include:</p>
134
<ul>
132
<ul>
135
<li><em>Encountered exception</em>
133
<li><em>Encountered exception</em>
136
    <blockquote>
137
    <p>An exception was encountered trying to start the web application.
134
    <p>An exception was encountered trying to start the web application.
138
    Check the Tomcat logs for the details.</p>
135
    Check the Tomcat logs for the details.</p>
139
    </blockquote></li>
136
    </li>
140
<li><em>Invalid context path was specified</em>
137
<li><em>Invalid context path was specified</em>
141
    <blockquote>
142
    <p>The context path must start with a slash character, unless you are
138
    <p>The context path must start with a slash character, unless you are
143
    referencing the ROOT web application -- in which case the context path
139
    referencing the ROOT web application -- in which case the context path
144
    must be a zero-length string.</p>
140
    must be a zero-length string.</p>
145
    </blockquote></li>
141
    </li>
146
<li><em>No context exists for path /foo</em>
142
<li><em>No context exists for path /foo</em>
147
    <blockquote>
148
    <p>There is no deployed application on the context path
143
    <p>There is no deployed application on the context path
149
    that you specified.</p>
144
    that you specified.</p>
150
    </blockquote></li>
145
    </li>
151
<li><em>No context path was specified</em>
146
<li><em>No context path was specified</em>
152
    <blockquote>
147
    <p>
153
    The <code>path</code> parameter is required.
148
    The <code>path</code> parameter is required.
154
    </blockquote></li>
149
    </p>
150
</li>
155
</ul>
151
</ul>
156
152
157
</subsection>
153
</subsection>
Lines 164-196 Link Here
164
"stopped" on a list applications command.</p>
160
"stopped" on a list applications command.</p>
165
161
166
<p>If this command succeeds, you will see a Message like this:</p>
162
<p>If this command succeeds, you will see a Message like this:</p>
167
<source>
163
<source>OK - Stopped application at context path /examples</source>
168
OK - Stopped application at context path /examples
169
</source>
170
164
171
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
165
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
172
error message.  Possible causes for problems include:</p>
166
error message.  Possible causes for problems include:</p>
173
<ul>
167
<ul>
174
<li><em>Encountered exception</em>
168
<li><em>Encountered exception</em>
175
    <blockquote>
176
    <p>An exception was encountered trying to stop the web application.
169
    <p>An exception was encountered trying to stop the web application.
177
    Check the Tomcat logs for the details.</p>
170
    Check the Tomcat logs for the details.</p>
178
    </blockquote></li>
171
    </li>
179
<li><em>Invalid context path was specified</em>
172
<li><em>Invalid context path was specified</em>
180
    <blockquote>
181
    <p>The context path must start with a slash character, unless you are
173
    <p>The context path must start with a slash character, unless you are
182
    referencing the ROOT web application -- in which case the context path
174
    referencing the ROOT web application -- in which case the context path
183
    must be a zero-length string.</p>
175
    must be a zero-length string.</p>
184
    </blockquote></li>
176
    </li>
185
<li><em>No context exists for path /foo</em>
177
<li><em>No context exists for path /foo</em>
186
    <blockquote>
187
    <p>There is no deployed application on the context path
178
    <p>There is no deployed application on the context path
188
    that you specified.</p>
179
    that you specified.</p>
189
    </blockquote></li>
180
    </li>
190
<li><em>No context path was specified</em>
181
<li><em>No context path was specified</em>
191
    <blockquote>
182
    <p>
192
    The <code>path</code> parameter is required.
183
    The <code>path</code> parameter is required.
193
    </blockquote></li>
184
    </p>
185
</li>
194
</ul>
186
</ul>
195
187
196
</subsection>
188
</subsection>
Lines 219-253 Link Here
219
error message.  Possible causes for problems include:</p>
211
error message.  Possible causes for problems include:</p>
220
<ul>
212
<ul>
221
<li><em>Encountered exception</em>
213
<li><em>Encountered exception</em>
222
    <blockquote>
223
    <p>An exception was encountered trying to restart the web application.
214
    <p>An exception was encountered trying to restart the web application.
224
    Check the Tomcat logs for the details.</p>
215
    Check the Tomcat logs for the details.</p>
225
    </blockquote></li>
216
    </li>
226
<li><em>Invalid context path was specified</em>
217
<li><em>Invalid context path was specified</em>
227
    <blockquote>
228
    <p>The context path must start with a slash character, unless you are
218
    <p>The context path must start with a slash character, unless you are
229
    referencing the ROOT web application -- in which case the context path
219
    referencing the ROOT web application -- in which case the context path
230
    must be a zero-length string.</p>
220
    must be a zero-length string.</p>
231
    </blockquote></li>
221
    </li>
232
<li><em>No context exists for path /foo</em>
222
<li><em>No context exists for path /foo</em>
233
    <blockquote>
234
    <p>There is no deployed application on the context path
223
    <p>There is no deployed application on the context path
235
    that you specified.</p>
224
    that you specified.</p>
236
    </blockquote></li>
225
    </li>
237
<li><em>No context path was specified</em>
226
<li><em>No context path was specified</em>
238
    <blockquote>
227
    <p>The <code>path</code> parameter is required.</p>
239
    The <code>path</code> parameter is required.
228
    </li>
240
    </blockquote></li>
241
<li><em>Reload not supported on WAR deployed at path /foo</em>
229
<li><em>Reload not supported on WAR deployed at path /foo</em>
242
    <blockquote>
230
    <p>Currently, application reloading (to pick up changes to the classes or
243
    Currently, application reloading (to pick up changes to the classes or
244
    <code>web.xml</code> file) is not supported when a web application is
231
    <code>web.xml</code> file) is not supported when a web application is
245
    installed directly from a WAR file, which happens when the host is
232
    installed directly from a WAR file, which happens when the host is
246
    configured to not unpack WAR files. As it only works when the web
233
    configured to not unpack WAR files. As it only works when the web
247
    application is installed from an unpacked directory, if you are using
234
    application is installed from an unpacked directory, if you are using
248
    a WAR file, you should <code>undeploy</code> and then <code>deploy</code>
235
    a WAR file, you should <code>undeploy</code> and then <code>deploy</code>
249
    the application again to pick up your changes.
236
    the application again to pick up your changes.</p>
250
    </blockquote></li>
237
    </li>
251
</ul>
238
</ul>
252
239
253
</subsection>
240
</subsection>
Lines 254-260 Link Here
254
241
255
<subsection name="Undeploy">
242
<subsection name="Undeploy">
256
243
257
<p><strong><font color="red">WARNING</font> - This command will delete the
244
<p><strong><span style="color: red;">WARNING</span> - This command will delete the
258
contents of the web application directory and/or ".war" file if it exists within
245
contents of the web application directory and/or ".war" file if it exists within
259
the <code>appBase</code> directory (typically "webapps") for this virtual host
246
the <code>appBase</code> directory (typically "webapps") for this virtual host
260
</strong>.  The web application temporary work directory is also deleted.  If
247
</strong>.  The web application temporary work directory is also deleted.  If
Lines 268-300 Link Here
268
in the HTML manager.</p>
255
in the HTML manager.</p>
269
256
270
<p>If this command succeeds, you will see a Message like this:</p>
257
<p>If this command succeeds, you will see a Message like this:</p>
271
<source>
258
<source>OK - Undeployed application at context path /examples</source>
272
OK - Undeployed application at context path /examples
273
</source>
274
259
275
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
260
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
276
error message.  Possible causes for problems include:</p>
261
error message.  Possible causes for problems include:</p>
277
<ul>
262
<ul>
278
<li><em>Encountered exception</em>
263
<li><em>Encountered exception</em>
279
    <blockquote>
280
    <p>An exception was encountered trying to undeploy the web application.
264
    <p>An exception was encountered trying to undeploy the web application.
281
    Check the Tomcat logs for the details.</p>
265
    Check the Tomcat logs for the details.</p>
282
    </blockquote></li>
266
    </li>
283
<li><em>Invalid context path was specified</em>
267
<li><em>Invalid context path was specified</em>
284
    <blockquote>
285
    <p>The context path must start with a slash character, unless you are
268
    <p>The context path must start with a slash character, unless you are
286
    referencing the ROOT web application -- in which case the context path
269
    referencing the ROOT web application -- in which case the context path
287
    must be a zero-length string.</p>
270
    must be a zero-length string.</p>
288
    </blockquote></li>
271
    </li>
289
<li><em>No context exists for path /foo</em>
272
<li><em>No context exists for path /foo</em>
290
    <blockquote>
291
    <p>There is no deployed application on the context path
273
    <p>There is no deployed application on the context path
292
    that you specified.</p>
274
    that you specified.</p>
293
    </blockquote></li>
275
    </li>
294
<li><em>No context path was specified</em>
276
<li><em>No context path was specified</em>
295
    <blockquote>
296
    The <code>path</code> parameter is required.
277
    The <code>path</code> parameter is required.
297
    </blockquote></li>
278
    </li>
298
</ul>
279
</ul>
299
280
300
</subsection>
281
</subsection>
Lines 319-325 Link Here
319
300
320
<p>There are a number of different ways the deploy command can be used.</p>
301
<p>There are a number of different ways the deploy command can be used.</p>
321
302
322
<h3>Deploy a Directory or WAR by URL</h3>
303
<h5>Deploy a Directory or WAR by URL</h5>
323
304
324
<p>Install a web application directory or ".war" file located on the Tomcat
305
<p>Install a web application directory or ".war" file located on the Tomcat
325
server. If no <i>Context Path</i> is specified, the directory name or the
306
server. If no <i>Context Path</i> is specified, the directory name or the
Lines 344-355 Link Here
344
context named <code>/bar</code>. Notice that there is no <code>path</code>
325
context named <code>/bar</code>. Notice that there is no <code>path</code>
345
parameter so the context path defaults to the name of the web application
326
parameter so the context path defaults to the name of the web application
346
archive file without the ".war" extension.</p>
327
archive file without the ".war" extension.</p>
347
<source>
328
<source>WAR or Directory URL: jar:file:/path/to/bar.war!/</source>
348
WAR or Directory URL: jar:file:/path/to/bar.war!/
349
</source>
350
329
351
330
352
<h3>Deploy a Directory or War from the Host appBase</h3>
331
<h5>Deploy a Directory or War from the Host appBase</h5>
353
332
354
<p>Install a web application directory or ".war" file located in your Host
333
<p>Install a web application directory or ".war" file located in your Host
355
appBase directory. If no <i>Context Path</i> is specified the directory name
334
appBase directory. If no <i>Context Path</i> is specified the directory name
Lines 360-380 Link Here
360
deployed as the web application context named <code>/foo</code>. Notice
339
deployed as the web application context named <code>/foo</code>. Notice
361
that there is no <code>path</code> parameter so the context path defaults
340
that there is no <code>path</code> parameter so the context path defaults
362
to the name of the web application directory.</p>
341
to the name of the web application directory.</p>
363
<source>
342
<source>WAR or Directory URL: foo</source>
364
WAR or Directory URL: foo
365
</source>
366
343
367
344
368
<p>In this example the ".war" file <code>bar.war</code> located in your
345
<p>In this example the ".war" file <code>bar.war</code> located in your
369
Host appBase directory on the Tomcat server is deployed as the web
346
Host appBase directory on the Tomcat server is deployed as the web
370
application context named <code>/bartoo</code>.</p>
347
application context named <code>/bartoo</code>.</p>
371
<source>
348
<source>Context Path: /bartoo
372
Context Path: /bartoo
349
WAR or Directory URL: bar.war</source>
373
WAR or Directory URL: bar.war
374
</source>
375
350
376
351
377
<h3>Deploy using a Context configuration ".xml" file</h3>
352
<h5>Deploy using a Context configuration ".xml" file</h5>
378
353
379
<p>If the Host deployXML flag is set to true, you can install a web
354
<p>If the Host deployXML flag is set to true, you can install a web
380
application using a Context configuration ".xml" file and an optional
355
application using a Context configuration ".xml" file and an optional
Lines 386-395 Link Here
386
web application Context just as if it were configured in your
361
web application Context just as if it were configured in your
387
Tomcat <code>server.xml</code> configuration file. Here is an
362
Tomcat <code>server.xml</code> configuration file. Here is an
388
example for Tomcat running on Windows:</p>
363
example for Tomcat running on Windows:</p>
389
<source>
364
<source><![CDATA[<Context path="/foobar" docBase="C:\path\to\application\foobar">
390
&lt;Context path="/foobar" docBase="C:\path\to\application\foobar"&gt;
365
</Context>]]></source>
391
&lt;/Context&gt;
392
</source>
393
366
394
367
395
<p>Use of the <i>WAR or Directory URL</i> is optional. When used
368
<p>Use of the <i>WAR or Directory URL</i> is optional. When used
Lines 398-415 Link Here
398
371
399
<p>Here is an example of installing an application using a Context
372
<p>Here is an example of installing an application using a Context
400
configuration ".xml" file for Tomcat running on Windows.</p>
373
configuration ".xml" file for Tomcat running on Windows.</p>
401
<source>
374
<source>XML Configuration file URL: file:C:/path/to/context.xml</source>
402
XML Configuration file URL: file:C:/path/to/context.xml
403
</source>
404
375
405
376
406
<p>Here is an example of installing an application using a Context
377
<p>Here is an example of installing an application using a Context
407
configuration ".xml" file and a web application ".war" file located
378
configuration ".xml" file and a web application ".war" file located
408
on the server (Tomcat running on Unix).</p>
379
on the server (Tomcat running on Unix).</p>
409
<source>
380
<source>XML Configuration file URL: file:/path/to/context.xml
410
XML Configuration file URL: file:/path/to/context.xml
381
WAR or Directory URL: jar:file:/path/to/bar.war!/</source>
411
WAR or Directory URL: jar:file:/path/to/bar.war!/
412
</source>
413
382
414
383
415
</subsection>
384
</subsection>
Lines 430-455 Link Here
430
<p>Upload of a WAR file could fail for the following reasons:</p>
399
<p>Upload of a WAR file could fail for the following reasons:</p>
431
<ul>
400
<ul>
432
<li><em>File uploaded must be a .war</em>
401
<li><em>File uploaded must be a .war</em>
433
    <blockquote>
434
    <p>The upload install will only accept files which have the filename
402
    <p>The upload install will only accept files which have the filename
435
    extension of ".war".</p>
403
    extension of ".war".</p>
436
    </blockquote></li>
404
    </li>
437
<li><em>War file already exists on server</em>
405
<li><em>War file already exists on server</em>
438
    <blockquote>
439
    <p>If a war file of the same name already exists in your Host's
406
    <p>If a war file of the same name already exists in your Host's
440
    appBase the upload will fail. Either undeploy the existing war file
407
    appBase the upload will fail. Either undeploy the existing war file
441
    from your Host's appBase or upload the new war file using a different
408
    from your Host's appBase or upload the new war file using a different
442
    name.</p>
409
    name.</p>
443
    </blockquote></li>
410
    </li>
444
<li><em>File upload failed, no file</em>
411
<li><em>File upload failed, no file</em>
445
    <blockquote>
446
    <p>The file upload failed, no file was received by the server.</p>
412
    <p>The file upload failed, no file was received by the server.</p>
447
    </blockquote></li>
413
    </li>
448
<li><em>Install Upload Failed, Exception:</em>
414
<li><em>Install Upload Failed, Exception:</em>
449
    <blockquote>
450
    <p>The war file upload or install failed with a Java Exception.
415
    <p>The war file upload or install failed with a Java Exception.
451
    The exception message will be listed.</p>
416
    The exception message will be listed.</p>
452
    </blockquote></li>
417
    </li>
453
</ul>
418
</ul>
454
419
455
</subsection>
420
</subsection>
Lines 477-538 Link Here
477
442
478
<p>If deployment and startup is successful, you will receive a Message
443
<p>If deployment and startup is successful, you will receive a Message
479
like this:</p>
444
like this:</p>
480
<source>
445
<source>OK - Deployed application at context path /foo</source>
481
OK - Deployed application at context path /foo
482
</source>
483
446
484
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
447
<p>Otherwise, the Message will start with <code>FAIL</code> and include an
485
error message.  Possible causes for problems include:</p>
448
error message.  Possible causes for problems include:</p>
486
<ul>
449
<ul>
487
<li><em>Application already exists at path /foo</em>
450
<li><em>Application already exists at path /foo</em>
488
    <blockquote>
489
    <p>The context paths for all currently running web applications must be
451
    <p>The context paths for all currently running web applications must be
490
    unique.  Therefore, you must either undeploy the existing web
452
    unique.  Therefore, you must either undeploy the existing web
491
    application using this context path, or choose a different context path
453
    application using this context path, or choose a different context path
492
    for the new one.</p>
454
    for the new one.</p>
493
    </blockquote></li>
455
    </li>
494
<li><em>Document base does not exist or is not a readable directory</em>
456
<li><em>Document base does not exist or is not a readable directory</em>
495
    <blockquote>
496
    <p>The URL specified by the <i>WAR or Directory URL:</i> field must
457
    <p>The URL specified by the <i>WAR or Directory URL:</i> field must
497
    identify a directory on this server that contains the "unpacked" version
458
    identify a directory on this server that contains the "unpacked" version
498
    of a web application, or the absolute URL of a web application archive
459
    of a web application, or the absolute URL of a web application archive
499
    (WAR) file that contains this application.  Correct the value entered for
460
    (WAR) file that contains this application.  Correct the value entered for
500
    the <i>WAR or Directory URL:</i> field.</p>
461
    the <i>WAR or Directory URL:</i> field.</p>
501
    </blockquote></li>
462
    </li>
502
<li><em>Encountered exception</em>
463
<li><em>Encountered exception</em>
503
    <blockquote>
504
    <p>An exception was encountered trying to start the new web application.
464
    <p>An exception was encountered trying to start the new web application.
505
    Check the Tomcat logs for the details, but likely explanations include
465
    Check the Tomcat logs for the details, but likely explanations include
506
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
466
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
507
    classes encountered when initializing application event listeners and
467
    classes encountered when initializing application event listeners and
508
    filters.</p>
468
    filters.</p>
509
    </blockquote></li>
469
    </li>
510
<li><em>Invalid application URL was specified</em>
470
<li><em>Invalid application URL was specified</em>
511
    <blockquote>
512
    <p>The URL for the <i>WAR or Directory URL:</i> field that you specified
471
    <p>The URL for the <i>WAR or Directory URL:</i> field that you specified
513
    was not valid.  Such URLs must start with <code>file:</code>, and URLs
472
    was not valid.  Such URLs must start with <code>file:</code>, and URLs
514
    for a WAR file must end in ".war".</p>
473
    for a WAR file must end in ".war".</p>
515
    </blockquote></li>
474
    </li>
516
<li><em>Invalid context path was specified</em>
475
<li><em>Invalid context path was specified</em>
517
    <blockquote>
518
    <p>The context path must start with a slash character, unless you are
476
    <p>The context path must start with a slash character, unless you are
519
    referencing the ROOT web application -- in which case the context path
477
    referencing the ROOT web application -- in which case the context path
520
    must be a "/" string.</p>
478
    must be a "/" string.</p>
521
    </blockquote></li>
479
    </li>
522
<li><em>Context path must match the directory or WAR file name:</em>
480
<li><em>Context path must match the directory or WAR file name:</em>
523
    <blockquote>
481
    <p>If the application war or directory is deployed in your Host appBase
524
    If the application war or directory is deployed in your Host appBase
525
    directory and either the Host is configured with autoDeploy=true the Context
482
    directory and either the Host is configured with autoDeploy=true the Context
526
    path must match the directory name or war file name without the ".war"
483
    path must match the directory name or war file name without the ".war"
527
    extension.
484
    extension.</p>
528
    </blockquote></li>
485
    </li>
529
<li><em>Only web applications in the Host web application directory can
486
<li><em>Only web applications in the Host web application directory can
530
     be deployed</em>
487
     be deployed</em>
531
     <blockquote>
488
     <p>
532
     If the Host deployXML flag is set to false this error will happen
489
     If the Host deployXML flag is set to false this error will happen
533
     if an attempt is made to install a web application directory or
490
     if an attempt is made to install a web application directory or
534
      ".war" file outside of the Host appBase directory.
491
      ".war" file outside of the Host appBase directory.
535
     </blockquote></li>
492
     </p></li>
536
</ul>
493
</ul>
537
494
538
</subsection>
495
</subsection>
(-)webapps/docs/jasper-howto.xml (-55 / +48 lines)
Lines 42-48 Link Here
42
42
43
<p>Jasper 2 has been redesigned to significantly improve performance over
43
<p>Jasper 2 has been redesigned to significantly improve performance over
44
the original Jasper.  In addition to general code improvements the following
44
the original Jasper.  In addition to general code improvements the following
45
changes were made:
45
changes were made:</p>
46
<ul>
46
<ul>
47
<li><strong>JSP Custom Tag Pooling</strong> - The java objects instantiated
47
<li><strong>JSP Custom Tag Pooling</strong> - The java objects instantiated
48
for JSP Custom Tags can now be pooled and reused.  This significantly boosts
48
for JSP Custom Tags can now be pooled and reused.  This significantly boosts
Lines 61-68 Link Here
61
compilation. This compiler loads source dependencies from the container
61
compilation. This compiler loads source dependencies from the container
62
classloader. Ant and javac can still be used.</li>
62
classloader. Ant and javac can still be used.</li>
63
</ul>
63
</ul>
64
</p>
65
64
65
66
<p>Jasper is implemented using the servlet class
66
<p>Jasper is implemented using the servlet class
67
<code>org.apache.jasper.servlet.JspServlet</code>.</p>
67
<code>org.apache.jasper.servlet.JspServlet</code>.</p>
68
68
Lines 71-83 Link Here
71
<section name="Configuration">
71
<section name="Configuration">
72
72
73
<p>By default Jasper is configured for use when doing web application
73
<p>By default Jasper is configured for use when doing web application
74
development.  See the section <a href="#Production Configuration">
74
development.  See the section <a href="#Production_Configuration">
75
Production Configuration</a> for information on configuring Jasper
75
Production Configuration</a> for information on configuring Jasper
76
for use on a production Tomcat server.</p>
76
for use on a production Tomcat server.</p>
77
77
78
<p>The servlet which implements Jasper is configured using init parameters
78
<p>The servlet which implements Jasper is configured using init parameters
79
in your global <code>$CATALINA_BASE/conf/web.xml</code>.
79
in your global <code>$CATALINA_BASE/conf/web.xml</code>.
80
80
</p>
81
<ul>
81
<ul>
82
<li><strong>checkInterval</strong> - If development is false and checkInterval
82
<li><strong>checkInterval</strong> - If development is false and checkInterval
83
is greater than zero, background compiles are enabled. checkInterval is the time
83
is greater than zero, background compiles are enabled. checkInterval is the time
Lines 198-205 Link Here
198
header is added by generated servlet. <code>true</code> or <code>false</code>,
198
header is added by generated servlet. <code>true</code> or <code>false</code>,
199
default <code>false</code>.</li>
199
default <code>false</code>.</li>
200
</ul>
200
</ul>
201
</p>
202
201
202
203
<p>The Java compiler from Eclipse JDT in included as the default compiler. It is
203
<p>The Java compiler from Eclipse JDT in included as the default compiler. It is
204
an advanced Java compiler which will load all dependencies from the Tomcat class
204
an advanced Java compiler which will load all dependencies from the Tomcat class
205
loader, which will help tremendously when compiling on large installations with
205
loader, which will help tremendously when compiling on large installations with
Lines 222-233 Link Here
222
<code>java.lang.InternalError: name is too long to represent</code> exception
222
<code>java.lang.InternalError: name is too long to represent</code> exception
223
when compiling very large JSPs. If this is observed then it may be worked around
223
when compiling very large JSPs. If this is observed then it may be worked around
224
by using one of the following:
224
by using one of the following:
225
</p>
225
<ul>
226
<ul>
226
<li>reduce the size of the JSP</li>
227
<li>reduce the size of the JSP</li>
227
<li>disable SMAP generation and JSR-045 support by setting
228
<li>disable SMAP generation and JSR-045 support by setting
228
<code>suppressSmap</code> to <code>true</code>.</li>
229
<code>suppressSmap</code> to <code>true</code>.</li>
229
</ul>
230
</ul>
230
</p>
231
231
232
</section>
232
</section>
233
233
Lines 239-245 Link Here
239
Jasper servlet becomes critical.</p>
239
Jasper servlet becomes critical.</p>
240
240
241
<p>When using Jasper 2 in a production Tomcat server you should consider making
241
<p>When using Jasper 2 in a production Tomcat server you should consider making
242
the following changes from the default configuration.
242
the following changes from the default configuration.</p>
243
<ul>
243
<ul>
244
<li><strong>development</strong> - To disable on access checks for JSP
244
<li><strong>development</strong> - To disable on access checks for JSP
245
pages compilation set this to <code>false</code>.</li>
245
pages compilation set this to <code>false</code>.</li>
Lines 251-257 Link Here
251
<li><strong>trimSpaces</strong> - To remove useless bytes from the response,
251
<li><strong>trimSpaces</strong> - To remove useless bytes from the response,
252
set this to <code>true</code>.</li>
252
set this to <code>true</code>.</li>
253
</ul>
253
</ul>
254
</p>
255
254
256
</section>
255
</section>
257
256
Lines 264-337 Link Here
264
download) to precompile a webapp:
263
download) to precompile a webapp:
265
</p>
264
</p>
266
265
267
<p>
266
<source><![CDATA[<project name="Webapp Precompilation" default="all" basedir=".">
268
<source>
269
&lt;project name="Webapp Precompilation" default="all" basedir="."&gt;
270
267
271
   &lt;import file="${tomcat.home}/bin/catalina-tasks.xml"/&gt;
268
   <import file="${tomcat.home}/bin/catalina-tasks.xml"/>
272
269
273
   &lt;target name="jspc"&gt;
270
   <target name="jspc">
274
271
275
    &lt;jasper
272
    <jasper
276
             validateXml="false"
273
             validateXml="false"
277
             uriroot="${webapp.path}"
274
             uriroot="${webapp.path}"
278
             webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml"
275
             webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml"
279
             outputDir="${webapp.path}/WEB-INF/src" /&gt;
276
             outputDir="${webapp.path}/WEB-INF/src" />
280
277
281
  &lt;/target&gt;
278
  </target>
282
279
283
  &lt;target name="compile"&gt;
280
  <target name="compile">
284
281
285
    &lt;mkdir dir="${webapp.path}/WEB-INF/classes"/&gt;
282
    <mkdir dir="${webapp.path}/WEB-INF/classes"/>
286
    &lt;mkdir dir="${webapp.path}/WEB-INF/lib"/&gt;
283
    <mkdir dir="${webapp.path}/WEB-INF/lib"/>
287
284
288
    &lt;javac destdir="${webapp.path}/WEB-INF/classes"
285
    <javac destdir="${webapp.path}/WEB-INF/classes"
289
           optimize="off"
286
           optimize="off"
290
           debug="on" failonerror="false"
287
           debug="on" failonerror="false"
291
           srcdir="${webapp.path}/WEB-INF/src"
288
           srcdir="${webapp.path}/WEB-INF/src"
292
           excludes="**/*.smap"&gt;
289
           excludes="**/*.smap">
293
      &lt;classpath&gt;
290
      <classpath>
294
        &lt;pathelement location="${webapp.path}/WEB-INF/classes"/&gt;
291
        <pathelement location="${webapp.path}/WEB-INF/classes"/>
295
        &lt;fileset dir="${webapp.path}/WEB-INF/lib"&gt;
292
        <fileset dir="${webapp.path}/WEB-INF/lib">
296
          &lt;include name="*.jar"/&gt;
293
          <include name="*.jar"/>
297
        &lt;/fileset&gt;
294
        </fileset>
298
        &lt;pathelement location="${tomcat.home}/lib"/&gt;
295
        <pathelement location="${tomcat.home}/lib"/>
299
        &lt;fileset dir="${tomcat.home}/lib"&gt;
296
        <fileset dir="${tomcat.home}/lib">
300
          &lt;include name="*.jar"/&gt;
297
          <include name="*.jar"/>
301
        &lt;/fileset&gt;
298
        </fileset>
302
        &lt;fileset dir="${tomcat.home}/bin"&gt;
299
        <fileset dir="${tomcat.home}/bin">
303
          &lt;include name="*.jar"/&gt;
300
          <include name="*.jar"/>
304
        &lt;/fileset&gt;
301
        </fileset>
305
      &lt;/classpath&gt;
302
      </classpath>
306
      &lt;include name="**" /&gt;
303
      <include name="**" />
307
      &lt;exclude name="tags/**" /&gt;
304
      <exclude name="tags/**" />
308
    &lt;/javac&gt;
305
    </javac>
309
306
310
  &lt;/target&gt;
307
  </target>
311
308
312
  &lt;target name="all" depends="jspc,compile"&gt;
309
  <target name="all" depends="jspc,compile">
313
  &lt;/target&gt;
310
  </target>
314
311
315
  &lt;target name="cleanup"&gt;
312
  <target name="cleanup">
316
    &lt;delete&gt;
313
    <delete>
317
        &lt;fileset dir="${webapp.path}/WEB-INF/src"/&gt;
314
        <fileset dir="${webapp.path}/WEB-INF/src"/>
318
        &lt;fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/&gt;
315
        <fileset dir="${webapp.path}/WEB-INF/classes/org/apache/jsp"/>
319
    &lt;/delete&gt;
316
    </delete>
320
  &lt;/target&gt;
317
  </target>
321
318
322
&lt;/project&gt;
319
</project>]]></source>
323
</source>
324
</p>
325
320
326
<p>
321
<p>
327
The following command line can be used to run the script
322
The following command line can be used to run the script
328
(replacing the tokens with the Tomcat base path and the path to the webapp
323
(replacing the tokens with the Tomcat base path and the path to the webapp
329
which should be precompiled):<br/>
324
which should be precompiled):
330
<source>
331
$ANT_HOME/bin/ant -Dtomcat.home=&lt;$TOMCAT_HOME&gt; -Dwebapp.path=&lt;$WEBAPP_PATH&gt;
332
</source>
333
</p>
325
</p>
326
<source>$ANT_HOME/bin/ant -Dtomcat.home=&lt;$TOMCAT_HOME&gt; -Dwebapp.path=&lt;$WEBAPP_PATH&gt;</source>
334
327
328
335
<p>
329
<p>
336
Then, the declarations and mappings for the servlets which were generated
330
Then, the declarations and mappings for the servlets which were generated
337
during the precompilation must be added to the web application deployment
331
during the precompilation must be added to the web application deployment
Lines 366-372 Link Here
366
<code>${webapp.path}/WEB-INF/classes/org/apache/jsp</code>.
360
<code>${webapp.path}/WEB-INF/classes/org/apache/jsp</code>.
367
</p>
361
</p>
368
362
369
<p><strong>Hints:</strong>
363
<p><strong>Hints:</strong></p>
370
<ul>
364
<ul>
371
<li> When you switch to another Tomcat release, then regenerate and recompile
365
<li> When you switch to another Tomcat release, then regenerate and recompile
372
your jsp's with the new Tomcat version.</li>
366
your jsp's with the new Tomcat version.</li>
Lines 377-383 Link Here
377
that changing from the defaults may affect performance, but it will vary
371
that changing from the defaults may affect performance, but it will vary
378
depending on the application.</li>
372
depending on the application.</li>
379
</ul>
373
</ul>
380
</p>
381
</section>
374
</section>
382
375
383
<section name="Optimisation">
376
<section name="Optimisation">
(-)webapps/docs/jndi-datasource-examples-howto.xml (-126 / +97 lines)
Lines 196-202 Link Here
196
196
197
<subsection name="MySQL DBCP Example">
197
<subsection name="MySQL DBCP Example">
198
198
199
<h3>0. Introduction</h3>
199
<h5>0. Introduction</h5>
200
<p>Versions of <a href="http://www.mysql.com/products/mysql/index.html">MySQL</a> and JDBC
200
<p>Versions of <a href="http://www.mysql.com/products/mysql/index.html">MySQL</a> and JDBC
201
drivers that have been reported to work:
201
drivers that have been reported to work:
202
</p>
202
</p>
Lines 208-214 Link Here
208
208
209
<p>Before you proceed, don't forget to copy the JDBC Driver's jar into <code>$CATALINA_HOME/lib</code>.</p>
209
<p>Before you proceed, don't forget to copy the JDBC Driver's jar into <code>$CATALINA_HOME/lib</code>.</p>
210
210
211
<h3>1. MySQL configuration</h3>
211
<h5>1. MySQL configuration</h5>
212
<p>
212
<p>
213
Ensure that you follow these instructions as variations can cause problems.
213
Ensure that you follow these instructions as variations can cause problems.
214
</p>
214
</p>
Lines 217-232 Link Here
217
Your MySQL user <strong>must</strong> have a password assigned. The driver
217
Your MySQL user <strong>must</strong> have a password assigned. The driver
218
will fail if you try to connect with an empty password.
218
will fail if you try to connect with an empty password.
219
</p>
219
</p>
220
<source>
220
<source><![CDATA[mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
221
mysql&gt; GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
221
    ->   IDENTIFIED BY 'javadude' WITH GRANT OPTION;
222
    -&gt;   IDENTIFIED BY 'javadude' WITH GRANT OPTION;
222
mysql> create database javatest;
223
mysql&gt; create database javatest;
223
mysql> use javatest;
224
mysql&gt; use javatest;
224
mysql> create table testdata (
225
mysql&gt; create table testdata (
225
    ->   id int not null auto_increment primary key,
226
    -&gt;   id int not null auto_increment primary key,
226
    ->   foo varchar(25),
227
    -&gt;   foo varchar(25),
227
    ->   bar int);]]></source>
228
    -&gt;   bar int);
229
</source>
230
<blockquote>
228
<blockquote>
231
<strong>Note:</strong> the above user should be removed once testing is
229
<strong>Note:</strong> the above user should be removed once testing is
232
complete!
230
complete!
Lines 234-241 Link Here
234
232
235
<p>Next insert some test data into the testdata table.
233
<p>Next insert some test data into the testdata table.
236
</p>
234
</p>
237
<source>
235
<source><![CDATA[mysql> insert into testdata values(null, 'hello', 12345);
238
mysql&gt; insert into testdata values(null, 'hello', 12345);
239
Query OK, 1 row affected (0.00 sec)
236
Query OK, 1 row affected (0.00 sec)
240
237
241
mysql> select * from testdata;
238
mysql> select * from testdata;
Lines 246-340 Link Here
246
+----+-------+-------+
243
+----+-------+-------+
247
1 row in set (0.00 sec)
244
1 row in set (0.00 sec)
248
245
249
mysql&gt;
246
mysql>]]></source>
250
</source>
251
247
252
<h3>2. Context configuration</h3>
248
<h5>2. Context configuration</h5>
253
<p>Configure the JNDI DataSource in Tomcat by adding a declaration for your
249
<p>Configure the JNDI DataSource in Tomcat by adding a declaration for your
254
resource to your <a href="config/context.html">Context</a>.</p>
250
resource to your <a href="config/context.html">Context</a>.</p>
255
<p>For example:</p>
251
<p>For example:</p>
256
<source>
252
<source><![CDATA[<Context>
257
&lt;Context&gt;
258
253
259
    &lt;!-- maxActive: Maximum number of database connections in pool. Make sure you
254
    <!-- maxActive: Maximum number of database connections in pool. Make sure you
260
         configure your mysqld max_connections large enough to handle
255
         configure your mysqld max_connections large enough to handle
261
         all of your db connections. Set to -1 for no limit.
256
         all of your db connections. Set to -1 for no limit.
262
         --&gt;
257
         -->
263
258
264
    &lt;!-- maxIdle: Maximum number of idle database connections to retain in pool.
259
    <!-- maxIdle: Maximum number of idle database connections to retain in pool.
265
         Set to -1 for no limit.  See also the DBCP documentation on this
260
         Set to -1 for no limit.  See also the DBCP documentation on this
266
         and the minEvictableIdleTimeMillis configuration parameter.
261
         and the minEvictableIdleTimeMillis configuration parameter.
267
         --&gt;
262
         -->
268
263
269
    &lt;!-- maxWait: Maximum time to wait for a database connection to become available
264
    <!-- maxWait: Maximum time to wait for a database connection to become available
270
         in ms, in this example 10 seconds. An Exception is thrown if
265
         in ms, in this example 10 seconds. An Exception is thrown if
271
         this timeout is exceeded.  Set to -1 to wait indefinitely.
266
         this timeout is exceeded.  Set to -1 to wait indefinitely.
272
         --&gt;
267
         -->
273
268
274
    &lt;!-- username and password: MySQL username and password for database connections  --&gt;
269
    <!-- username and password: MySQL username and password for database connections  -->
275
270
276
    &lt;!-- driverClassName: Class name for the old mm.mysql JDBC driver is
271
    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
277
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
272
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
278
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
273
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
279
         --&gt;
274
         -->
280
275
281
    &lt;!-- url: The JDBC connection url for connecting to your MySQL database.
276
    <!-- url: The JDBC connection url for connecting to your MySQL database.
282
         --&gt;
277
         -->
283
278
284
  &lt;Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
279
  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
285
               maxActive="100" maxIdle="30" maxWait="10000"
280
               maxActive="100" maxIdle="30" maxWait="10000"
286
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
281
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
287
               url="jdbc:mysql://localhost:3306/javatest"/&gt;
282
               url="jdbc:mysql://localhost:3306/javatest"/>
288
283
289
&lt;/Context&gt;
284
</Context>]]></source>
290
</source>
291
285
292
<h3>3. web.xml configuration</h3>
286
<h5>3. web.xml configuration</h5>
293
287
294
<p>Now create a <code>WEB-INF/web.xml</code> for this test application.</p>
288
<p>Now create a <code>WEB-INF/web.xml</code> for this test application.</p>
295
<source>
289
<source><![CDATA[<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
296
&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee"
297
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
290
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
298
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
291
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
299
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
292
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
300
    version="2.4"&gt;
293
    version="2.4">
301
  &lt;description&gt;MySQL Test App&lt;/description&gt;
294
  <description>MySQL Test App</description>
302
  &lt;resource-ref&gt;
295
  <resource-ref>
303
      &lt;description&gt;DB Connection&lt;/description&gt;
296
      <description>DB Connection</description>
304
      &lt;res-ref-name&gt;jdbc/TestDB&lt;/res-ref-name&gt;
297
      <res-ref-name>jdbc/TestDB</res-ref-name>
305
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
298
      <res-type>javax.sql.DataSource</res-type>
306
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
299
      <res-auth>Container</res-auth>
307
  &lt;/resource-ref&gt;
300
  </resource-ref>
308
&lt;/web-app&gt;
301
</web-app>]]></source>
309
</source>
310
302
311
<h3>4. Test code</h3>
303
<h5>4. Test code</h5>
312
<p>Now create a simple <code>test.jsp</code> page for use later.
304
<p>Now create a simple <code>test.jsp</code> page for use later.</p>
313
<source>
305
<source><![CDATA[<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
314
&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %&gt;
306
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
315
&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
316
307
317
&lt;sql:query var="rs" dataSource="jdbc/TestDB"&gt;
308
<sql:query var="rs" dataSource="jdbc/TestDB">
318
select id, foo, bar from testdata
309
select id, foo, bar from testdata
319
&lt;/sql:query&gt;
310
</sql:query>
320
311
321
&lt;html&gt;
312
<html>
322
  &lt;head&gt;
313
  <head>
323
    &lt;title&gt;DB Test&lt;/title&gt;
314
    <title>DB Test</title>
324
  &lt;/head&gt;
315
  </head>
325
  &lt;body&gt;
316
  <body>
326
317
327
  &lt;h2&gt;Results&lt;/h2&gt;
318
  <h2>Results</h2>
328
319
329
&lt;c:forEach var="row" items="${rs.rows}"&gt;
320
<c:forEach var="row" items="${rs.rows}">
330
    Foo ${row.foo}&lt;br/&gt;
321
    Foo ${row.foo}<br/>
331
    Bar ${row.bar}&lt;br/&gt;
322
    Bar ${row.bar}<br/>
332
&lt;/c:forEach&gt;
323
</c:forEach>
333
324
334
  &lt;/body&gt;
325
  </body>
335
&lt;/html&gt;
326
</html>]]></source>
336
</source>
337
</p>
338
327
339
<p>That JSP page makes use of <a href="http://java.sun.com/products/jsp/jstl">JSTL</a>'s
328
<p>That JSP page makes use of <a href="http://java.sun.com/products/jsp/jstl">JSTL</a>'s
340
SQL and Core taglibs. You can get it from
329
SQL and Core taglibs. You can get it from
Lines 355-361 Link Here
355
</subsection>
344
</subsection>
356
345
357
<subsection name="Oracle 8i, 9i &amp; 10g">
346
<subsection name="Oracle 8i, 9i &amp; 10g">
358
<h3>0.    Introduction</h3>
347
<h5>0.    Introduction</h5>
359
348
360
<p>Oracle requires minimal changes from the MySQL configuration except for the
349
<p>Oracle requires minimal changes from the MySQL configuration except for the
361
usual gotchas :-)</p>
350
usual gotchas :-)</p>
Lines 372-378 Link Here
372
for this driver class will be discontinued in the next major release.
361
for this driver class will be discontinued in the next major release.
373
</p>
362
</p>
374
363
375
<h3>1. Context configuration</h3>
364
<h5>1. Context configuration</h5>
376
<p>In a similar manner to the mysql config above, you will need to define your
365
<p>In a similar manner to the mysql config above, you will need to define your
377
Datasource in your <a href="config/context.html">Context</a>. Here we define a
366
Datasource in your <a href="config/context.html">Context</a>. Here we define a
378
Datasource called myoracle using the thin driver to connect as user scott,
367
Datasource called myoracle using the thin driver to connect as user scott,
Lines 382-424 Link Here
382
371
383
<p>Use of the OCI driver should simply involve a changing thin to oci in the URL string.
372
<p>Use of the OCI driver should simply involve a changing thin to oci in the URL string.
384
</p>
373
</p>
385
<source>
374
<source><![CDATA[<Resource name="jdbc/myoracle" auth="Container"
386
&lt;Resource name="jdbc/myoracle" auth="Container"
387
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
375
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
388
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
376
              url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
389
              username="scott" password="tiger" maxActive="20" maxIdle="10"
377
              username="scott" password="tiger" maxActive="20" maxIdle="10"
390
              maxWait="-1"/&gt;
378
              maxWait="-1"/>]]></source>
391
</source>
392
379
393
<h3>2.    web.xml configuration</h3>
380
<h5>2.    web.xml configuration</h5>
394
<p>You should ensure that you respect the element ordering defined by the DTD when you
381
<p>You should ensure that you respect the element ordering defined by the DTD when you
395
create you applications web.xml file.</p>
382
create you applications web.xml file.</p>
396
<source>
383
<source><![CDATA[<resource-ref>
397
&lt;resource-ref&gt;
384
 <description>Oracle Datasource example</description>
398
 &lt;description&gt;Oracle Datasource example&lt;/description&gt;
385
 <res-ref-name>jdbc/myoracle</res-ref-name>
399
 &lt;res-ref-name&gt;jdbc/myoracle&lt;/res-ref-name&gt;
386
 <res-type>javax.sql.DataSource</res-type>
400
 &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
387
 <res-auth>Container</res-auth>
401
 &lt;res-auth&gt;Container&lt;/res-auth&gt;
388
</resource-ref>]]></source>
402
&lt;/resource-ref&gt;
389
<h5>3.   Code example</h5>
403
</source>
404
<h3>3.   Code example</h3>
405
<p>You can use the same example application as above (asuming you create the required DB
390
<p>You can use the same example application as above (asuming you create the required DB
406
instance, tables etc.) replacing the Datasource code with something like</p>
391
instance, tables etc.) replacing the Datasource code with something like</p>
407
<source>
392
<source><![CDATA[Context initContext = new InitialContext();
408
Context initContext = new InitialContext();
409
Context envContext  = (Context)initContext.lookup("java:/comp/env");
393
Context envContext  = (Context)initContext.lookup("java:/comp/env");
410
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
394
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
411
Connection conn = ds.getConnection();
395
Connection conn = ds.getConnection();
412
//etc.
396
//etc.]]></source>
413
</source>
414
</subsection>
397
</subsection>
415
398
416
399
417
<subsection name="PostgreSQL">
400
<subsection name="PostgreSQL">
418
<h3>0.    Introduction</h3>
401
<h5>0.    Introduction</h5>
419
<p>PostgreSQL is configured in a similar manner to Oracle.</p>
402
<p>PostgreSQL is configured in a similar manner to Oracle.</p>
420
403
421
<h3>1. Required files </h3>
404
<h5>1. Required files </h5>
422
<p>
405
<p>
423
Copy the Postgres JDBC jar to $CATALINA_HOME/lib. As with Oracle, the
406
Copy the Postgres JDBC jar to $CATALINA_HOME/lib. As with Oracle, the
424
jars need to be in this directory in order for DBCP's Classloader to find
407
jars need to be in this directory in order for DBCP's Classloader to find
Lines 425-431 Link Here
425
them. This has to be done regardless of which configuration step you take next.
408
them. This has to be done regardless of which configuration step you take next.
426
</p>
409
</p>
427
410
428
<h3>2. Resource configuration</h3>
411
<h5>2. Resource configuration</h5>
429
412
430
<p>
413
<p>
431
You have two choices here: define a datasource that is shared across all Tomcat
414
You have two choices here: define a datasource that is shared across all Tomcat
Lines 432-438 Link Here
432
applications, or define a datasource specifically for one application.
415
applications, or define a datasource specifically for one application.
433
</p>
416
</p>
434
417
435
<h4>2a. Shared resource configuration</h4>
418
<h6>2a. Shared resource configuration</h6>
436
<p>
419
<p>
437
Use this option if you wish to define a datasource that is shared across
420
Use this option if you wish to define a datasource that is shared across
438
multiple Tomcat applications, or if you just prefer defining your datasource
421
multiple Tomcat applications, or if you just prefer defining your datasource
Lines 441-453 Link Here
441
<p><i>This author has not had success here, although others have reported so.
424
<p><i>This author has not had success here, although others have reported so.
442
Clarification would be appreciated here.</i></p>
425
Clarification would be appreciated here.</i></p>
443
426
444
<source>
427
<source><![CDATA[<Resource name="jdbc/postgres" auth="Container"
445
&lt;Resource name="jdbc/postgres" auth="Container"
446
          type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
428
          type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
447
          url="jdbc:postgresql://127.0.0.1:5432/mydb"
429
          url="jdbc:postgresql://127.0.0.1:5432/mydb"
448
          username="myuser" password="mypasswd" maxActive="20" maxIdle="10" maxWait="-1"/&gt;
430
          username="myuser" password="mypasswd" maxActive="20" maxIdle="10" maxWait="-1"/>]]></source>
449
</source>
431
<h6>2b. Application-specific resource configuration</h6>
450
<h4>2b. Application-specific resource configuration</h4>
451
432
452
<p>
433
<p>
453
Use this option if you wish to define a datasource specific to your application,
434
Use this option if you wish to define a datasource specific to your application,
Lines 460-487 Link Here
460
The Context element should look something like the following.
441
The Context element should look something like the following.
461
</p>
442
</p>
462
443
463
<source>
444
<source><![CDATA[<Context>
464
&lt;Context&gt;
465
445
466
&lt;Resource name="jdbc/postgres" auth="Container"
446
<Resource name="jdbc/postgres" auth="Container"
467
          type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
447
          type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
468
          url="jdbc:postgresql://127.0.0.1:5432/mydb"
448
          url="jdbc:postgresql://127.0.0.1:5432/mydb"
469
          username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
449
          username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
470
maxWait="-1"/&gt;
450
maxWait="-1"/>
471
&lt;/Context&gt;
451
</Context>]]></source>
472
</source>
473
452
474
<h3>3. web.xml configuration</h3>
453
<h5>3. web.xml configuration</h5>
475
<source>
454
<source><![CDATA[<resource-ref>
476
&lt;resource-ref&gt;
455
 <description>postgreSQL Datasource example</description>
477
 &lt;description&gt;postgreSQL Datasource example&lt;/description&gt;
456
 <res-ref-name>jdbc/postgres</res-ref-name>
478
 &lt;res-ref-name&gt;jdbc/postgres&lt;/res-ref-name&gt;
457
 <res-type>javax.sql.DataSource</res-type>
479
 &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
458
 <res-auth>Container</res-auth>
480
 &lt;res-auth&gt;Container&lt;/res-auth&gt;
459
</resource-ref>]]></source>
481
&lt;/resource-ref&gt;
482
</source>
483
460
484
<h4>4. Accessing the datasource</h4>
461
<h5>4. Accessing the datasource</h5>
485
<p>
462
<p>
486
When accessing the datasource programmatically, remember to prepend
463
When accessing the datasource programmatically, remember to prepend
487
<code>java:/comp/env</code> to your JNDI lookup, as in the following snippet of
464
<code>java:/comp/env</code> to your JNDI lookup, as in the following snippet of
Lines 489-496 Link Here
489
you change it in the above resource definition file as well.
466
you change it in the above resource definition file as well.
490
</p>
467
</p>
491
468
492
<source>
469
<source><![CDATA[InitialContext cxt = new InitialContext();
493
InitialContext cxt = new InitialContext();
494
if ( cxt == null ) {
470
if ( cxt == null ) {
495
   throw new Exception("Uh oh -- no context!");
471
   throw new Exception("Uh oh -- no context!");
496
}
472
}
Lines 499-506 Link Here
499
475
500
if ( ds == null ) {
476
if ( ds == null ) {
501
   throw new Exception("Data source not found!");
477
   throw new Exception("Data source not found!");
502
}
478
}]]></source>
503
</source>
504
479
505
</subsection>
480
</subsection>
506
</section>
481
</section>
Lines 539-550 Link Here
539
You should next create a simple test servlet or jsp that has these
514
You should next create a simple test servlet or jsp that has these
540
<strong>critical lines</strong>:
515
<strong>critical lines</strong>:
541
</p>
516
</p>
542
<source>
517
<source><![CDATA[DriverManager.registerDriver(new
543
DriverManager.registerDriver(new
544
oracle.jdbc.driver.OracleDriver());
518
oracle.jdbc.driver.OracleDriver());
545
conn =
519
conn =
546
DriverManager.getConnection("jdbc:oracle:oci8:@database","username","password");
520
DriverManager.getConnection("jdbc:oracle:oci8:@database","username","password");]]></source>
547
</source>
548
<p>
521
<p>
549
where database is of the form <code>host:port:SID</code> Now if you try to access the URL of your
522
where database is of the form <code>host:port:SID</code> Now if you try to access the URL of your
550
test servlet/jsp and what you get is a
523
test servlet/jsp and what you get is a
Lines 552-557 Link Here
552
</p>
525
</p>
553
<p>
526
<p>
554
First, the <code>UnsatisfiedLinkError</code> indicates that you have
527
First, the <code>UnsatisfiedLinkError</code> indicates that you have
528
</p>
555
<ul>
529
<ul>
556
<li>a mismatch between your JDBC classes file and
530
<li>a mismatch between your JDBC classes file and
557
your Oracle client version. The giveaway here is the message stating that a needed library file cannot be
531
your Oracle client version. The giveaway here is the message stating that a needed library file cannot be
Lines 563-569 Link Here
563
the classes12.zip file from the directory <code>$ORAHOME\jdbc\lib</code> will also work.
537
the classes12.zip file from the directory <code>$ORAHOME\jdbc\lib</code> will also work.
564
</li>
538
</li>
565
</ul>
539
</ul>
566
</p>
567
<p>
540
<p>
568
Next you may experience the error <code>ORA-06401 NETCMN: invalid driver designator</code>
541
Next you may experience the error <code>ORA-06401 NETCMN: invalid driver designator</code>
569
</p>
542
</p>
Lines 640-647 Link Here
640
Here is an example of properly written code to use a database connection
613
Here is an example of properly written code to use a database connection
641
obtained from a connection pool:
614
obtained from a connection pool:
642
</p>
615
</p>
643
<pre>
616
<source><![CDATA[  Connection conn = null;
644
  Connection conn = null;
645
  Statement stmt = null;  // Or PreparedStatement if needed
617
  Statement stmt = null;  // Or PreparedStatement if needed
646
  ResultSet rs = null;
618
  ResultSet rs = null;
647
  try {
619
  try {
Lines 672-679 Link Here
672
      try { conn.close(); } catch (SQLException e) { ; }
644
      try { conn.close(); } catch (SQLException e) { ; }
673
      conn = null;
645
      conn = null;
674
    }
646
    }
675
  }
647
  }]]></source>
676
</pre>
677
648
678
</subsection>
649
</subsection>
679
650
(-)webapps/docs/jndi-resources-howto.xml (-145 / +111 lines)
Lines 108-125 Link Here
108
element:</p>
108
element:</p>
109
109
110
<ul>
110
<ul>
111
<li><a href="config/context.html#Environment Entries">&lt;Environment&gt;</a> -
111
<li><a href="config/context.html#Environment_Entries">&lt;Environment&gt;</a> -
112
    Configure names and values for scalar environment entries that will be
112
    Configure names and values for scalar environment entries that will be
113
    exposed to the web application through the JNDI
113
    exposed to the web application through the JNDI
114
    <code>InitialContext</code> (equivalent to the inclusion of an
114
    <code>InitialContext</code> (equivalent to the inclusion of an
115
    <code>&lt;env-entry&gt;</code> element in the web application
115
    <code>&lt;env-entry&gt;</code> element in the web application
116
    deployment descriptor).</li>
116
    deployment descriptor).</li>
117
<li><a href="config/context.html#Resource Definitions">&lt;Resource&gt;</a> -
117
<li><a href="config/context.html#Resource_Definitions">&lt;Resource&gt;</a> -
118
    Configure the name and data type of a resource made available to the
118
    Configure the name and data type of a resource made available to the
119
    application (equivalent to the inclusion of a
119
    application (equivalent to the inclusion of a
120
    <code>&lt;resource-ref&gt;</code> element in the web application
120
    <code>&lt;resource-ref&gt;</code> element in the web application
121
    deployment descriptor).</li>
121
    deployment descriptor).</li>
122
<li><a href="config/context.html#Resource Links">&lt;ResourceLink&gt;</a> -
122
<li><a href="config/context.html#Resource_Links">&lt;ResourceLink&gt;</a> -
123
    Add a link to a resource defined in the global JNDI context. Use resource
123
    Add a link to a resource defined in the global JNDI context. Use resource
124
    links to give a web application access to a resource defined in
124
    links to give a web application access to a resource defined in
125
    the <a href="config/globalresources.html">&lt;GlobalNamingResources&gt;</a>
125
    the <a href="config/globalresources.html">&lt;GlobalNamingResources&gt;</a>
Lines 161-171 Link Here
161
<code><strong>&lt;GlobalNamingResources&gt;</strong></code></a> element of
161
<code><strong>&lt;GlobalNamingResources&gt;</strong></code></a> element of
162
<code>$CATALINA_BASE/conf/server.xml</code>. You may expose these resources to
162
<code>$CATALINA_BASE/conf/server.xml</code>. You may expose these resources to
163
web applications by using a
163
web applications by using a
164
<a href="config/context.html#Resource Links">&lt;ResourceLink&gt;</a> to
164
<a href="config/context.html#Resource_Links">&lt;ResourceLink&gt;</a> to
165
include it in the per-web-application context.</p>
165
include it in the per-web-application context.</p>
166
166
167
<p>If a resource has been defined using a
167
<p>If a resource has been defined using a
168
<a href="config/context.html#Resource Links">&lt;ResourceLink&gt;</a>, it is not
168
<a href="config/context.html#Resource_Links">&lt;ResourceLink&gt;</a>, it is not
169
necessary for that resource to be defined in <code>/WEB-INF/web.xml</code>.
169
necessary for that resource to be defined in <code>/WEB-INF/web.xml</code>.
170
However, it is recommended to keep the entry in <code>/WEB-INF/web.xml</code>
170
However, it is recommended to keep the entry in <code>/WEB-INF/web.xml</code>
171
to document the resource requirements for the web application.</p>
171
to document the resource requirements for the web application.</p>
Lines 181-188 Link Here
181
access to a resource - in this case, to a JDBC <code>DataSource</code> -
181
access to a resource - in this case, to a JDBC <code>DataSource</code> -
182
would look something like this:</p>
182
would look something like this:</p>
183
183
184
<source>
184
<source><![CDATA[// Obtain our environment naming context
185
// Obtain our environment naming context
186
Context initCtx = new InitialContext();
185
Context initCtx = new InitialContext();
187
Context envCtx = (Context) initCtx.lookup("java:comp/env");
186
Context envCtx = (Context) initCtx.lookup("java:comp/env");
188
187
Lines 193-200 Link Here
193
// Allocate and use a connection from the pool
192
// Allocate and use a connection from the pool
194
Connection conn = ds.getConnection();
193
Connection conn = ds.getConnection();
195
... use this connection to access the database ...
194
... use this connection to access the database ...
196
conn.close();
195
conn.close();]]></source>
197
</source>
198
196
199
</section>
197
</section>
200
198
Lines 208-214 Link Here
208
  subsection below details the configuration and usage of the standard resource
206
  subsection below details the configuration and usage of the standard resource
209
  factories.</p>
207
  factories.</p>
210
208
211
  <p>See <a href="#Adding Custom Resource Factories">Adding Custom
209
  <p>See <a href="#Adding_Custom_Resource_Factories">Adding Custom
212
  Resource Factories</a> for information about how to create, install,
210
  Resource Factories</a> for information about how to create, install,
213
  configure, and use your own custom resource factory classes with
211
  configure, and use your own custom resource factory classes with
214
  Tomcat.</p>
212
  Tomcat.</p>
Lines 223-229 Link Here
223
221
224
  <subsection name="Generic JavaBean Resources">
222
  <subsection name="Generic JavaBean Resources">
225
223
226
    <h3>0.  Introduction</h3>
224
    <h5>0.  Introduction</h5>
227
225
228
    <p>This resource factory can be used to create objects of <em>any</em>
226
    <p>This resource factory can be used to create objects of <em>any</em>
229
    Java class that conforms to standard JavaBeans naming conventions (i.e.
227
    Java class that conforms to standard JavaBeans naming conventions (i.e.
Lines 234-240 Link Here
234
232
235
    <p>The steps required to use this facility are described below.</p>
233
    <p>The steps required to use this facility are described below.</p>
236
234
237
    <h3>1.  Create Your JavaBean Class</h3>
235
    <h5>1.  Create Your JavaBean Class</h5>
238
236
239
    <p>Create the JavaBean class which will be instantiated each time
237
    <p>Create the JavaBean class which will be instantiated each time
240
    that the resource factory is looked up.  For this example, assume
238
    that the resource factory is looked up.  For this example, assume
Lines 241-248 Link Here
241
    you create a class <code>com.mycompany.MyBean</code>, which looks
239
    you create a class <code>com.mycompany.MyBean</code>, which looks
242
    like this:</p>
240
    like this:</p>
243
241
244
<source>
242
<source><![CDATA[package com.mycompany;
245
package com.mycompany;
246
243
247
public class MyBean {
244
public class MyBean {
248
245
Lines 267-276 Link Here
267
  }
264
  }
268
265
269
266
270
}
267
}]]></source>
271
</source>
272
268
273
  <h3>2.  Declare Your Resource Requirements</h3>
269
  <h5>2.  Declare Your Resource Requirements</h5>
274
270
275
  <p>Next, modify your web application deployment descriptor
271
  <p>Next, modify your web application deployment descriptor
276
  (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under which
272
  (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under which
Lines 277-295 Link Here
277
  you will request new instances of this bean.  The simplest approach is
273
  you will request new instances of this bean.  The simplest approach is
278
  to use a <code>&lt;resource-env-ref&gt;</code> element, like this:</p>
274
  to use a <code>&lt;resource-env-ref&gt;</code> element, like this:</p>
279
275
280
<source>
276
<source><![CDATA[<resource-env-ref>
281
&lt;resource-env-ref&gt;
277
  <description>
282
  &lt;description&gt;
283
    Object factory for MyBean instances.
278
    Object factory for MyBean instances.
284
  &lt;/description&gt;
279
  </description>
285
  &lt;resource-env-ref-name&gt;
280
  <resource-env-ref-name>
286
    bean/MyBeanFactory
281
    bean/MyBeanFactory
287
  &lt;/resource-env-ref-name&gt;
282
  </resource-env-ref-name>
288
  &lt;resource-env-ref-type&gt;
283
  <resource-env-ref-type>
289
    com.mycompany.MyBean
284
    com.mycompany.MyBean
290
  &lt;/resource-env-ref-type&gt;
285
  </resource-env-ref-type>
291
&lt;/resource-env-ref&gt;
286
</resource-env-ref>]]></source>
292
</source>
293
287
294
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
288
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
295
    that is required by the DTD for web application deployment descriptors!
289
    that is required by the DTD for web application deployment descriptors!
Lines 297-332 Link Here
297
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
291
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
298
    Specification</a> for details.</p>
292
    Specification</a> for details.</p>
299
293
300
  <h3>3.  Code Your Application's Use Of This Resource</h3>
294
  <h5>3.  Code Your Application's Use Of This Resource</h5>
301
295
302
  <p>A typical use of this resource environment reference might look
296
  <p>A typical use of this resource environment reference might look
303
  like this:</p>
297
  like this:</p>
304
298
305
<source>
299
<source><![CDATA[Context initCtx = new InitialContext();
306
Context initCtx = new InitialContext();
307
Context envCtx = (Context) initCtx.lookup("java:comp/env");
300
Context envCtx = (Context) initCtx.lookup("java:comp/env");
308
MyBean bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
301
MyBean bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
309
302
310
writer.println("foo = " + bean.getFoo() + ", bar = " +
303
writer.println("foo = " + bean.getFoo() + ", bar = " +
311
               bean.getBar());
304
               bean.getBar());]]></source>
312
</source>
313
305
314
    <h3>4.  Configure Tomcat's Resource Factory</h3>
306
    <h5>4.  Configure Tomcat's Resource Factory</h5>
315
307
316
    <p>To configure Tomcat's resource factory, add an element like this to the
308
    <p>To configure Tomcat's resource factory, add an element like this to the
317
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
309
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
318
    this web application.</p>
310
    this web application.</p>
319
311
320
<source>
312
<source><![CDATA[<Context ...>
321
&lt;Context ...&gt;
322
  ...
313
  ...
323
  &lt;Resource name="bean/MyBeanFactory" auth="Container"
314
  <Resource name="bean/MyBeanFactory" auth="Container"
324
            type="com.mycompany.MyBean"
315
            type="com.mycompany.MyBean"
325
            factory="org.apache.naming.factory.BeanFactory"
316
            factory="org.apache.naming.factory.BeanFactory"
326
            bar="23"/&gt;
317
            bar="23"/>
327
  ...
318
  ...
328
&lt;/Context&gt;
319
</Context>]]></source>
329
</source>
330
320
331
    <p>Note that the resource name (here, <code>bean/MyBeanFactory</code>
321
    <p>Note that the resource name (here, <code>bean/MyBeanFactory</code>
332
    must match the value specified in the web application deployment
322
    must match the value specified in the web application deployment
Lines 341-347 Link Here
341
331
342
  <subsection name="UserDatabase Resources">
332
  <subsection name="UserDatabase Resources">
343
333
344
    <h3>0.  Introduction</h3>
334
    <h5>0.  Introduction</h5>
345
335
346
    <p>UserDatabase resources are typically configured as global resources for
336
    <p>UserDatabase resources are typically configured as global resources for
347
    use by a UserDatabase realm. Tomcat includes a UserDatabaseFactoory that
337
    use by a UserDatabase realm. Tomcat includes a UserDatabaseFactoory that
Lines 351-357 Link Here
351
    <p>The steps required to set up a global UserDatabase resource are described
341
    <p>The steps required to set up a global UserDatabase resource are described
352
    below.</p>
342
    below.</p>
353
343
354
    <h3>1. Create/edit the XML file</h3>
344
    <h5>1. Create/edit the XML file</h5>
355
345
356
    <p>The XMl file is typically located at
346
    <p>The XMl file is typically located at
357
    <code>$CATALINA_BASE/conf/tomcat-users.xml</code> however, you are free to
347
    <code>$CATALINA_BASE/conf/tomcat-users.xml</code> however, you are free to
Lines 359-390 Link Here
359
    files are placed in <code>$CATALINA_BASE/conf</code>. A typical XML would
349
    files are placed in <code>$CATALINA_BASE/conf</code>. A typical XML would
360
    look like:</p>
350
    look like:</p>
361
351
362
<source>
352
<source><![CDATA[<?xml version='1.0' encoding='utf-8'?>
363
&lt;?xml version='1.0' encoding='utf-8'?&gt;
353
<tomcat-users>
364
&lt;tomcat-users&gt;
354
  <role rolename="tomcat"/>
365
  &lt;role rolename="tomcat"/&gt;
355
  <role rolename="role1"/>
366
  &lt;role rolename="role1"/&gt;
356
  <user username="tomcat" password="tomcat" roles="tomcat"/>
367
  &lt;user username="tomcat" password="tomcat" roles="tomcat"/&gt;
357
  <user username="both" password="tomcat" roles="tomcat,role1"/>
368
  &lt;user username="both" password="tomcat" roles="tomcat,role1"/&gt;
358
  <user username="role1" password="tomcat" roles="role1"/>
369
  &lt;user username="role1" password="tomcat" roles="role1"/&gt;
359
</tomcat-users>]]></source>
370
&lt;/tomcat-users&gt;
371
</source>
372
360
373
    <h3>2.  Declare Your Resource</h3>
361
    <h5>2.  Declare Your Resource</h5>
374
362
375
    <p>Next, modify <code>$CATALINA_BASE/conf/server.xml</code> to create the
363
    <p>Next, modify <code>$CATALINA_BASE/conf/server.xml</code> to create the
376
    UserDatabase resource based on your XMl file. It should look something like
364
    UserDatabase resource based on your XMl file. It should look something like
377
    this:</p>
365
    this:</p>
378
366
379
<source>
367
<source><![CDATA[<Resource name="UserDatabase"
380
&lt;Resource name="UserDatabase"
381
          auth="Container"
368
          auth="Container"
382
          type="org.apache.catalina.UserDatabase"
369
          type="org.apache.catalina.UserDatabase"
383
          description="User database that can be updated and saved"
370
          description="User database that can be updated and saved"
384
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
371
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
385
          pathname="conf/tomcat-users.xml"
372
          pathname="conf/tomcat-users.xml"
386
          readonly="false" /&gt;
373
          readonly="false" />]]></source>
387
</source>
388
374
389
    <p>The <code>pathname</code> attribute can be absolute or relative. If
375
    <p>The <code>pathname</code> attribute can be absolute or relative. If
390
    relative, it is relative to <code>$CATALINA_BASE</code>.</p>
376
    relative, it is relative to <code>$CATALINA_BASE</code>.</p>
Lines 396-402 Link Here
396
    is running as. Ensure that these are appropriate to maintain the security
382
    is running as. Ensure that these are appropriate to maintain the security
397
    of your installation.</p>
383
    of your installation.</p>
398
384
399
    <h3>3.  Configure the Realm</h3>
385
    <h5>3.  Configure the Realm</h5>
400
386
401
    <p>Configure a UserDatabase Realm to use this resource as described in the
387
    <p>Configure a UserDatabase Realm to use this resource as described in the
402
    <a href="config/realm.html">Realm configuration documentation</a>.</p>
388
    <a href="config/realm.html">Realm configuration documentation</a>.</p>
Lines 406-412 Link Here
406
392
407
  <subsection name="JavaMail Sessions">
393
  <subsection name="JavaMail Sessions">
408
394
409
    <h3>0.  Introduction</h3>
395
    <h5>0.  Introduction</h5>
410
396
411
    <p>In many web applications, sending electronic mail messages is a
397
    <p>In many web applications, sending electronic mail messages is a
412
    required part of the system's functionality.  The
398
    required part of the system's functionality.  The
Lines 424-430 Link Here
424
410
425
    <p>The steps required for this are outlined below.</p>
411
    <p>The steps required for this are outlined below.</p>
426
412
427
    <h3>1.  Declare Your Resource Requirements</h3>
413
    <h5>1.  Declare Your Resource Requirements</h5>
428
414
429
    <p>The first thing you should do is modify the web application deployment
415
    <p>The first thing you should do is modify the web application deployment
430
    descriptor (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under
416
    descriptor (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under
Lines 433-457 Link Here
433
    standard <code>java:comp/env</code> naming context that is the root of
419
    standard <code>java:comp/env</code> naming context that is the root of
434
    all provided resource factories.  A typical <code>web.xml</code> entry
420
    all provided resource factories.  A typical <code>web.xml</code> entry
435
    might look like this:</p>
421
    might look like this:</p>
436
<source>
422
<source><![CDATA[<resource-ref>
437
&lt;resource-ref&gt;
423
  <description>
438
  &lt;description&gt;
439
    Resource reference to a factory for javax.mail.Session
424
    Resource reference to a factory for javax.mail.Session
440
    instances that may be used for sending electronic mail
425
    instances that may be used for sending electronic mail
441
    messages, preconfigured to connect to the appropriate
426
    messages, preconfigured to connect to the appropriate
442
    SMTP server.
427
    SMTP server.
443
  &lt;/description&gt;
428
  </description>
444
  &lt;res-ref-name&gt;
429
  <res-ref-name>
445
    mail/Session
430
    mail/Session
446
  &lt;/res-ref-name&gt;
431
  </res-ref-name>
447
  &lt;res-type&gt;
432
  <res-type>
448
    javax.mail.Session
433
    javax.mail.Session
449
  &lt;/res-type&gt;
434
  </res-type>
450
  &lt;res-auth&gt;
435
  <res-auth>
451
    Container
436
    Container
452
  &lt;/res-auth&gt;
437
  </res-auth>
453
&lt;/resource-ref&gt;
438
</resource-ref>]]></source>
454
</source>
455
439
456
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
440
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
457
    that is required by the DTD for web application deployment descriptors!
441
    that is required by the DTD for web application deployment descriptors!
Lines 459-469 Link Here
459
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
443
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
460
    Specification</a> for details.</p>
444
    Specification</a> for details.</p>
461
445
462
    <h3>2.  Code Your Application's Use Of This Resource</h3>
446
    <h5>2.  Code Your Application's Use Of This Resource</h5>
463
447
464
    <p>A typical use of this resource reference might look like this:</p>
448
    <p>A typical use of this resource reference might look like this:</p>
465
<source>
449
<source><![CDATA[Context initCtx = new InitialContext();
466
Context initCtx = new InitialContext();
467
Context envCtx = (Context) initCtx.lookup("java:comp/env");
450
Context envCtx = (Context) initCtx.lookup("java:comp/env");
468
Session session = (Session) envCtx.lookup("mail/Session");
451
Session session = (Session) envCtx.lookup("mail/Session");
469
452
Lines 474-481 Link Here
474
message.setRecipients(Message.RecipientType.TO, to);
457
message.setRecipients(Message.RecipientType.TO, to);
475
message.setSubject(request.getParameter("subject"));
458
message.setSubject(request.getParameter("subject"));
476
message.setContent(request.getParameter("content"), "text/plain");
459
message.setContent(request.getParameter("content"), "text/plain");
477
Transport.send(message);
460
Transport.send(message);]]></source>
478
</source>
479
461
480
    <p>Note that the application uses the same resource reference name
462
    <p>Note that the application uses the same resource reference name
481
    that was declared in the web application deployment descriptor.  This
463
    that was declared in the web application deployment descriptor.  This
Lines 483-503 Link Here
483
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element
465
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element
484
    for the web application as described below.</p>
466
    for the web application as described below.</p>
485
467
486
    <h3>3.  Configure Tomcat's Resource Factory</h3>
468
    <h5>3.  Configure Tomcat's Resource Factory</h5>
487
469
488
    <p>To configure Tomcat's resource factory, add an elements like this to the
470
    <p>To configure Tomcat's resource factory, add an elements like this to the
489
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
471
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
490
    this web application.</p>
472
    this web application.</p>
491
473
492
<source>
474
<source><![CDATA[<Context ...>
493
&lt;Context ...&gt;
494
  ...
475
  ...
495
  &lt;Resource name="mail/Session" auth="Container"
476
  <Resource name="mail/Session" auth="Container"
496
            type="javax.mail.Session"
477
            type="javax.mail.Session"
497
            mail.smtp.host="localhost"/&gt;
478
            mail.smtp.host="localhost"/>
498
  ...
479
  ...
499
&lt;/Context&gt;
480
</Context>]]></source>
500
</source>
501
481
502
    <p>Note that the resource name (here, <code>mail/Session</code>) must
482
    <p>Note that the resource name (here, <code>mail/Session</code>) must
503
    match the value specified in the web application deployment descriptor.
483
    match the value specified in the web application deployment descriptor.
Lines 517-525 Link Here
517
    then Tomcat&apos;s resource factory will configure and add a
497
    then Tomcat&apos;s resource factory will configure and add a
518
    <code>javax.mail.Authenticator</code> to the mail session.</p>
498
    <code>javax.mail.Authenticator</code> to the mail session.</p>
519
499
520
    <h3>4.  Install the JavaMail libraries</h3>
500
    <h5>4.  Install the JavaMail libraries</h5>
521
501
522
    <p><a href="http://www.oracle.com/technetwork/java/index-138643.html">
502
    <p><a href="http://javamail.java.net/">
523
    Download the JavaMail API</a>.</p>
503
    Download the JavaMail API</a>.</p>
524
504
525
    <p>Unpackage the distribution and place mail.jar  into $CATALINA_HOME/lib so
505
    <p>Unpackage the distribution and place mail.jar  into $CATALINA_HOME/lib so
Lines 529-541 Link Here
529
    it in the $CATALINA_HOME/lib location only.
509
    it in the $CATALINA_HOME/lib location only.
530
    </p>
510
    </p>
531
511
532
    <h3>5.  Restart Tomcat</h3>
512
    <h5>5.  Restart Tomcat</h5>
533
513
534
    <p>For the additional JAR to be visible to Tomcat, it is necessary for the
514
    <p>For the additional JAR to be visible to Tomcat, it is necessary for the
535
    Tomcat instance to be restarted.</p>
515
    Tomcat instance to be restarted.</p>
536
516
537
517
538
    <h3>Example Application</h3>
518
    <h5>Example Application</h5>
539
519
540
    <p>The <code>/examples</code> application included with Tomcat contains
520
    <p>The <code>/examples</code> application included with Tomcat contains
541
    an example of utilizing this resource factory.  It is accessed via the
521
    an example of utilizing this resource factory.  It is accessed via the
Lines 555-561 Link Here
555
535
556
  <subsection name="JDBC Data Sources">
536
  <subsection name="JDBC Data Sources">
557
537
558
    <h3>0.  Introduction</h3>
538
    <h5>0.  Introduction</h5>
559
539
560
    <p>Many web applications need to access a database via a JDBC driver,
540
    <p>Many web applications need to access a database via a JDBC driver,
561
    to support the functionality required by that application.  The Java EE
541
    to support the functionality required by that application.  The Java EE
Lines 586-594 Link Here
586
    project.  However, it is possible to use any other connection pool
566
    project.  However, it is possible to use any other connection pool
587
    that implements <code>javax.sql.DataSource</code>, by writing your
567
    that implements <code>javax.sql.DataSource</code>, by writing your
588
    own custom resource factory, as described
568
    own custom resource factory, as described
589
    <a href="#Adding Custom Resource Factories">below</a>.</p>
569
    <a href="#Adding_Custom_Resource_Factories">below</a>.</p>
590
570
591
    <h3>1.  Install Your JDBC Driver</h3>
571
    <h5>1.  Install Your JDBC Driver</h5>
592
572
593
    <p>Use of the <em>JDBC Data Sources</em> JNDI Resource Factory requires
573
    <p>Use of the <em>JDBC Data Sources</em> JNDI Resource Factory requires
594
    that you make an appropriate JDBC driver available to both Tomcat internal
574
    that you make an appropriate JDBC driver available to both Tomcat internal
Lines 597-603 Link Here
597
    <code>$CATALINA_HOME/lib</code> directory, which makes the driver
577
    <code>$CATALINA_HOME/lib</code> directory, which makes the driver
598
    available both to the resource factory and to your application.</p>
578
    available both to the resource factory and to your application.</p>
599
579
600
    <h3>2.  Declare Your Resource Requirements</h3>
580
    <h5>2.  Declare Your Resource Requirements</h5>
601
581
602
    <p>Next, modify the web application deployment descriptor
582
    <p>Next, modify the web application deployment descriptor
603
    (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under
583
    (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under
Lines 606-630 Link Here
606
    standard <code>java:comp/env</code> naming context that is the root of
586
    standard <code>java:comp/env</code> naming context that is the root of
607
    all provided resource factories.  A typical <code>web.xml</code> entry
587
    all provided resource factories.  A typical <code>web.xml</code> entry
608
    might look like this:</p>
588
    might look like this:</p>
609
<source>
589
<source><![CDATA[<resource-ref>
610
&lt;resource-ref&gt;
590
  <description>
611
  &lt;description&gt;
612
    Resource reference to a factory for java.sql.Connection
591
    Resource reference to a factory for java.sql.Connection
613
    instances that may be used for talking to a particular
592
    instances that may be used for talking to a particular
614
    database that is configured in the &lt;Context&gt;
593
    database that is configured in the <Context>
615
    configurartion for the web application.
594
    configurartion for the web application.
616
  &lt;/description&gt;
595
  </description>
617
  &lt;res-ref-name&gt;
596
  <res-ref-name>
618
    jdbc/EmployeeDB
597
    jdbc/EmployeeDB
619
  &lt;/res-ref-name&gt;
598
  </res-ref-name>
620
  &lt;res-type&gt;
599
  <res-type>
621
    javax.sql.DataSource
600
    javax.sql.DataSource
622
  &lt;/res-type&gt;
601
  </res-type>
623
  &lt;res-auth&gt;
602
  <res-auth>
624
    Container
603
    Container
625
  &lt;/res-auth&gt;
604
  </res-auth>
626
&lt;/resource-ref&gt;
605
</resource-ref>]]></source>
627
</source>
628
606
629
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
607
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
630
    that is required by the DTD for web application deployment descriptors!
608
    that is required by the DTD for web application deployment descriptors!
Lines 632-642 Link Here
632
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
610
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
633
    Specification</a> for details.</p>
611
    Specification</a> for details.</p>
634
612
635
    <h3>3.  Code Your Application's Use Of This Resource</h3>
613
    <h5>3.  Code Your Application's Use Of This Resource</h5>
636
614
637
    <p>A typical use of this resource reference might look like this:</p>
615
    <p>A typical use of this resource reference might look like this:</p>
638
<source>
616
<source><![CDATA[Context initCtx = new InitialContext();
639
Context initCtx = new InitialContext();
640
Context envCtx = (Context) initCtx.lookup("java:comp/env");
617
Context envCtx = (Context) initCtx.lookup("java:comp/env");
641
DataSource ds = (DataSource)
618
DataSource ds = (DataSource)
642
  envCtx.lookup("jdbc/EmployeeDB");
619
  envCtx.lookup("jdbc/EmployeeDB");
Lines 643-650 Link Here
643
620
644
Connection conn = ds.getConnection();
621
Connection conn = ds.getConnection();
645
... use this connection to access the database ...
622
... use this connection to access the database ...
646
conn.close();
623
conn.close();]]></source>
647
</source>
648
624
649
    <p>Note that the application uses the same resource reference name that was
625
    <p>Note that the application uses the same resource reference name that was
650
    declared in the web application deployment descriptor. This is matched up
626
    declared in the web application deployment descriptor. This is matched up
Lines 652-667 Link Here
652
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
628
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
653
    the web application as described below.</p>
629
    the web application as described below.</p>
654
630
655
    <h3>4.  Configure Tomcat's Resource Factory</h3>
631
    <h5>4.  Configure Tomcat's Resource Factory</h5>
656
632
657
    <p>To configure Tomcat's resource factory, add an element like this to the
633
    <p>To configure Tomcat's resource factory, add an element like this to the
658
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
634
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
659
    the web application.</p>
635
    the web application.</p>
660
636
661
<source>
637
<source><![CDATA[<Context ...>
662
&lt;Context ...&gt;
663
  ...
638
  ...
664
  &lt;Resource name="jdbc/EmployeeDB"
639
  <Resource name="jdbc/EmployeeDB"
665
            auth="Container"
640
            auth="Container"
666
            type="javax.sql.DataSource"
641
            type="javax.sql.DataSource"
667
            username="dbusername"
642
            username="dbusername"
Lines 669-678 Link Here
669
            driverClassName="org.hsql.jdbcDriver"
644
            driverClassName="org.hsql.jdbcDriver"
670
            url="jdbc:HypersonicSQL:database"
645
            url="jdbc:HypersonicSQL:database"
671
            maxActive="8"
646
            maxActive="8"
672
            maxIdle="4"/&gt;
647
            maxIdle="4"/>
673
  ...
648
  ...
674
&lt;/Context&gt;
649
</Context>]]></source>
675
</source>
676
650
677
    <p>Note that the resource name (here, <code>jdbc/EmployeeDB</code>) must
651
    <p>Note that the resource name (here, <code>jdbc/EmployeeDB</code>) must
678
    match the value specified in the web application deployment descriptor.</p>
652
    match the value specified in the web application deployment descriptor.</p>
Lines 807-816 Link Here
807
  <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
781
  <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
808
  the web application. In the example below, we will create a factory that only
782
  the web application. In the example below, we will create a factory that only
809
  knows how to create <code>com.mycompany.MyBean</code> beans from the
783
  knows how to create <code>com.mycompany.MyBean</code> beans from the
810
  <a href="#Generic JavaBean Resources">Generic JavaBean Resources</a> example
784
  <a href="#Generic_JavaBean_Resources">Generic JavaBean Resources</a> example
811
  above.</p>
785
  above.</p>
812
786
813
  <h3>1.  Write A Resource Factory Class</h3>
787
  <h4>1.  Write A Resource Factory Class</h4>
814
788
815
  <p>You must write a class that implements the JNDI service provider
789
  <p>You must write a class that implements the JNDI service provider
816
  <code>javax.naming.spi.ObjectFactory</code> inteface.  Every time your
790
  <code>javax.naming.spi.ObjectFactory</code> inteface.  Every time your
Lines 839-846 Link Here
839
  <p>To create a resource factory that knows how to produce <code>MyBean</code>
813
  <p>To create a resource factory that knows how to produce <code>MyBean</code>
840
  instances, you might create a class like this:</p>
814
  instances, you might create a class like this:</p>
841
815
842
<source>
816
<source><![CDATA[package com.mycompany;
843
package com.mycompany;
844
817
845
import java.util.Enumeration;
818
import java.util.Enumeration;
846
import java.util.Hashtable;
819
import java.util.Hashtable;
Lines 883-890 Link Here
883
856
884
  }
857
  }
885
858
886
}
859
}]]></source>
887
</source>
888
860
889
  <p>In this example, we are unconditionally creating a new instance of
861
  <p>In this example, we are unconditionally creating a new instance of
890
  the <code>com.mycompany.MyBean</code> class, and populating its properties
862
  the <code>com.mycompany.MyBean</code> class, and populating its properties
Lines 907-913 Link Here
907
  files are visible to both Catalina internal resources and your web
879
  files are visible to both Catalina internal resources and your web
908
  application.</p>
880
  application.</p>
909
881
910
  <h3>2.  Declare Your Resource Requirements</h3>
882
  <h4>2.  Declare Your Resource Requirements</h4>
911
883
912
  <p>Next, modify your web application deployment descriptor
884
  <p>Next, modify your web application deployment descriptor
913
  (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under which
885
  (<code>/WEB-INF/web.xml</code>) to declare the JNDI name under which
Lines 914-932 Link Here
914
  you will request new instances of this bean.  The simplest approach is
886
  you will request new instances of this bean.  The simplest approach is
915
  to use a <code>&lt;resource-env-ref&gt;</code> element, like this:</p>
887
  to use a <code>&lt;resource-env-ref&gt;</code> element, like this:</p>
916
888
917
<source>
889
<source><![CDATA[<resource-env-ref>
918
&lt;resource-env-ref&gt;
890
  <description>
919
  &lt;description&gt;
920
    Object factory for MyBean instances.
891
    Object factory for MyBean instances.
921
  &lt;/description&gt;
892
  </description>
922
  &lt;resource-env-ref-name&gt;
893
  <resource-env-ref-name>
923
    bean/MyBeanFactory
894
    bean/MyBeanFactory
924
  &lt;/resource-env-ref-name&gt;
895
  </resource-env-ref-name>
925
  &lt;resource-env-ref-type&gt;
896
  <resource-env-ref-type>
926
    com.mycompany.MyBean
897
    com.mycompany.MyBean
927
  &lt;/resource-env-ref-type&gt;
898
  </resource-env-ref-type>
928
&lt;resource-env-ref&gt;
899
<resource-env-ref>]]></source>
929
</source>
930
900
931
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
901
    <p><strong>WARNING</strong> - Be sure you respect the element ordering
932
    that is required by the DTD for web application deployment descriptors!
902
    that is required by the DTD for web application deployment descriptors!
Lines 934-969 Link Here
934
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
904
    <a href="http://wiki.apache.org/tomcat/Specifications">Servlet
935
    Specification</a> for details.</p>
905
    Specification</a> for details.</p>
936
906
937
  <h3>3.  Code Your Application's Use Of This Resource</h3>
907
  <h4>3.  Code Your Application's Use Of This Resource</h4>
938
908
939
  <p>A typical use of this resource environment reference might look
909
  <p>A typical use of this resource environment reference might look
940
  like this:</p>
910
  like this:</p>
941
911
942
<source>
912
<source><![CDATA[Context initCtx = new InitialContext();
943
Context initCtx = new InitialContext();
944
Context envCtx = (Context) initCtx.lookup("java:comp/env");
913
Context envCtx = (Context) initCtx.lookup("java:comp/env");
945
MyBean bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
914
MyBean bean = (MyBean) envCtx.lookup("bean/MyBeanFactory");
946
915
947
writer.println("foo = " + bean.getFoo() + ", bar = " +
916
writer.println("foo = " + bean.getFoo() + ", bar = " +
948
               bean.getBar());
917
               bean.getBar());]]></source>
949
</source>
950
918
951
    <h3>4.  Configure Tomcat's Resource Factory</h3>
919
    <h4>4.  Configure Tomcat's Resource Factory</h4>
952
920
953
    <p>To configure Tomcat's resource factory, add an elements like this to the
921
    <p>To configure Tomcat's resource factory, add an elements like this to the
954
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
922
    <a href="config/context.html"><code>&lt;Context&gt;</code></a> element for
955
    this web application.</p>
923
    this web application.</p>
956
924
957
<source>
925
<source><![CDATA[<Context ...>
958
&lt;Context ...&gt;
959
  ...
926
  ...
960
  &lt;Resource name="bean/MyBeanFactory" auth="Container"
927
  <Resource name="bean/MyBeanFactory" auth="Container"
961
            type="com.mycompany.MyBean"
928
            type="com.mycompany.MyBean"
962
            factory="com.mycompany.MyBeanFactory"
929
            factory="com.mycompany.MyBeanFactory"
963
            bar="23"/&gt;
930
            bar="23"/>
964
  ...
931
  ...
965
&lt;/Context&gt;
932
</Context>]]></source>
966
</source>
967
933
968
    <p>Note that the resource name (here, <code>bean/MyBeanFactory</code>
934
    <p>Note that the resource name (here, <code>bean/MyBeanFactory</code>
969
    must match the value specified in the web application deployment
935
    must match the value specified in the web application deployment
(-)webapps/docs/logging.xml (-22 / +14 lines)
Lines 222-227 Link Here
222
    JULI is enabled by default, and supports per classloader configuration, in
222
    JULI is enabled by default, and supports per classloader configuration, in
223
    addition to the regular global java.util.logging configuration. This means
223
    addition to the regular global java.util.logging configuration. This means
224
    that logging can be configured at the following layers:
224
    that logging can be configured at the following layers:
225
  </p>
225
    <ul>
226
    <ul>
226
      <li>Globally. That is usually done in the
227
      <li>Globally. That is usually done in the
227
        <code>${catalina.base}/conf/logging.properties</code> file.
228
        <code>${catalina.base}/conf/logging.properties</code> file.
Lines 234-240 Link Here
234
        <code>WEB-INF/classes/logging.properties</code>
235
        <code>WEB-INF/classes/logging.properties</code>
235
      </li>
236
      </li>
236
    </ul>
237
    </ul>
237
  </p>
238
  <p>
238
  <p>
239
    The default <code>logging.properties</code> in the JRE specifies a
239
    The default <code>logging.properties</code> in the JRE specifies a
240
    <code>ConsoleHandler</code> that routes logging to System.err.
240
    <code>ConsoleHandler</code> that routes logging to System.err.
Lines 253-262 Link Here
253
    so FINEST or ALL should be set. Please refer to <code>java.util.logging</code>
253
    so FINEST or ALL should be set. Please refer to <code>java.util.logging</code>
254
    documentation in the JDK for the complete details:
254
    documentation in the JDK for the complete details:
255
  </p>
255
  </p>
256
  <source>org.apache.catalina.level=FINEST</source>
256
  <p>
257
  <p>
257
    <source>org.apache.catalina.level=FINEST</source>
258
  </p>
259
  <p>
260
    The configuration used by JULI is extremely similar to the one supported by
258
    The configuration used by JULI is extremely similar to the one supported by
261
    plain <code>java.util.logging</code>, but uses a few
259
    plain <code>java.util.logging</code>, but uses a few
262
    extensions to allow better flexibility in assigning loggers. The main
260
    extensions to allow better flexibility in assigning loggers. The main
Lines 295-302 Link Here
295
  </p>
293
  </p>
296
  <p>
294
  <p>
297
    Example logging.properties file to be placed in $CATALINA_BASE/conf:
295
    Example logging.properties file to be placed in $CATALINA_BASE/conf:
298
    <source>
296
  </p>
299
handlers = 1catalina.org.apache.juli.FileHandler, \
297
  <source><![CDATA[handlers = 1catalina.org.apache.juli.FileHandler, \
300
           2localhost.org.apache.juli.FileHandler, \
298
           2localhost.org.apache.juli.FileHandler, \
301
           3manager.org.apache.juli.FileHandler, \
299
           3manager.org.apache.juli.FileHandler, \
302
           java.util.logging.ConsoleHandler
300
           java.util.logging.ConsoleHandler
Lines 340-354 Link Here
340
338
341
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
339
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
342
# each component that extends LifecycleBase changing state:
340
# each component that extends LifecycleBase changing state:
343
#org.apache.catalina.util.LifecycleBase.level = FINE
341
#org.apache.catalina.util.LifecycleBase.level = FINE]]></source>
344
</source>
345
    </p>
346
342
347
    <p>
343
    <p>
348
      Example logging.properties for the servlet-examples web application to be
344
      Example logging.properties for the servlet-examples web application to be
349
      placed in WEB-INF/classes inside the web application:
345
      placed in WEB-INF/classes inside the web application:
350
      <source>
346
    </p>
351
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
347
    <source><![CDATA[handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
352
348
353
############################################################
349
############################################################
354
# Handler specific properties.
350
# Handler specific properties.
Lines 360-369 Link Here
360
org.apache.juli.FileHandler.prefix = servlet-examples.
356
org.apache.juli.FileHandler.prefix = servlet-examples.
361
357
362
java.util.logging.ConsoleHandler.level = FINE
358
java.util.logging.ConsoleHandler.level = FINE
363
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
359
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter]]></source>
364
</source>
365
    </p>
366
360
361
367
    <subsection name="Documentation references">
362
    <subsection name="Documentation references">
368
      <p>See the following resources for additional information:</p>
363
      <p>See the following resources for additional information:</p>
369
      <ul>
364
      <ul>
Lines 423-429 Link Here
423
        <li>Create a file called <code>log4j.properties</code> with the
418
        <li>Create a file called <code>log4j.properties</code> with the
424
        following content and save it into <code>$CATALINA_BASE/lib</code></li>
419
        following content and save it into <code>$CATALINA_BASE/lib</code></li>
425
    </ol>
420
    </ol>
426
    <source>
421
    <source><![CDATA[
427
log4j.rootLogger = INFO, CATALINA
422
log4j.rootLogger = INFO, CATALINA
428
423
429
# Define all the appenders
424
# Define all the appenders
Lines 470-477 Link Here
470
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
465
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
471
  INFO, MANAGER
466
  INFO, MANAGER
472
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
467
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
473
  INFO, HOST-MANAGER
468
  INFO, HOST-MANAGER]]></source>
474
</source>
475
    <ol start="2">
469
    <ol start="2">
476
        <li><a href="http://logging.apache.org/log4j">Download Log4J</a>
470
        <li><a href="http://logging.apache.org/log4j">Download Log4J</a>
477
        (v1.2 or later).</li>
471
        (v1.2 or later).</li>
Lines 546-556 Link Here
546
      configuration files, so we recommend you use a properties file as
540
      configuration files, so we recommend you use a properties file as
547
      described until a future version of log4j allows this convention.
541
      described until a future version of log4j allows this convention.
548
    </p>
542
    </p>
549
      <source>
543
      <source><![CDATA[log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG
550
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG<br />
544
log4j.logger.org.apache.catalina.core=DEBUG
551
log4j.logger.org.apache.catalina.core=DEBUG<br />
545
log4j.logger.org.apache.catalina.session=DEBUG]]></source>
552
log4j.logger.org.apache.catalina.session=DEBUG<br />
553
</source>
554
546
555
    <p>
547
    <p>
556
      Be warned: a level of DEBUG will produce megabytes of logging and slow
548
      Be warned: a level of DEBUG will produce megabytes of logging and slow
(-)webapps/docs/manager-howto.xml (-374 / +252 lines)
Lines 70-82 Link Here
70
<code>manager.xml</code> context configuration file in the
70
<code>manager.xml</code> context configuration file in the
71
<code>$CATALINA_BASE/conf/[enginename]/[hostname]</code> folder. Here is an
71
<code>$CATALINA_BASE/conf/[enginename]/[hostname]</code> folder. Here is an
72
example:</p>
72
example:</p>
73
<pre>
73
<source><![CDATA[<Context privileged="true" antiResourceLocking="false"
74
&lt;Context privileged="true" antiResourceLocking="false"
74
         docBase="${catalina.home}/webapps/manager">
75
         docBase="${catalina.home}/webapps/manager"&gt;
75
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
76
  &lt;Valve className="org.apache.catalina.valves.RemoteAddrValve"
76
         allow="127\.0\.0\.1" />
77
         allow="127\.0\.0\.1" /&gt;
77
</Context>]]></source>
78
&lt;/Context&gt;
79
</pre>
80
78
81
<p>If you have Tomcat configured to support multiple virtual hosts
79
<p>If you have Tomcat configured to support multiple virtual hosts
82
(websites) you would need to configure a Manager for each.</p>
80
(websites) you would need to configure a Manager for each.</p>
Lines 89-99 Link Here
89
<li>A minimal version using HTTP requests only which is suitable for use
87
<li>A minimal version using HTTP requests only which is suitable for use
90
by scripts setup by system administrators.  Commands are given as part of the
88
by scripts setup by system administrators.  Commands are given as part of the
91
request URI, and responses are in the form of simple text that can be easily
89
request URI, and responses are in the form of simple text that can be easily
92
parsed and processed.  See <a href="#Supported Manager Commands">
90
parsed and processed.  See <a href="#Supported_Manager_Commands">
93
Supported Manager Commands</a> for more information.</li>
91
Supported Manager Commands</a> for more information.</li>
94
<li>A convenient set of task definitions for the <em>Ant</em>
92
<li>A convenient set of task definitions for the <em>Ant</em>
95
(version 1.4 or later) build tool.  See
93
(version 1.4 or later) build tool.  See
96
<a href="#Executing Manager Commands With Ant">Executing Manager Commands
94
<a href="#Executing_Manager_Commands_With_Ant">Executing Manager Commands
97
With Ant</a> for more information.</li>
95
With Ant</a> for more information.</li>
98
</ul>
96
</ul>
99
97
Lines 101-113 Link Here
101
99
102
<section name="Configuring Manager Application Access">
100
<section name="Configuring Manager Application Access">
103
101
104
    <blockquote>
102
    
105
    <p><em>The description below uses the variable name $CATALINA_BASE to refer the
103
    <p><em>The description below uses the variable name $CATALINA_BASE to refer the
106
    base directory against which most relative paths are resolved. If you have
104
    base directory against which most relative paths are resolved. If you have
107
    not configured Tomcat for multiple instances by setting a CATALINA_BASE
105
    not configured Tomcat for multiple instances by setting a CATALINA_BASE
108
    directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME,
106
    directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME,
109
    the directory into which you have installed Tomcat.</em></p>
107
    the directory into which you have installed Tomcat.</em></p>
110
    </blockquote>
108
    
111
109
112
<p>It would be quite unsafe to ship Tomcat with default settings that allowed
110
<p>It would be quite unsafe to ship Tomcat with default settings that allowed
113
anyone on the Internet to execute the Manager application on your server.
111
anyone on the Internet to execute the Manager application on your server.
Lines 175-183 Link Here
175
    edited with any text editor.  This file contains an XML
173
    edited with any text editor.  This file contains an XML
176
    <code>&lt;user&gt;</code> for each individual user, which might
174
    <code>&lt;user&gt;</code> for each individual user, which might
177
    look something like this:
175
    look something like this:
178
<source>
176
<source><![CDATA[<user name="craigmcc" password="secret" roles="standard,manager-script" />]]></source>
179
&lt;user name="craigmcc" password="secret" roles="standard,manager-script" /&gt;
180
</source>
181
    which defines the username and password used by this individual to
177
    which defines the username and password used by this individual to
182
    log on, and the role names he or she is associated with.  You can
178
    log on, and the role names he or she is associated with.  You can
183
    add the <strong>manager-script</strong> role to the comma-delimited
179
    add the <strong>manager-script</strong> role to the comma-delimited
Lines 207-218 Link Here
207
See <a href="config/valve.html#Remote_Address_Filter">valves documentation</a>
203
See <a href="config/valve.html#Remote_Address_Filter">valves documentation</a>
208
for details. Here is
204
for details. Here is
209
an example of restricting access to the localhost by IP address:</p>
205
an example of restricting access to the localhost by IP address:</p>
210
<pre>
206
<source><![CDATA[<Context privileged="true">
211
&lt;Context privileged="true"&gt;
207
         <Valve className="org.apache.catalina.valves.RemoteAddrValve"
212
         &lt;Valve className="org.apache.catalina.valves.RemoteAddrValve"
208
                allow="127\.0\.0\.1"/>
213
                allow="127\.0\.0\.1"/&gt;
209
</Context>]]></source>
214
&lt;/Context&gt;
215
</pre>
216
210
217
</section>
211
</section>
218
212
Lines 221-229 Link Here
221
215
222
<p>All commands that the Manager application knows how to process are
216
<p>All commands that the Manager application knows how to process are
223
specified in a single request URI like this:</p>
217
specified in a single request URI like this:</p>
224
<source>
218
<source>http://{host}:{port}/manager/text/{command}?{parameters}</source>
225
http://{host}:{port}/manager/text/{command}?{parameters}
226
</source>
227
<p>where <code>{host}</code> and <code>{port}</code> represent the hostname
219
<p>where <code>{host}</code> and <code>{port}</code> represent the hostname
228
and port number on which Tomcat is running, <code>{command}</code>
220
and port number on which Tomcat is running, <code>{command}</code>
229
represents the Manager command you wish to execute, and
221
represents the Manager command you wish to execute, and
Lines 282-290 Link Here
282
274
283
<subsection name="Deploy A New Application Remotely">
275
<subsection name="Deploy A New Application Remotely">
284
276
285
<source>
277
<source>http://localhost:8080/manager/text/deploy?path=/foo</source>
286
http://localhost:8080/manager/text/deploy?path=/foo
287
</source>
288
278
289
<p>Upload the web application archive (WAR) file that is specified as the
279
<p>Upload the web application archive (WAR) file that is specified as the
290
request data in this HTTP PUT request, install it into the <code>appBase</code>
280
request data in this HTTP PUT request, install it into the <code>appBase</code>
Lines 311-325 Link Here
311
301
312
<p>If installation and startup is successful, you will receive a response
302
<p>If installation and startup is successful, you will receive a response
313
like this:</p>
303
like this:</p>
314
<source>
304
<source>OK - Deployed application at context path /foo</source>
315
OK - Deployed application at context path /foo
316
</source>
317
305
318
<p>Otherwise, the response will start with <code>FAIL</code> and include an
306
<p>Otherwise, the response will start with <code>FAIL</code> and include an
319
error message.  Possible causes for problems include:</p>
307
error message.  Possible causes for problems include:</p>
320
<ul>
308
<ul>
321
<li><em>Application already exists at path /foo</em>
309
<li><em>Application already exists at path /foo</em>
322
    <blockquote>
323
    <p>The context paths for all currently running web applications must be
310
    <p>The context paths for all currently running web applications must be
324
    unique.  Therefore, you must undeploy the existing web
311
    unique.  Therefore, you must undeploy the existing web
325
    application using this context path, or choose a different context path
312
    application using this context path, or choose a different context path
Lines 327-341 Link Here
327
    a parameter on the URL, with a value of <code>true</code> to avoid this
314
    a parameter on the URL, with a value of <code>true</code> to avoid this
328
    error. In that case, an undeploy will be performed on an existing
315
    error. In that case, an undeploy will be performed on an existing
329
    application before performing the deployment.</p>
316
    application before performing the deployment.</p>
330
    </blockquote></li>
317
    </li>
331
<li><em>Encountered exception</em>
318
<li><em>Encountered exception</em>
332
    <blockquote>
333
    <p>An exception was encountered trying to start the new web application.
319
    <p>An exception was encountered trying to start the new web application.
334
    Check the Tomcat logs for the details, but likely explanations include
320
    Check the Tomcat logs for the details, but likely explanations include
335
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
321
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
336
    classes encountered when initializing application event listeners and
322
    classes encountered when initializing application event listeners and
337
    filters.</p>
323
    filters.</p>
338
    </blockquote></li>
324
    </li>
339
</ul>
325
</ul>
340
326
341
</subsection>
327
</subsection>
Lines 348-365 Link Here
348
334
349
<p>There are a number of different ways the deploy command can be used.</p>
335
<p>There are a number of different ways the deploy command can be used.</p>
350
336
351
<h3>Deploy a previously deployed webapp</h3>
337
<h5>Deploy a previously deployed webapp</h5>
352
338
353
<p>This can be used to deploy a previously deployed web application, which
339
<p>This can be used to deploy a previously deployed web application, which
354
has been deployed using the <code>tag</code> attribute. Note that the work
340
has been deployed using the <code>tag</code> attribute. Note that the work
355
directory for the Manager webapp will contain the previously deployed WARs;
341
directory for the Manager webapp will contain the previously deployed WARs;
356
removing it would make the deployment fail.</p>
342
removing it would make the deployment fail.</p>
357
<source>
343
<source>http://localhost:8080/manager/text/deploy?path=/footoo&amp;tag=footag</source>
358
http://localhost:8080/manager/text/deploy?path=/footoo&amp;tag=footag
359
</source>
360
344
361
345
362
<h3>Deploy a Directory or WAR by URL</h3>
346
<h5>Deploy a Directory or WAR by URL</h5>
363
347
364
<p>Deploy a web application directory or ".war" file located on the Tomcat
348
<p>Deploy a web application directory or ".war" file located on the Tomcat
365
server. If no <code>path</code> is specified, the directory name or the war file
349
server. If no <code>path</code> is specified, the directory name or the war file
Lines 373-381 Link Here
373
<p>In this example the web application located in the directory
357
<p>In this example the web application located in the directory
374
<code>/path/to/foo</code> on the Tomcat server is deployed as the
358
<code>/path/to/foo</code> on the Tomcat server is deployed as the
375
web application context named <code>/footoo</code>.</p>
359
web application context named <code>/footoo</code>.</p>
376
<source>
360
<source>http://localhost:8080/manager/text/deploy?path=/footoo&amp;war=file:/path/to/foo</source>
377
http://localhost:8080/manager/text/deploy?path=/footoo&amp;war=file:/path/to/foo
378
</source>
379
361
380
362
381
<p>In this example the ".war" file <code>/path/to/bar.war</code> on the
363
<p>In this example the ".war" file <code>/path/to/bar.war</code> on the
Lines 383-394 Link Here
383
<code>/bar</code>. Notice that there is no <code>path</code> parameter
365
<code>/bar</code>. Notice that there is no <code>path</code> parameter
384
so the context path defaults to the name of the web application archive
366
so the context path defaults to the name of the web application archive
385
file without the ".war" extension.</p>
367
file without the ".war" extension.</p>
386
<source>
368
<source>http://localhost:8080/manager/text/deploy?war=jar:file:/path/to/bar.war!/</source>
387
http://localhost:8080/manager/text/deploy?war=jar:file:/path/to/bar.war!/
388
</source>
389
369
390
370
391
<h3>Deploy a Directory or War from the Host appBase</h3>
371
<h5>Deploy a Directory or War from the Host appBase</h5>
392
372
393
<p>Deploy a web application directory or ".war" file located in your Host
373
<p>Deploy a web application directory or ".war" file located in your Host
394
appBase directory. The directory name or the war file name without the ".war"
374
appBase directory. The directory name or the war file name without the ".war"
Lines 398-417 Link Here
398
<code>foo</code> in the Host appBase directory of the Tomcat server is
378
<code>foo</code> in the Host appBase directory of the Tomcat server is
399
deployed as the web application context named <code>/foo</code>. Notice
379
deployed as the web application context named <code>/foo</code>. Notice
400
that the context path used is the name of the web application directory.</p>
380
that the context path used is the name of the web application directory.</p>
401
<source>
381
<source>http://localhost:8080/manager/text/deploy?war=foo</source>
402
http://localhost:8080/manager/text/deploy?war=foo
403
</source>
404
382
405
383
406
<p>In this example the ".war" file <code>bar.war</code> located in your
384
<p>In this example the ".war" file <code>bar.war</code> located in your
407
Host appBase directory on the Tomcat server is deployed as the web
385
Host appBase directory on the Tomcat server is deployed as the web
408
application context named <code>/bar</code>.</p>
386
application context named <code>/bar</code>.</p>
409
<source>
387
<source>http://localhost:8080/manager/text/deploy?war=bar.war</source>
410
http://localhost:8080/manager/text/deploy?war=bar.war
411
</source>
412
388
413
389
414
<h3>Deploy using a Context configuration ".xml" file</h3>
390
<h5>Deploy using a Context configuration ".xml" file</h5>
415
391
416
<p>If the Host deployXML flag is set to true you can deploy a web
392
<p>If the Host deployXML flag is set to true you can deploy a web
417
application using a Context configuration ".xml" file and an optional
393
application using a Context configuration ".xml" file and an optional
Lines 423-432 Link Here
423
web application Context just as if it were configured in your
399
web application Context just as if it were configured in your
424
Tomcat <code>server.xml</code> configuration file. Here is an
400
Tomcat <code>server.xml</code> configuration file. Here is an
425
example:</p>
401
example:</p>
426
<source>
402
<source><![CDATA[<Context path="/foobar" docBase="/path/to/application/foobar">
427
&lt;Context path="/foobar" docBase="/path/to/application/foobar"&gt;
403
</Context>]]></source>
428
&lt;/Context&gt;
429
</source>
430
404
431
405
432
<p>When the optional <code>war</code> parameter is set to the URL
406
<p>When the optional <code>war</code> parameter is set to the URL
Lines 435-455 Link Here
435
409
436
<p>Here is an example of deploying an application using a Context
410
<p>Here is an example of deploying an application using a Context
437
configuration ".xml" file.</p>
411
configuration ".xml" file.</p>
438
<source>
412
<source>http://localhost:8080/manager/text/deploy?config=file:/path/context.xml</source>
439
http://localhost:8080/manager/text/deploy?config=file:/path/context.xml
440
</source>
441
413
442
414
443
<p>Here is an example of deploying an application using a Context
415
<p>Here is an example of deploying an application using a Context
444
configuration ".xml" file and a web application ".war" file located
416
configuration ".xml" file and a web application ".war" file located
445
on the server.</p>
417
on the server.</p>
446
<source>
418
<source>http://localhost:8080/manager/text/deploy
447
http://localhost:8080/manager/text/deploy
419
 ?config=file:/path/context.xml&amp;war=jar:file:/path/bar.war!/</source>
448
 ?config=file:/path/context.xml&amp;war=jar:file:/path/bar.war!/
449
</source>
450
420
451
421
452
<h3>Deployment Notes</h3>
422
<h5>Deployment Notes</h5>
453
423
454
<p>If the Host is configured with unpackWARs=true and you deploy a war
424
<p>If the Host is configured with unpackWARs=true and you deploy a war
455
file, the war will be unpacked into a directory in your Host appBase
425
file, the war will be unpacked into a directory in your Host appBase
Lines 467-485 Link Here
467
files located outside of their Host appBase.</p>
437
files located outside of their Host appBase.</p>
468
438
469
439
470
<h3>Deploy Response</h3>
440
<h5>Deploy Response</h5>
471
441
472
<p>If installation and startup is successful, you will receive a response
442
<p>If installation and startup is successful, you will receive a response
473
like this:</p>
443
like this:</p>
474
<source>
444
<source>OK - Deployed application at context path /foo</source>
475
OK - Deployed application at context path /foo
476
</source>
477
445
478
<p>Otherwise, the response will start with <code>FAIL</code> and include an
446
<p>Otherwise, the response will start with <code>FAIL</code> and include an
479
error message.  Possible causes for problems include:</p>
447
error message.  Possible causes for problems include:</p>
480
<ul>
448
<ul>
481
<li><em>Application already exists at path /foo</em>
449
<li><em>Application already exists at path /foo</em>
482
    <blockquote>
483
    <p>The context paths for all currently running web applications must be
450
    <p>The context paths for all currently running web applications must be
484
    unique.  Therefore, you must undeploy the existing web
451
    unique.  Therefore, you must undeploy the existing web
485
    application using this context path, or choose a different context path
452
    application using this context path, or choose a different context path
Lines 487-534 Link Here
487
    a parameter on the URL, with a value of <code>true</code> to avoid this
454
    a parameter on the URL, with a value of <code>true</code> to avoid this
488
    error. In that case, an undeploy will be performed on an existing
455
    error. In that case, an undeploy will be performed on an existing
489
    application before performing the deployment.</p>
456
    application before performing the deployment.</p>
490
    </blockquote></li>
457
    </li>
491
<li><em>Document base does not exist or is not a readable directory</em>
458
<li><em>Document base does not exist or is not a readable directory</em>
492
    <blockquote>
493
    <p>The URL specified by the <code>war</code> parameter must identify a
459
    <p>The URL specified by the <code>war</code> parameter must identify a
494
    directory on this server that contains the "unpacked" version of a
460
    directory on this server that contains the "unpacked" version of a
495
    web application, or the absolute URL of a web application archive (WAR)
461
    web application, or the absolute URL of a web application archive (WAR)
496
    file that contains this application.  Correct the value specified by
462
    file that contains this application.  Correct the value specified by
497
    the <code>war</code> parameter.</p>
463
    the <code>war</code> parameter.</p>
498
    </blockquote></li>
464
    </li>
499
<li><em>Encountered exception</em>
465
<li><em>Encountered exception</em>
500
    <blockquote>
501
    <p>An exception was encountered trying to start the new web application.
466
    <p>An exception was encountered trying to start the new web application.
502
    Check the Tomcat logs for the details, but likely explanations include
467
    Check the Tomcat logs for the details, but likely explanations include
503
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
468
    problems parsing your <code>/WEB-INF/web.xml</code> file, or missing
504
    classes encountered when initializing application event listeners and
469
    classes encountered when initializing application event listeners and
505
    filters.</p>
470
    filters.</p>
506
    </blockquote></li>
471
    </li>
507
<li><em>Invalid application URL was specified</em>
472
<li><em>Invalid application URL was specified</em>
508
    <blockquote>
509
    <p>The URL for the directory or web application that you specified
473
    <p>The URL for the directory or web application that you specified
510
    was not valid.  Such URLs must start with <code>file:</code>, and URLs
474
    was not valid.  Such URLs must start with <code>file:</code>, and URLs
511
    for a WAR file must end in ".war".</p>
475
    for a WAR file must end in ".war".</p>
512
    </blockquote></li>
476
    </li>
513
<li><em>Invalid context path was specified</em>
477
<li><em>Invalid context path was specified</em>
514
    <blockquote>
515
    <p>The context path must start with a slash character. To reference the
478
    <p>The context path must start with a slash character. To reference the
516
    ROOT web application use "/".</p>
479
    ROOT web application use "/".</p>
517
    </blockquote></li>
480
    </li>
518
<li><em>Context path must match the directory or WAR file name:</em>
481
<li><em>Context path must match the directory or WAR file name:</em>
519
    <blockquote>
482
    <p>If the application war or directory is installed in your Host appBase
520
    If the application war or directory is installed in your Host appBase
521
    directory and either the Host is configured with autoDeploy=true the
483
    directory and either the Host is configured with autoDeploy=true the
522
    Context path must match the directory name or war file name without
484
    Context path must match the directory name or war file name without
523
    the ".war" extension.
485
    the ".war" extension.</p>
524
    </blockquote></li>
486
    </li>
525
<li><em>Only web applications in the Host web application directory can
487
<li><em>Only web applications in the Host web application directory can
526
     be installed</em>
488
     be installed</em>
527
     <blockquote>
489
     <p>
528
     If the Host deployXML flag is set to false this error will happen
490
     If the Host deployXML flag is set to false this error will happen
529
     if an attempt is made to deploy a web application directory or
491
     if an attempt is made to deploy a web application directory or
530
      ".war" file outside of the Host appBase directory.
492
      ".war" file outside of the Host appBase directory.
531
     </blockquote></li>
493
     </p></li>
532
</ul>
494
</ul>
533
495
534
</subsection>
496
</subsection>
Lines 535-563 Link Here
535
497
536
<subsection name="List Currently Deployed Applications">
498
<subsection name="List Currently Deployed Applications">
537
499
538
<source>
500
<source>http://localhost:8080/manager/text/list</source>
539
http://localhost:8080/manager/text/list
540
</source>
541
501
542
<p>List the context paths, current status (<code>running</code> or
502
<p>List the context paths, current status (<code>running</code> or
543
<code>stopped</code>), and number of active sessions for all currently
503
<code>stopped</code>), and number of active sessions for all currently
544
deployed web applications.  A typical response immediately
504
deployed web applications.  A typical response immediately
545
after starting Tomcat might look like this:</p>
505
after starting Tomcat might look like this:</p>
546
<source>
506
<source>OK - Listed applications for virtual host localhost
547
OK - Listed applications for virtual host localhost
548
/webdav:running:0
507
/webdav:running:0
549
/examples:running:0
508
/examples:running:0
550
/manager:running:0
509
/manager:running:0
551
/:running:0
510
/:running:0</source>
552
</source>
553
511
554
</subsection>
512
</subsection>
555
513
556
<subsection name="Reload An Existing Application">
514
<subsection name="Reload An Existing Application">
557
515
558
<source>
516
<source>http://localhost:8080/manager/text/reload?path=/examples</source>
559
http://localhost:8080/manager/text/reload?path=/examples
560
</source>
561
517
562
<p>Signal an existing application to shut itself down and reload.  This can
518
<p>Signal an existing application to shut itself down and reload.  This can
563
be useful when the web application context is not reloadable and you have
519
be useful when the web application context is not reloadable and you have
Lines 572-605 Link Here
572
</p>
528
</p>
573
529
574
<p>If this command succeeds, you will see a response like this:</p>
530
<p>If this command succeeds, you will see a response like this:</p>
575
<source>
531
<source>OK - Reloaded application at context path /examples</source>
576
OK - Reloaded application at context path /examples
577
</source>
578
532
579
<p>Otherwise, the response will start with <code>FAIL</code> and include an
533
<p>Otherwise, the response will start with <code>FAIL</code> and include an
580
error message.  Possible causes for problems include:</p>
534
error message.  Possible causes for problems include:</p>
581
<ul>
535
<ul>
582
<li><em>Encountered exception</em>
536
<li><em>Encountered exception</em>
583
    <blockquote>
584
    <p>An exception was encountered trying to restart the web application.
537
    <p>An exception was encountered trying to restart the web application.
585
    Check the Tomcat logs for the details.</p>
538
    Check the Tomcat logs for the details.</p>
586
    </blockquote></li>
539
    </li>
587
<li><em>Invalid context path was specified</em>
540
<li><em>Invalid context path was specified</em>
588
    <blockquote>
589
    <p>The context path must start with a slash character. To reference the
541
    <p>The context path must start with a slash character. To reference the
590
    ROOT web application use "/".</p>
542
    ROOT web application use "/".</p>
591
    </blockquote></li>
543
    </li>
592
<li><em>No context exists for path /foo</em>
544
<li><em>No context exists for path /foo</em>
593
    <blockquote>
594
    <p>There is no deployed application on the context path
545
    <p>There is no deployed application on the context path
595
    that you specified.</p>
546
    that you specified.</p>
596
    </blockquote></li>
547
    </li>
597
<li><em>No context path was specified</em>
548
<li><em>No context path was specified</em>
598
    <blockquote>
549
    <p>
599
    The <code>path</code> parameter is required.
550
    The <code>path</code> parameter is required.
600
    </blockquote></li>
551
    </p></li>
601
<li><em>Reload not supported on WAR deployed at path /foo</em>
552
<li><em>Reload not supported on WAR deployed at path /foo</em>
602
    <blockquote>
553
    <p>
603
    Currently, application reloading (to pick up changes to the classes or
554
    Currently, application reloading (to pick up changes to the classes or
604
    <code>web.xml</code> file) is not supported when a web application is
555
    <code>web.xml</code> file) is not supported when a web application is
605
    deployed directly from a WAR file.  It only works when the web application
556
    deployed directly from a WAR file.  It only works when the web application
Lines 607-613 Link Here
607
    you should <code>undeploy</code> and then <code>deploy</code> or
558
    you should <code>undeploy</code> and then <code>deploy</code> or
608
    <code>deploy</code> with the <code>update</code> parameter the
559
    <code>deploy</code> with the <code>update</code> parameter the
609
    application again to pick up your changes.
560
    application again to pick up your changes.
610
    </blockquote></li>
561
    </p></li>
611
</ul>
562
</ul>
612
563
613
</subsection>
564
</subsection>
Lines 614-622 Link Here
614
565
615
<subsection name="List OS and JVM Properties">
566
<subsection name="List OS and JVM Properties">
616
567
617
<source>
568
<source>http://localhost:8080/manager/text/serverinfo</source>
618
http://localhost:8080/manager/text/serverinfo
619
</source>
620
569
621
<p>Lists information about the Tomcat version, OS, and JVM properties.</p>
570
<p>Lists information about the Tomcat version, OS, and JVM properties.</p>
622
571
Lines 624-633 Link Here
624
include an error message.  Possible causes for problems include:</p>
573
include an error message.  Possible causes for problems include:</p>
625
<ul>
574
<ul>
626
<li><em>Encountered exception</em>
575
<li><em>Encountered exception</em>
627
    <blockquote>
628
    <p>An exception was encountered trying to enumerate the system properties.
576
    <p>An exception was encountered trying to enumerate the system properties.
629
    Check the Tomcat logs for the details.</p>
577
    Check the Tomcat logs for the details.</p>
630
    </blockquote></li>
578
    </li>
631
</ul>
579
</ul>
632
580
633
</subsection>
581
</subsection>
Lines 634-642 Link Here
634
582
635
<subsection name="List Available Global JNDI Resources">
583
<subsection name="List Available Global JNDI Resources">
636
584
637
<source>
585
<source>http://localhost:8080/manager/text/resources[?type=xxxxx]</source>
638
http://localhost:8080/manager/text/resources[?type=xxxxx]
639
</source>
640
586
641
<p>List the global JNDI resources that are available for use in resource
587
<p>List the global JNDI resources that are available for use in resource
642
links for context configuration files.  If you specify the <code>type</code>
588
links for context configuration files.  If you specify the <code>type</code>
Lines 648-660 Link Here
648
594
649
<p>Depending on whether the <code>type</code> request parameter is specified
595
<p>Depending on whether the <code>type</code> request parameter is specified
650
or not, the first line of a normal response will be:</p>
596
or not, the first line of a normal response will be:</p>
651
<pre>
597
<source>OK - Listed global resources of all types</source>
652
  OK - Listed global resources of all types
653
</pre>
654
<p>or</p>
598
<p>or</p>
655
<pre>
599
<source>OK - Listed global resources of type xxxxx</source>
656
  OK - Listed global resources of type xxxxx
657
</pre>
658
<p>followed by one line for each resource.  Each line is composed of fields
600
<p>followed by one line for each resource.  Each line is composed of fields
659
delimited by colon characters (":"), as follows:</p>
601
delimited by colon characters (":"), as follows:</p>
660
<ul>
602
<ul>
Lines 669-683 Link Here
669
include an error message.  Possible causes for problems include:</p>
611
include an error message.  Possible causes for problems include:</p>
670
<ul>
612
<ul>
671
<li><em>Encountered exception</em>
613
<li><em>Encountered exception</em>
672
    <blockquote>
673
    <p>An exception was encountered trying to enumerate the global JNDI
614
    <p>An exception was encountered trying to enumerate the global JNDI
674
    resources.  Check the Tomcat logs for the details.</p>
615
    resources.  Check the Tomcat logs for the details.</p>
675
    </blockquote></li>
616
    </li>
676
<li><em>No global JNDI resources are available</em>
617
<li><em>No global JNDI resources are available</em>
677
    <blockquote>
678
    <p>The Tomcat server you are running has been configured without
618
    <p>The Tomcat server you are running has been configured without
679
    global JNDI resources.</p>
619
    global JNDI resources.</p>
680
    </blockquote></li>
620
    </li>
681
</ul>
621
</ul>
682
622
683
623
Lines 685-693 Link Here
685
625
686
<subsection name="Session Statistics">
626
<subsection name="Session Statistics">
687
627
688
<source>
628
<source>http://localhost:8080/manager/text/sessions?path=/examples</source>
689
http://localhost:8080/manager/text/sessions?path=/examples
690
</source>
691
629
692
<p>Display the default session timeout for a web application, and the
630
<p>Display the default session timeout for a web application, and the
693
number of currently active sessions that fall within ten-minute ranges of
631
number of currently active sessions that fall within ten-minute ranges of
Lines 694-704 Link Here
694
their actual timeout times.  For example, after restarting Tomcat and then
632
their actual timeout times.  For example, after restarting Tomcat and then
695
executing one of the JSP samples in the <code>/examples</code> web app,
633
executing one of the JSP samples in the <code>/examples</code> web app,
696
you might get something like this:</p>
634
you might get something like this:</p>
697
<source>
635
<source>OK - Session information for application at context path /examples
698
OK - Session information for application at context path /examples
699
Default maximum session inactive interval 30 minutes
636
Default maximum session inactive interval 30 minutes
700
30 - &lt;40 minutes:1 sessions
637
30 - &lt;40 minutes:1 sessions</source>
701
</source>
702
638
703
</subsection>
639
</subsection>
704
640
Lines 705-713 Link Here
705
641
706
<subsection name="Start an Existing Application">
642
<subsection name="Start an Existing Application">
707
643
708
<source>
644
<source>http://localhost:8080/manager/text/start?path=/examples</source>
709
http://localhost:8080/manager/text/start?path=/examples
710
</source>
711
645
712
<p>Signal a stopped application to restart, and make itself available again.
646
<p>Signal a stopped application to restart, and make itself available again.
713
Stopping and starting is useful, for example, if the database required by
647
Stopping and starting is useful, for example, if the database required by
Lines 716-747 Link Here
716
users continuously encounter database exceptions.</p>
650
users continuously encounter database exceptions.</p>
717
651
718
<p>If this command succeeds, you will see a response like this:</p>
652
<p>If this command succeeds, you will see a response like this:</p>
719
<source>
653
<source>OK - Started application at context path /examples</source>
720
OK - Started application at context path /examples
721
</source>
722
654
723
<p>Otherwise, the response will start with <code>FAIL</code> and include an
655
<p>Otherwise, the response will start with <code>FAIL</code> and include an
724
error message.  Possible causes for problems include:</p>
656
error message.  Possible causes for problems include:</p>
725
<ul>
657
<ul>
726
<li><em>Encountered exception</em>
658
<li><em>Encountered exception</em>
727
    <blockquote>
728
    <p>An exception was encountered trying to start the web application.
659
    <p>An exception was encountered trying to start the web application.
729
    Check the Tomcat logs for the details.</p>
660
    Check the Tomcat logs for the details.</p>
730
    </blockquote></li>
661
    </li>
731
<li><em>Invalid context path was specified</em>
662
<li><em>Invalid context path was specified</em>
732
    <blockquote>
733
    <p>The context path must start with a slash character. To reference the
663
    <p>The context path must start with a slash character. To reference the
734
    ROOT web application use "/".</p>
664
    ROOT web application use "/".</p>
735
    </blockquote></li>
665
    </li>
736
<li><em>No context exists for path /foo</em>
666
<li><em>No context exists for path /foo</em>
737
    <blockquote>
738
    <p>There is no deployed application on the context path
667
    <p>There is no deployed application on the context path
739
    that you specified.</p>
668
    that you specified.</p>
740
    </blockquote></li>
669
    </li>
741
<li><em>No context path was specified</em>
670
<li><em>No context path was specified</em>
742
    <blockquote>
671
    <p>
743
    The <code>path</code> parameter is required.
672
    The <code>path</code> parameter is required.
744
    </blockquote></li>
673
    </p></li>
745
</ul>
674
</ul>
746
675
747
</subsection>
676
</subsection>
Lines 748-756 Link Here
748
677
749
<subsection name="Stop an Existing Application">
678
<subsection name="Stop an Existing Application">
750
679
751
<source>
680
<source>http://localhost:8080/manager/text/stop?path=/examples</source>
752
http://localhost:8080/manager/text/stop?path=/examples
753
</source>
754
681
755
<p>Signal an existing application to make itself unavailable, but leave it
682
<p>Signal an existing application to make itself unavailable, but leave it
756
deployed.  Any request that comes in while an application is
683
deployed.  Any request that comes in while an application is
Lines 758-789 Link Here
758
"stopped" on a list applications command.</p>
685
"stopped" on a list applications command.</p>
759
686
760
<p>If this command succeeds, you will see a response like this:</p>
687
<p>If this command succeeds, you will see a response like this:</p>
761
<source>
688
<source>OK - Stopped application at context path /examples</source>
762
OK - Stopped application at context path /examples
763
</source>
764
689
765
<p>Otherwise, the response will start with <code>FAIL</code> and include an
690
<p>Otherwise, the response will start with <code>FAIL</code> and include an
766
error message.  Possible causes for problems include:</p>
691
error message.  Possible causes for problems include:</p>
767
<ul>
692
<ul>
768
<li><em>Encountered exception</em>
693
<li><em>Encountered exception</em>
769
    <blockquote>
770
    <p>An exception was encountered trying to stop the web application.
694
    <p>An exception was encountered trying to stop the web application.
771
    Check the Tomcat logs for the details.</p>
695
    Check the Tomcat logs for the details.</p>
772
    </blockquote></li>
696
    </li>
773
<li><em>Invalid context path was specified</em>
697
<li><em>Invalid context path was specified</em>
774
    <blockquote>
775
    <p>The context path must start with a slash character. To reference the
698
    <p>The context path must start with a slash character. To reference the
776
    ROOT web application use "/".</p>
699
    ROOT web application use "/".</p>
777
    </blockquote></li>
700
    </li>
778
<li><em>No context exists for path /foo</em>
701
<li><em>No context exists for path /foo</em>
779
    <blockquote>
780
    <p>There is no deployed application on the context path
702
    <p>There is no deployed application on the context path
781
    that you specified.</p>
703
    that you specified.</p>
782
    </blockquote></li>
704
    </li>
783
<li><em>No context path was specified</em>
705
<li><em>No context path was specified</em>
784
    <blockquote>
785
    The <code>path</code> parameter is required.
706
    The <code>path</code> parameter is required.
786
    </blockquote></li>
707
    </li>
787
</ul>
708
</ul>
788
709
789
</subsection>
710
</subsection>
Lines 791-801 Link Here
791
712
792
<subsection name="Undeploy an Existing Application">
713
<subsection name="Undeploy an Existing Application">
793
714
794
<source>
715
<source>http://localhost:8080/manager/text/undeploy?path=/examples</source>
795
http://localhost:8080/manager/text/undeploy?path=/examples
796
</source>
797
716
798
<p><strong><font color="red">WARNING</font> - This command will delete any web
717
<p><strong><span style="color: red;">WARNING</span> - This command will delete any web
799
application artifacts that exist within <code>appBase</code> directory
718
application artifacts that exist within <code>appBase</code> directory
800
(typically "webapps") for this virtual host</strong>.
719
(typically "webapps") for this virtual host</strong>.
801
This will delete the the application .WAR, if present,
720
This will delete the the application .WAR, if present,
Lines 813-844 Link Here
813
<code>/deploy</code> command.</p>
732
<code>/deploy</code> command.</p>
814
733
815
<p>If this command succeeds, you will see a response like this:</p>
734
<p>If this command succeeds, you will see a response like this:</p>
816
<source>
735
<source>OK - Undeployed application at context path /examples</source>
817
OK - Undeployed application at context path /examples
818
</source>
819
736
820
<p>Otherwise, the response will start with <code>FAIL</code> and include an
737
<p>Otherwise, the response will start with <code>FAIL</code> and include an
821
error message.  Possible causes for problems include:</p>
738
error message.  Possible causes for problems include:</p>
822
<ul>
739
<ul>
823
<li><em>Encountered exception</em>
740
<li><em>Encountered exception</em>
824
    <blockquote>
825
    <p>An exception was encountered trying to undeploy the web application.
741
    <p>An exception was encountered trying to undeploy the web application.
826
    Check the Tomcat logs for the details.</p>
742
    Check the Tomcat logs for the details.</p>
827
    </blockquote></li>
743
    </li>
828
<li><em>Invalid context path was specified</em>
744
<li><em>Invalid context path was specified</em>
829
    <blockquote>
830
    <p>The context path must start with a slash character. To reference the
745
    <p>The context path must start with a slash character. To reference the
831
    ROOT web application use "/".</p>
746
    ROOT web application use "/".</p>
832
    </blockquote></li>
747
    </li>
833
<li><em>No context exists for path /foo</em>
748
<li><em>No context exists for path /foo</em>
834
    <blockquote>
835
    <p>There is no deployed application on the context path
749
    <p>There is no deployed application on the context path
836
    that you specified.</p>
750
    that you specified.</p>
837
    </blockquote></li>
751
    </li>
838
<li><em>No context path was specified</em>
752
<li><em>No context path was specified</em>
839
    <blockquote>
840
    The <code>path</code> parameter is required.
753
    The <code>path</code> parameter is required.
841
    </blockquote></li>
754
    </li>
842
</ul>
755
</ul>
843
756
844
</subsection>
757
</subsection>
Lines 845-853 Link Here
845
758
846
<subsection name="Finding memory leaks">
759
<subsection name="Finding memory leaks">
847
760
848
<source>
761
<source>http://localhost:8080/manager/text/findleaks[?statusLine=[true|false]]</source>
849
http://localhost:8080/manager/text/findleaks[?statusLine=[true|false]]
850
</source>
851
762
852
<p><strong>The find leaks diagnostic triggers a full garbage collection. It
763
<p><strong>The find leaks diagnostic triggers a full garbage collection. It
853
should be used with extreme caution on production systems.</strong></p>
764
should be used with extreme caution on production systems.</strong></p>
Lines 866-874 Link Here
866
GC, you will need to check using tools like GC logging, JConsole or similar.</p>
777
GC, you will need to check using tools like GC logging, JConsole or similar.</p>
867
778
868
<p>If this command succeeds, you will see a response like this:</p>
779
<p>If this command succeeds, you will see a response like this:</p>
869
<source>
780
<source>/leaking-webapp</source>
870
/leaking-webapp
871
</source>
872
781
873
<p>If you wish to see a status line included in the response then include the
782
<p>If you wish to see a status line included in the response then include the
874
<code>statusLine</code> query parameter in the request with a value of
783
<code>statusLine</code> query parameter in the request with a value of
Lines 886-894 Link Here
886
795
887
<subsection name="Connector SSL diagnostics">
796
<subsection name="Connector SSL diagnostics">
888
797
889
<source>
798
<source>http://localhost:8080/manager/text/sslConnectorCiphers</source>
890
http://localhost:8080/manager/text/sslConnectorCiphers
891
</source>
892
799
893
<p>The SSL Connector/Ciphers diagnostic lists the SSL ciphers that are currently
800
<p>The SSL Connector/Ciphers diagnostic lists the SSL ciphers that are currently
894
configured for each connector. For BIO and NIO, the names of the individual
801
configured for each connector. For BIO and NIO, the names of the individual
Lines 895-902 Link Here
895
cipher suites are listed. For APR, the value of SSLCipherSuite is returned.</p>
802
cipher suites are listed. For APR, the value of SSLCipherSuite is returned.</p>
896
803
897
<p>The response will ook something like this:</p>
804
<p>The response will ook something like this:</p>
898
<source>
805
<source>OK - Connector / SSL Cipher information
899
OK - Connector / SSL Cipher information
900
Connector[HTTP/1.1-8080]
806
Connector[HTTP/1.1-8080]
901
  SSL is not enabled for this connector
807
  SSL is not enabled for this connector
902
Connector[HTTP/1.1-8443]
808
Connector[HTTP/1.1-8443]
Lines 904-911 Link Here
904
  TLS_DHE_RSA_WITH_AES_128_CBC_SHA
810
  TLS_DHE_RSA_WITH_AES_128_CBC_SHA
905
  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
811
  TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
906
  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
812
  TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
907
  ...
813
  ...</source>
908
</source>
909
814
910
</subsection>
815
</subsection>
911
816
Lines 982-1038 Link Here
982
<code>&lt;taskdef&gt;</code> element.  Therefore, your <code>build.xml</code>
887
<code>&lt;taskdef&gt;</code> element.  Therefore, your <code>build.xml</code>
983
file might look something like this:</p>
888
file might look something like this:</p>
984
889
985
<table border="1">
890
<source><![CDATA[<project name="My Application" default="compile" basedir=".">
986
<tr><td><pre>
987
&lt;project name="My Application" default="compile" basedir="."&gt;
988
891
989
  &lt;!-- Configure the directory into which the web application is built --&gt;
892
  <!-- Configure the directory into which the web application is built -->
990
  &lt;property name="build"    value="${basedir}/build"/&gt;
893
  <property name="build"    value="${basedir}/build"/>
991
894
992
  &lt;!-- Configure the context path for this application --&gt;
895
  <!-- Configure the context path for this application -->
993
  &lt;property name="path"     value="/myapp"/&gt;
896
  <property name="path"     value="/myapp"/>
994
897
995
  &lt;!-- Configure properties to access the Manager application --&gt;
898
  <!-- Configure properties to access the Manager application -->
996
  &lt;property name="url"      value="http://localhost:8080/manager/text"/&gt;
899
  <property name="url"      value="http://localhost:8080/manager/text"/>
997
  &lt;property name="username" value="myusername"/&gt;
900
  <property name="username" value="myusername"/>
998
  &lt;property name="password" value="mypassword"/&gt;
901
  <property name="password" value="mypassword"/>
999
902
1000
  &lt;!-- Configure the custom Ant tasks for the Manager application --&gt;
903
  <!-- Configure the custom Ant tasks for the Manager application -->
1001
  &lt;taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/&gt;
904
  <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/>
1002
  &lt;taskdef name="list"      classname="org.apache.catalina.ant.ListTask"/&gt;
905
  <taskdef name="list"      classname="org.apache.catalina.ant.ListTask"/>
1003
  &lt;taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"/&gt;
906
  <taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"/>
1004
  &lt;taskdef name="findleaks" classname="org.apache.catalina.ant.FindLeaksTask"/&gt;
907
  <taskdef name="findleaks" classname="org.apache.catalina.ant.FindLeaksTask"/>
1005
  &lt;taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/&gt;
908
  <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/>
1006
  &lt;taskdef name="start"     classname="org.apache.catalina.ant.StartTask"/&gt;
909
  <taskdef name="start"     classname="org.apache.catalina.ant.StartTask"/>
1007
  &lt;taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"/&gt;
910
  <taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"/>
1008
  &lt;taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/&gt;
911
  <taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/>
1009
912
1010
  &lt;!-- Executable Targets --&gt;
913
  <!-- Executable Targets -->
1011
  &lt;target name="compile" description="Compile web application"&gt;
914
  <target name="compile" description="Compile web application">
1012
    &lt;!-- ... construct web application in ${build} subdirectory, and
915
    <!-- ... construct web application in ${build} subdirectory, and
1013
            generated a ${path}.war ... --&gt;
916
            generated a ${path}.war ... -->
1014
  &lt;/target&gt;
917
  </target>
1015
918
1016
  &lt;target name="deploy" description="Install web application"
919
  <target name="deploy" description="Install web application"
1017
          depends="compile"&gt;
920
          depends="compile">
1018
    &lt;deploy url="${url}" username="${username}" password="${password}"
921
    <deploy url="${url}" username="${username}" password="${password}"
1019
            path="${path}" war="file:${build}${path}.war"/&gt;
922
            path="${path}" war="file:${build}${path}.war"/>
1020
  &lt;/target&gt;
923
  </target>
1021
924
1022
  &lt;target name="reload" description="Reload web application"
925
  <target name="reload" description="Reload web application"
1023
          depends="compile"&gt;
926
          depends="compile">
1024
    &lt;reload  url="${url}" username="${username}" password="${password}"
927
    <reload  url="${url}" username="${username}" password="${password}"
1025
            path="${path}"/&gt;
928
            path="${path}"/>
1026
  &lt;/target&gt;
929
  </target>
1027
930
1028
  &lt;target name="undeploy" description="Remove web application"&gt;
931
  <target name="undeploy" description="Remove web application">
1029
    &lt;undeploy url="${url}" username="${username}" password="${password}"
932
    <undeploy url="${url}" username="${username}" password="${password}"
1030
            path="${path}"/&gt;
933
            path="${path}"/>
1031
  &lt;/target&gt;
934
  </target>
1032
935
1033
&lt;/project&gt;
936
</project>]]></source>
1034
</pre></td></tr>
1035
</table>
1036
937
1037
<p>Note: The definition of the resources task above will override the resources
938
<p>Note: The definition of the resources task above will override the resources
1038
datatype added in Ant 1.7. If you wish to use the resources datatype you will
939
datatype added in Ant 1.7. If you wish to use the resources datatype you will
Lines 1047-1055 Link Here
1047
consider it a security risk to include the real manager password in your
948
consider it a security risk to include the real manager password in your
1048
<code>build.xml</code> file's source code.  To avoid this, omit the password
949
<code>build.xml</code> file's source code.  To avoid this, omit the password
1049
property, and specify it from the command line:</p>
950
property, and specify it from the command line:</p>
1050
<pre>
951
<source>ant -Dpassword=secret deploy</source>
1051
  ant -Dpassword=secret deploy
1052
</pre>
1053
952
1054
<subsection name="Tasks output capture">
953
<subsection name="Tasks output capture">
1055
954
Lines 1059-1153 Link Here
1059
<code>&lt;redirector&gt;</code> type attributes:
958
<code>&lt;redirector&gt;</code> type attributes:
1060
</p>
959
</p>
1061
960
1062
<table border="1" cellpadding="2" cellspacing="0">
961
<table class="defaultTable">
1063
<tbody>
1064
<tr>
962
<tr>
1065
<td valign="top"><b>Attribute</b></td>
963
<th>Attribute</th>
1066
<td valign="top"><b>Description</b></td>
964
<th>Description</th>
1067
<td align="center" valign="top"><b>Required</b></td>
965
<th style="text-align: center;">Required</th>
1068
</tr>
966
</tr>
1069
<tr>
967
<tr>
1070
<td valign="top">output</td>
968
<td>output</td>
1071
<td valign="top">Name of a file to which to write the output. If
969
<td>Name of a file to which to write the output. If
1072
the error stream is not also redirected to a file or property, it will
970
the error stream is not also redirected to a file or property, it will
1073
appear in this output.</td>
971
appear in this output.</td>
1074
<td align="center" valign="top">No</td>
972
<td style="text-align: center;">No</td>
1075
</tr>
973
</tr>
1076
<tr>
974
<tr>
1077
<td valign="top">error</td>
975
<td>error</td>
1078
<td valign="top">The file to which the standard error of the
976
<td>The file to which the standard error of the
1079
command should be redirected.</td>
977
command should be redirected.</td>
1080
<td align="center" valign="top">No</td>
978
<td style="text-align: center;">No</td>
1081
</tr>
979
</tr>
1082
<tr>
980
<tr>
1083
<td valign="top">logError</td>
981
<td>logError</td>
1084
<td valign="top">This attribute is used when you wish to see
982
<td>This attribute is used when you wish to see
1085
error output in Ant's log and you are redirecting output to a
983
error output in Ant's log and you are redirecting output to a
1086
file/property. The error output will not be included in the output
984
file/property. The error output will not be included in the output
1087
file/property. If you redirect error with the <i>error</i> or <i>errorProperty</i>
985
file/property. If you redirect error with the <i>error</i> or <i>errorProperty</i>
1088
attributes, this will have no effect.</td>
986
attributes, this will have no effect.</td>
1089
<td align="center" valign="top">No</td>
987
<td style="text-align: center;">No</td>
1090
</tr>
988
</tr>
1091
<tr>
989
<tr>
1092
<td valign="top">append</td>
990
<td>append</td>
1093
<td valign="top">Whether output and error files should be
991
<td>Whether output and error files should be
1094
appended to or overwritten. Defaults to <code>false</code>.</td>
992
appended to or overwritten. Defaults to <code>false</code>.</td>
1095
<td align="center" valign="top">No</td>
993
<td style="text-align: center;">No</td>
1096
</tr>
994
</tr>
1097
<tr>
995
<tr>
1098
<td valign="top">createemptyfiles</td>
996
<td>createemptyfiles</td>
1099
<td valign="top">Whether output and error files should be created
997
<td>Whether output and error files should be created
1100
even when empty. Defaults to <code>true</code>.</td>
998
even when empty. Defaults to <code>true</code>.</td>
1101
<td align="center" valign="top">No</td>
999
<td style="text-align: center;">No</td>
1102
</tr>
1000
</tr>
1103
<tr>
1001
<tr>
1104
<td valign="top">outputproperty</td>
1002
<td>outputproperty</td>
1105
<td valign="top">The name of a property in which the output of
1003
<td>The name of a property in which the output of
1106
the command should be stored. Unless the error stream is redirected to
1004
the command should be stored. Unless the error stream is redirected to
1107
a separate file or stream, this property will include the error output.</td>
1005
a separate file or stream, this property will include the error output.</td>
1108
<td align="center" valign="top">No</td>
1006
<td style="text-align: center;">No</td>
1109
</tr>
1007
</tr>
1110
<tr>
1008
<tr>
1111
<td valign="top">errorproperty</td>
1009
<td>errorproperty</td>
1112
<td valign="top">The name of a property in which the standard
1010
<td>The name of a property in which the standard
1113
error of the command should be stored.</td>
1011
error of the command should be stored.</td>
1114
<td align="center" valign="top">No</td>
1012
<td style="text-align: center;">No</td>
1115
</tr>
1013
</tr>
1116
</tbody>
1117
</table>
1014
</table>
1118
1015
1119
<p>A couple of additional attributes can also be specified:
1016
<p>A couple of additional attributes can also be specified:
1120
</p>
1017
</p>
1121
<table border="1" cellpadding="2" cellspacing="0">
1018
<table class="defaultTable">
1122
<tbody>
1123
<tr>
1019
<tr>
1124
<td valign="top"><b>Attribute</b></td>
1020
<th>Attribute</th>
1125
<td valign="top"><b>Description</b></td>
1021
<th>Description</th>
1126
<td align="center" valign="top"><b>Required</b></td>
1022
<th style="text-align: center;">Required</th>
1127
</tr>
1023
</tr>
1128
<tr>
1024
<tr>
1129
<td valign="top">alwaysLog</td>
1025
<td>alwaysLog</td>
1130
<td valign="top">This attribute is used when you wish to see the
1026
<td>This attribute is used when you wish to see the
1131
output you are capturing, appearing also in the Ant's log. It must not be
1027
output you are capturing, appearing also in the Ant's log. It must not be
1132
used unless you are capturing task output.
1028
used unless you are capturing task output.
1133
Defaults to <code>false</code>.
1029
Defaults to <code>false</code>.
1134
<em>This attribute will be supported directly by <code>&lt;redirector&gt;</code>
1030
<em>This attribute will be supported directly by <code>&lt;redirector&gt;</code>
1135
in Ant 1.6.3</em></td>
1031
in Ant 1.6.3</em></td>
1136
<td align="center" valign="top">No</td>
1032
<td style="text-align: center;">No</td>
1137
</tr>
1033
</tr>
1138
<tr>
1034
<tr>
1139
<td valign="top">failonerror</td>
1035
<td>failonerror</td>
1140
<td valign="top">This attribute is used when you wish to avoid that
1036
<td>This attribute is used when you wish to avoid that
1141
any manager command processing error terminates the ant execution. Defaults to <code>true</code>.
1037
any manager command processing error terminates the ant execution. Defaults to <code>true</code>.
1142
It must be set to <code>false</code>, if you want to capture error output,
1038
It must be set to <code>false</code>, if you want to capture error output,
1143
otherwise execution will terminate before anything can be captured.
1039
otherwise execution will terminate before anything can be captured.
1144
<br></br>
1040
<br/>
1145
This attribute acts only on manager command execution,
1041
This attribute acts only on manager command execution,
1146
any wrong or missing command attribute will still cause Ant execution termination.
1042
any wrong or missing command attribute will still cause Ant execution termination.
1147
</td>
1043
</td>
1148
<td align="center" valign="top">No</td>
1044
<td style="text-align: center;">No</td>
1149
</tr>
1045
</tr>
1150
</tbody>
1151
</table>
1046
</table>
1152
1047
1153
<p>They also support the embedded <code>&lt;redirector&gt;</code> element
1048
<p>They also support the embedded <code>&lt;redirector&gt;</code> element
Lines 1164-1236 Link Here
1164
can be used:
1059
can be used:
1165
</p>
1060
</p>
1166
1061
1167
<table border="1">
1062
<source><![CDATA[    <target name="manager.deploy"
1168
<tr><td><pre>
1169
    &lt;target name="manager.deploy"
1170
        depends="context.status"
1063
        depends="context.status"
1171
        if="context.notInstalled"&gt;
1064
        if="context.notInstalled">
1172
        &lt;deploy url="${mgr.url}"
1065
        <deploy url="${mgr.url}"
1173
            username="${mgr.username}"
1066
            username="${mgr.username}"
1174
            password="${mgr.password}"
1067
            password="${mgr.password}"
1175
            path="${mgr.context.path}"
1068
            path="${mgr.context.path}"
1176
            config="${mgr.context.descriptor}"/&gt;
1069
            config="${mgr.context.descriptor}"/>
1177
    &lt;/target&gt;
1070
    </target>
1178
1071
1179
    &lt;target name="manager.deploy.war"
1072
    <target name="manager.deploy.war"
1180
        depends="context.status"
1073
        depends="context.status"
1181
        if="context.deployable"&gt;
1074
        if="context.deployable">
1182
        &lt;deploy url="${mgr.url}"
1075
        <deploy url="${mgr.url}"
1183
            username="${mgr.username}"
1076
            username="${mgr.username}"
1184
            password="${mgr.password}"
1077
            password="${mgr.password}"
1185
            update="${mgr.update}"
1078
            update="${mgr.update}"
1186
            path="${mgr.context.path}"
1079
            path="${mgr.context.path}"
1187
            war="${mgr.war.file}"/&gt;
1080
            war="${mgr.war.file}"/>
1188
    &lt;/target&gt;
1081
    </target>
1189
1082
1190
    &lt;target name="context.status"&gt;
1083
    <target name="context.status">
1191
        &lt;property name="running" value="${mgr.context.path}:running"/&gt;
1084
        <property name="running" value="${mgr.context.path}:running"/>
1192
        &lt;property name="stopped" value="${mgr.context.path}:stopped"/&gt;
1085
        <property name="stopped" value="${mgr.context.path}:stopped"/>
1193
1086
1194
        &lt;list url="${mgr.url}"
1087
        <list url="${mgr.url}"
1195
            outputproperty="ctx.status"
1088
            outputproperty="ctx.status"
1196
            username="${mgr.username}"
1089
            username="${mgr.username}"
1197
            password="${mgr.password}"&gt;
1090
            password="${mgr.password}">
1198
        &lt;/list&gt;
1091
        </list>
1199
1092
1200
        &lt;condition property="context.running"&gt;
1093
        <condition property="context.running">
1201
            &lt;contains string="${ctx.status}" substring="${running}"/&gt;
1094
            <contains string="${ctx.status}" substring="${running}"/>
1202
        &lt;/condition&gt;
1095
        </condition>
1203
        &lt;condition property="context.stopped"&gt;
1096
        <condition property="context.stopped">
1204
            &lt;contains string="${ctx.status}" substring="${stopped}"/&gt;
1097
            <contains string="${ctx.status}" substring="${stopped}"/>
1205
        &lt;/condition&gt;
1098
        </condition>
1206
        &lt;condition property="context.notInstalled"&gt;
1099
        <condition property="context.notInstalled">
1207
            &lt;and&gt;
1100
            <and>
1208
                &lt;isfalse value="${context.running}"/&gt;
1101
                <isfalse value="${context.running}"/>
1209
                &lt;isfalse value="${context.stopped}"/&gt;
1102
                <isfalse value="${context.stopped}"/>
1210
            &lt;/and&gt;
1103
            </and>
1211
        &lt;/condition&gt;
1104
        </condition>
1212
        &lt;condition property="context.deployable"&gt;
1105
        <condition property="context.deployable">
1213
            &lt;or&gt;
1106
            <or>
1214
                &lt;istrue value="${context.notInstalled}"/&gt;
1107
                <istrue value="${context.notInstalled}"/>
1215
                &lt;and&gt;
1108
                <and>
1216
                    &lt;istrue value="${context.running}"/&gt;
1109
                    <istrue value="${context.running}"/>
1217
                    &lt;istrue value="${mgr.update}"/&gt;
1110
                    <istrue value="${mgr.update}"/>
1218
                &lt;/and&gt;
1111
                </and>
1219
                &lt;and&gt;
1112
                <and>
1220
                    &lt;istrue value="${context.stopped}"/&gt;
1113
                    <istrue value="${context.stopped}"/>
1221
                    &lt;istrue value="${mgr.update}"/&gt;
1114
                    <istrue value="${mgr.update}"/>
1222
                &lt;/and&gt;
1115
                </and>
1223
            &lt;/or&gt;
1116
            </or>
1224
        &lt;/condition&gt;
1117
        </condition>
1225
        &lt;condition property="context.undeployable"&gt;
1118
        <condition property="context.undeployable">
1226
            &lt;or&gt;
1119
            <or>
1227
                &lt;istrue value="${context.running}"/&gt;
1120
                <istrue value="${context.running}"/>
1228
                &lt;istrue value="${context.stopped}"/&gt;
1121
                <istrue value="${context.stopped}"/>
1229
            &lt;/or&gt;
1122
            </or>
1230
        &lt;/condition&gt;
1123
        </condition>
1231
    &lt;/target&gt;
1124
    </target>]]></source>
1232
</pre></td></tr>
1233
</table>
1234
1125
1235
<p><strong>WARNING:</strong> even if it doesn't make many sense, and is always a bad idea,
1126
<p><strong>WARNING:</strong> even if it doesn't make many sense, and is always a bad idea,
1236
calling a Catalina task more than once,
1127
calling a Catalina task more than once,
Lines 1265-1276 Link Here
1265
  </subsection>
1156
  </subsection>
1266
1157
1267
  <subsection name="JMX Query command">
1158
  <subsection name="JMX Query command">
1268
    This takes the form:
1159
    <p>This takes the form:</p>
1269
<source>
1160
<source>http://webserver/manager/jmxproxy/?qry=STUFF</source>
1270
http://webserver/manager/jmxproxy/?qry=STUFF
1161
    <p>Where <code>STUFF</code> is the JMX query you wish to perform. For example,
1271
</source>
1162
    here are some queries you might wish to run:</p>
1272
    Where <code>STUFF</code> is the JMX query you wish to perform. For example,
1273
    here are some queries you might wish to run:
1274
    <ul>
1163
    <ul>
1275
      <li>
1164
      <li>
1276
        <code>qry=*%3Atype%3DRequestProcessor%2C* -->
1165
        <code>qry=*%3Atype%3DRequestProcessor%2C* -->
Lines 1288-1383 Link Here
1288
            which look for a specific MBean by the given name.
1177
            which look for a specific MBean by the given name.
1289
      </li>
1178
      </li>
1290
    </ul>
1179
    </ul>
1180
    <p>
1291
    You'll need to experiment with this to really understand its capabilites.
1181
    You'll need to experiment with this to really understand its capabilites.
1292
    If you provide no <code>qry</code> parameter, then all of the MBeans will
1182
    If you provide no <code>qry</code> parameter, then all of the MBeans will
1293
    be displayed. We really recommend looking at the tomcat source code and
1183
    be displayed. We really recommend looking at the tomcat source code and
1294
    understand the JMX spec to get a better understanding of all the queries
1184
    understand the JMX spec to get a better understanding of all the queries
1295
    you may run.
1185
    you may run.
1186
    </p>
1296
  </subsection>
1187
  </subsection>
1297
1188
1298
  <subsection name="JMX Get command">
1189
  <subsection name="JMX Get command">
1190
  <p>
1299
    The JXMProxyServlet also supports a "get" command that you can use to
1191
    The JXMProxyServlet also supports a "get" command that you can use to
1300
    fetch the value of a specific MBean's attribute. The general form of
1192
    fetch the value of a specific MBean's attribute. The general form of
1301
    the <code>get</code> command is:
1193
    the <code>get</code> command is:
1194
  </p>
1302
1195
1303
<source>
1196
<source>http://webserver/manager/jmxproxy/?get=BEANNAME&amp;att=MYATTRIBUTE&amp;key=MYKEY</source>
1304
http://webserver/manager/jmxproxy/?get=BEANNAME&amp;att=MYATTRIBUTE&amp;key=MYKEY
1305
</source>
1306
1197
1307
    You must provide the following parameters:
1198
    <p>You must provide the following parameters:</p>
1308
    <ol>
1199
    <ol>
1309
      <li><code>get</code>: The full bean name</li>
1200
      <li><code>get</code>: The full bean name</li>
1310
      <li><code>att</code>: The attribute you wish to fetch</li>
1201
      <li><code>att</code>: The attribute you wish to fetch</li>
1311
      <li><code>key</code>: (optional) The key into a CompositeData MBean attribute</li>
1202
      <li><code>key</code>: (optional) The key into a CompositeData MBean attribute</li>
1312
    </ol>
1203
    </ol>
1313
1204
    <p>
1314
    If all goes well, then it will say OK, otherwise an error message will
1205
    If all goes well, then it will say OK, otherwise an error message will
1315
    be shown. For example, let's say we wish to fetch the current heap memory
1206
    be shown. For example, let's say we wish to fetch the current heap memory
1316
    data:
1207
    data:
1208
    </p>
1317
1209
1318
<source>
1210
<source>http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage</source>
1319
http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage
1320
</source>
1321
1211
1322
    Or, if you only want the "used" key:
1212
    <p>Or, if you only want the "used" key:</p>
1323
1213
1324
<source>
1214
<source>http://webserver/manager/jmxproxy/
1325
http://webserver/manager/jmxproxy/
1215
 ?get=java.lang:type=Memory&amp;att=HeapMemoryUsage&amp;key=used</source>
1326
 ?get=java.lang:type=Memory&amp;att=HeapMemoryUsage&amp;key=used
1327
</source>
1328
  </subsection>
1216
  </subsection>
1329
1217
1330
  <subsection name="JMX Set command">
1218
  <subsection name="JMX Set command">
1219
    <p>
1331
    Now that you can query an MBean, its time to muck with Tomcat's internals!
1220
    Now that you can query an MBean, its time to muck with Tomcat's internals!
1332
    The general form of the set command is :
1221
    The general form of the set command is :
1333
<source>
1222
    </p>
1334
http://webserver/manager/jmxproxy/?set=BEANNAME&amp;att=MYATTRIBUTE&amp;val=NEWVALUE
1223
<source>http://webserver/manager/jmxproxy/?set=BEANNAME&amp;att=MYATTRIBUTE&amp;val=NEWVALUE</source>
1335
</source>
1224
    <p>So you need to provide 3 request parameters:</p>
1336
    So you need to provide 3 request parameters:
1337
    <ol>
1225
    <ol>
1338
      <li><code>set</code>: The full bean name</li>
1226
      <li><code>set</code>: The full bean name</li>
1339
      <li><code>att</code>: The attribute you wish to alter</li>
1227
      <li><code>att</code>: The attribute you wish to alter</li>
1340
      <li><code>val</code>: The new value </li>
1228
      <li><code>val</code>: The new value </li>
1341
    </ol>
1229
    </ol>
1230
    <p>
1342
    If all goes ok, then it will say OK, otherwise an error message will be
1231
    If all goes ok, then it will say OK, otherwise an error message will be
1343
    shown. For example, lets say we wish to turn up debugging on the fly for the
1232
    shown. For example, lets say we wish to turn up debugging on the fly for the
1344
    <code>ErrorReportValve</code>. The following will set debugging to 10.
1233
    <code>ErrorReportValve</code>. The following will set debugging to 10.
1345
<source>
1234
    </p>
1346
http://localhost:8080/manager/jmxproxy/
1235
<source>http://localhost:8080/manager/jmxproxy/
1347
 ?set=Catalina%3Atype%3DValve%2Cname%3DErrorReportValve%2Chost%3Dlocalhost
1236
 ?set=Catalina%3Atype%3DValve%2Cname%3DErrorReportValve%2Chost%3Dlocalhost
1348
 &amp;att=debug&amp;val=10
1237
 &amp;att=debug&amp;val=10</source>
1349
</source>
1238
    <p>and my result is (YMMV):</p>
1350
    and my result is (YMMV):
1239
<source>Result: ok</source>
1351
<source>
1352
Result: ok
1353
</source>
1354
1240
1355
    Here is what I see if I pass in a bad value. Here is the URL I used,
1241
    <p>Here is what I see if I pass in a bad value. Here is the URL I used,
1356
    I try set debugging equal to 'cow':
1242
    I try set debugging equal to 'cow':</p>
1357
<source>
1243
<source>http://localhost:8080/manager/jmxproxy/
1358
http://localhost:8080/manager/jmxproxy/
1359
 ?set=Catalina%3Atype%3DValve%2Cname%3DErrorReportValve%2Chost%3Dlocalhost
1244
 ?set=Catalina%3Atype%3DValve%2Cname%3DErrorReportValve%2Chost%3Dlocalhost
1360
 &amp;att=debug&amp;val=cow
1245
 &amp;att=debug&amp;val=cow</source>
1361
</source>
1246
    <p>When I try that, my result is</p>
1362
    When I try that, my result is
1247
<source>Error: java.lang.NumberFormatException: For input string: "cow"</source>
1363
<source>
1364
Error: java.lang.NumberFormatException: For input string: "cow"
1365
</source>
1366
  </subsection>
1248
  </subsection>
1367
1249
1368
  <subsection name="JMX Invoke command">
1250
  <subsection name="JMX Invoke command">
1369
    <p>The <code>invoke</code> command enables methods to be called on MBeans. The
1251
    <p>The <code>invoke</code> command enables methods to be called on MBeans. The
1370
    general form of the command is:</p>
1252
    general form of the command is:</p>
1371
<source>
1253
<source>http://webserver/manager/jmxproxy/
1372
http://webserver/manager/jmxproxy/
1254
 ?invoke=BEANNAME&amp;op=METHODNAME&amp;ps=COMMASEPARATEDPARAMETERS</source>
1373
 ?invoke=BEANNAME&amp;op=METHODNAME&amp;ps=COMMASEPARATEDPARAMETERS
1374
</source>
1375
    <p>For example, to call the <code>findConnectors()</code> method of the
1255
    <p>For example, to call the <code>findConnectors()</code> method of the
1376
    <strong>Service</strong> use:</p>
1256
    <strong>Service</strong> use:</p>
1377
<source>
1257
<source>http://localhost:8080/manager/jmxproxy/
1378
http://localhost:8080/manager/jmxproxy/
1258
 ?invoke=Catalina%3Atype%3DService&amp;op=findConnectors&amp;ps=</source>
1379
 ?invoke=Catalina%3Atype%3DService&amp;op=findConnectors&amp;ps=
1380
</source>
1381
  </subsection>
1259
  </subsection>
1382
</section>
1260
</section>
1383
1261

Return to bug 55383