You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Stevenson <ds...@rochester.rr.com> on 2004/11/26 21:26:55 UTC
Tomcat 4.1: Setting Up Connection Pooling, Adding Resource to
server.xml
The question relates to my home study of the Tomcat Server via the book
referenced below.
Added Context via Tomcat Administration page.
Added Resource, ResourceParams, and parameter tags by hand-editing
the server.xml file, and re-starting.
Reference: Ian McFarland, Peter Harrison, Mastering Tomcat Development,
Wiley Publishing, Inc., p. 283-284.
=============================================================
In Tomcat Administration Page:
Clicking on Data Sources, under Resources, under Context /tomcatbook,
under Host, gives the
following exception, perhaps indicating Tomcat 4.1 is not compatible
with this XML setup. Exception truncated for brevity's sake.
exception
org.apache.jasper.JasperException: Exception retrieving attribute
'driverClassName'
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
=============================================================
Changes to $CATALINA/HOME/server.xml (Context tag added by Tomcat
Administration page,
inside Context tag manually added via text editor, as recommended by
referenced book):
<Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true" crossContext="false" debug="0" docBase="tomcatbook"
mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/tomcatbook" privileged="false" reloadable="true"
swallowOutput="false" useNaming="false"
wrapperClass="org.apache.catalina.core.StandardWrapper">
<Resource name="jdbc/tomcatbook" auth="Container"
type="javax.sql.DataSource" >
<ResourceParams name="jdbc/tomcatbook">
<parameter>
<name>user</name>
<value>tomcatbook</value>
</parameter>
<parameter>
<name>password</name>
<value>PasswordIntentionallyChangedToProtectMeFromTheGuilty</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost.localdomain/tomcatbook</value>
</parameter>
</ResourceParams>
</Resource>
</Context>
=============================================================
Should I create a New Data Source in the Tomcat Administration Tool?
Would the following values be correct?
Property Value
JNDI Name: jdbc/tomcatbook
Data Source URL: jdbc:mysql://localhost.localdomain/tomcatbook
JDBC Driver Class: com.mysql.jdbc.Driver
User Name: tomcat
Password: PasswordIntentionallyChangedToProtectMeFromTheGuilty
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 5000
Validation Query: ??? select login, password from user ????
=============================================================
Server Information
Tomcat Version Apache Tomcat/4.1.24-LE-jdk14
JVM Version 1.4.2-b28
JVM Vendor Sun Microsystems Inc.
OS Name Linux
OS Version 2.4.20-31.9
OS Architecture i386
=============================================================
Working Java code:
import java.sql.* ;
public class TestMySQL3
{
public static void main ( String [] args )
throws Exception
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = null ;
Statement statement = null ;
ResultSet resultSet = null ;
String query = "select login, password from user" ;
try
{
connection = DriverManager.getConnection (
"jdbc:mysql://localhost/tomcatbook",
"tomcat",
"PasswordIntentionallyChangedToProtectMeFromTheGuilty" ) ;
statement = connection.createStatement () ;
resultSet = statement.executeQuery ( query ) ;
while ( resultSet.next () )
{
String login =
resultSet.getString ( 1 ) ;
String password =
resultSet.getString ( 2 ) ;
System.out.println ( "login: " + login +
" password: " + password ) ;
}
}
finally
{
if ( resultSet != null )
resultSet.close () ;
if ( statement != null )
statement.close () ;
if ( connection != null )
connection.close () ;
}
}
}
David Stevenson
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: CLIENT-CERT
Posted by Mario Ivankovits <ma...@ops.co.at>.
Raphael Gallo wrote:
> It´s possible use FORM authentication and CLIENT-CERT in the same
>application. How can I do this ?
>
>
Not sure if it works with FORM but I have done this with BASIC (through
https).
If the CLIENT-CERT fails the system will fallback to BASIC.
I have done this by fiddling my own SSLAuthenticator (called
SSLAuthenticatorOptional) into Tomcat.
The main changes in short:
private BasicAuthenticator secondAuth = new BasicAuthenticator();
// Authenticate the specified certificate chain
principal = context.getRealm().authenticate(certs);
if (principal == null)
{
if (debug >= 1)
{
log(" Realm.authenticate() returned false");
}
return secondAuth.authenticate(request, response, config);
// hres.sendError(HttpServletResponse.SC_UNAUTHORIZED,
// sm.getString("authenticator.unauthorized"));
// return (false);
}
To put the SSLAuthenticatorOptional into Tomcat I have had to change the
Authenticators.properties - which could done by this ant task
<target name="config-tomcat" description="Tomcat configuration">
<unjar src="${tomcat-server}/lib/catalina.jar"
dest="${tomcat-server}/classes">
<patternset
includes="org/apache/catalina/startup/Authenticators.properties"/>
</unjar>
<replaceregexp
file="${tomcat-server}/classes/org/apache/catalina/startup/Authenticators.properties"
byline="true"
match="CLIENT-CERT=org.apache.catalina.authenticator.SSLAuthenticator"
replace="CLIENT-CERT=tomcat.SSLAuthenticatorOptional"/>
</target>
---
Mario
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: bug JDBC Real with CLIENT-CERT
Posted by Mark Thomas <ma...@apache.org>.
I committed some patches to support CLIENT-CERT to 5.5.x recently. Should be in
the next release. If you want them now, you can always grab them from CVS.
Mark
> -----Original Message-----
> From: Paulo Alvim [mailto:alvim@powerlogic.com.br]
> Sent: Monday, November 29, 2004 4:02 PM
> To: Tomcat Users List
> Subject: bug JDBC Real with CLIENT-CERT
>
> Hi,
>
> I'm trying to use Client-Cert authentication with Tomcat
> 5.0.28. I could
> make it work using Memory Realm but when I changed to
> JDBCRealm I received
> an authorization error...
>
> In truth, it seems that there's a bug with Client-Cert and
> others Realm
> since 4.x.
>
> I've just read about that in a few links:
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=30352
>
> http://www.junlu.com/msg/43156.html
>
> Anyone could update that information? Is there any fix or
> patchs in Tomcat
> 5.0.28? I'll need to use it with JDBCRealm and with LDAP (Active
> Directory)...
>
> Thanks a lot!
>
> Paulo Alvim
> Powerlogic - Brazil
>
>
> -----Mensagem original-----
> De: Paulo Alvim [mailto:alvim@powerlogic.com.br]
> Enviada em: sábado, 27 de novembro de 2004 14:20
> Para: Tomcat Users List
> Assunto: RES: [work] CLIENT-CERT
>
>
> Hi,
>
> The questions are:
>
> 1. Is it possible to use two authentication methods (FORM and
> CLIENT_CERT)
> in the same J2EE application?
>
> 2. If so, how could we do it in Tomcat 5.0.19?
>
> Thanks in advance!
>
> Paulo Alvim/Raphael
> Powerlogic - Brazil
>
> -----Mensagem original-----
> De: Raphael Gallo [mailto:raphael@powerlogic.com.br]
> Enviada em: sexta-feira, 26 de novembro de 2004 17:44
> Para: Tomcat Users List
> Assunto: [work] CLIENT-CERT
>
>
> Hi,
>
>
> It´s possible use FORM authentication and CLIENT-CERT
> in the same
> application. How can I do this ?
>
>
>
> Thanks,
>
> Raphael Gallo
> raphael@powerlogic.com.br
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
bug JDBC Real with CLIENT-CERT
Posted by Paulo Alvim <al...@powerlogic.com.br>.
Hi,
I'm trying to use Client-Cert authentication with Tomcat 5.0.28. I could
make it work using Memory Realm but when I changed to JDBCRealm I received
an authorization error...
In truth, it seems that there's a bug with Client-Cert and others Realm
since 4.x.
I've just read about that in a few links:
http://issues.apache.org/bugzilla/show_bug.cgi?id=30352
http://www.junlu.com/msg/43156.html
Anyone could update that information? Is there any fix or patchs in Tomcat
5.0.28? I'll need to use it with JDBCRealm and with LDAP (Active
Directory)...
Thanks a lot!
Paulo Alvim
Powerlogic - Brazil
-----Mensagem original-----
De: Paulo Alvim [mailto:alvim@powerlogic.com.br]
Enviada em: sábado, 27 de novembro de 2004 14:20
Para: Tomcat Users List
Assunto: RES: [work] CLIENT-CERT
Hi,
The questions are:
1. Is it possible to use two authentication methods (FORM and CLIENT_CERT)
in the same J2EE application?
2. If so, how could we do it in Tomcat 5.0.19?
Thanks in advance!
Paulo Alvim/Raphael
Powerlogic - Brazil
-----Mensagem original-----
De: Raphael Gallo [mailto:raphael@powerlogic.com.br]
Enviada em: sexta-feira, 26 de novembro de 2004 17:44
Para: Tomcat Users List
Assunto: [work] CLIENT-CERT
Hi,
It´s possible use FORM authentication and CLIENT-CERT in the same
application. How can I do this ?
Thanks,
Raphael Gallo
raphael@powerlogic.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RES: [work] CLIENT-CERT
Posted by Paulo Alvim <al...@powerlogic.com.br>.
Hi,
The questions are:
1. Is it possible to use two authentication methods (FORM and CLIENT_CERT)
in the same J2EE application?
2. If so, how could we do it in Tomcat 5.0.19?
Thanks in advance!
Paulo Alvim/Raphael
Powerlogic - Brazil
-----Mensagem original-----
De: Raphael Gallo [mailto:raphael@powerlogic.com.br]
Enviada em: sexta-feira, 26 de novembro de 2004 17:44
Para: Tomcat Users List
Assunto: [work] CLIENT-CERT
Hi,
It´s possible use FORM authentication and CLIENT-CERT in the same
application. How can I do this ?
Thanks,
Raphael Gallo
raphael@powerlogic.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
CLIENT-CERT
Posted by Raphael Gallo <ra...@powerlogic.com.br>.
Hi,
It´s possible use FORM authentication and CLIENT-CERT in the same
application. How can I do this ?
Thanks,
Raphael Gallo
raphael@powerlogic.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Tomcat 4.1: Setting Up Connection Pooling, Adding Resource to
server.xml,
Posted by David Stevenson <ds...@rochester.rr.com>.
I missed the following important information that was in the Tomcat
documentation, that wasn't in the book I was reading. I am currently
getting the following exception in my log file when executing a servlet
that obtains a DataSource using the JNDI InitialContext. I previously
thought it might be a class not defined exception because I didn't
supply the connection pooling .jar files as required by the
instructions.
2004-11-26 20:15:24 org.apache.catalina.INVOKER.ClientListPooledServlet:
ClientListPooledServlet.init:
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context
at
org.apache.naming.NamingContext.lookup(NamingContext.java:811)
at
org.apache.naming.NamingContext.lookup(NamingContext.java:194)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at ClientListPooledServlet.init(ClientListPooledServlet.java:25)
>>From ClientListPooledServlet.java. Line 25 is the one with the new
InitialContext () constructor call.
public void init ( ServletConfig config )
throws ServletException
{
super.init ( config ) ;
log ( "ClientListPooledServlet.init entered" ) ;
try
{
// Context initCtx = new InitialContext () ;
// Context envCtx = (Context) initCtx.lookup (
"java:comp/env" ) ;
// ds = (DataSource) envCtx.lookup (
"jdbc/tomcatbook" ) ;
ds = (DataSource) new InitialContext ().lookup (
"java:comp/env/jdbc/tomcatbook" ) ;
}
catch ( Exception e )
{
log ( "ClientListPooledServlet.init: " +
e.getMessage () ) ;
log ( "ClientListPooledServlet.init: ", e ) ;
throw new UnavailableException ( e.getMessage ()
) ;
}
log ( "ClientListPooledServlet.init exiting" ) ;
}
DBCP uses the Jakarta-Commons Database Connection Pool. It relies on
number of Jakarta-Commons componenets:
* Jakarta-Commons DBCP 1.0
* Jakarta-Commons Collections 2.0
* Jakarta-Commons Pool 1.0
These jar files along with your the jar file for your JDBC driver should
be installed in $CATALINA_HOME/common/lib.
I don't know if these versions are close enough, or not.
If not, I can go through the Jakarta Archives looking for
closer versions.
[david@galileo logs]$ ll -rt $CATALINA_HOME/common/lib
...
-rw-r--r-- 1 david stevenson 175426 Nov 26 20:06
commons-collections-2.1.1.jar
-rw-r--r-- 1 david stevenson 42492 Nov 26 20:06
commons-pool-1.2.jar
-rw-r--r-- 1 david stevenson 107631 Nov 26 20:08
commons-dbcp-1.2.1.jar
Based on the Tomcat Documentation, I revamped the server.xml
configuration (I haven't modified this yet to include the
instructions under Preventing dB connection pool leaks in
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html).
<Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true"
crossContext="false" debug="9" docBase="tomcatbook"
mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/tomcatbook" privileged="false" reloadable="true"
swallowOutput="false"
useNaming="false"
wrapperClass="org.apache.catalina.core.StandardWrapper"
displayName="Mastering Tomcat Development"
>
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_tomcatbook_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/tomcatbook" auth="Container"
type="javax.sql.DataSource" >
<ResourceParams name="jdbc/tomcatbook">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>tomcat</value>
</parameter>
<parameter>
<name>password</name>
<value>RealPasswordOmitted</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/tomcatbook?autoReconnect=true</value>
</parameter>
</ResourceParams>
</Resource>
</Context>
$ more $CATALINA_HOME/webapps/tomcatbook/WEB-INF/web.xml
...
<resource-ref>
<description>
This is a reference to the data source we use
to talk to the database configured in the
server.xml file.
</description>
<res-ref-name>jdbc/tomcatbook</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
=============================================================
Server Information
Tomcat Version Apache Tomcat/4.1.24-LE-jdk14
JVM Version 1.4.2-b28
JVM Vendor Sun Microsystems Inc.
OS Name Linux
OS Version 2.4.20-31.9
OS Architecture i386
MySQL mysql-standard-4.0.18-pc-linux-i686
mysql-connector-java-3.0.11-stable
=============================================================
David Stevenson
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org