tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zsolt Koppany" <>
Subject How to start a Realm from a servlet or a filter
Date Fri, 09 Apr 2004 08:49:20 GMT

because of technical reasons I want to start a Realm class during run-time,
thus I cannot just configure Realm via "<Realm...". When I try to start
MemoryRealm I get a null pointer exception, because the container of Realm
is not set. The application does work (because I catch the exception) but I
would like to start Realm correctly.

What is wrong in my example?

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

Object realm_instance = envCtx.lookup("realm/RealmFactory");"Realm class: " + realm_instance.getClass().getName());
Realm rlm = (Realm)realm_instance;
if (rlm instanceof Lifecycle)
	// rlm.setContainer(...);		Is that the problem????
	((Lifecycle) rlm).start();
catch (Exception e)
	log.error("LifecycleException (start): " + e.getMessage(), e);

Here is my web-application configuration file:

<Context path="/cb" docBase="cb" debug="0" reloadable="true">
    <Resources className="org.apache.naming.resources.FileDirContext"
allowLinking="false" />

    <Resource name="realm/RealmFactory" auth="Container"
    <ResourceParams name="realm/RealmFactory">


Zsolt Koppany
Phone: +49-711-722 1874
Intland Software GmbH, Schulze-Delitzsch-Strasse 16
D-70565 Stuttgart, Germany
Phone: +49-711-722 1873,
Fax: +49-711-722 1835

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message