I have defined my datasource parameters in context.xml. I've
initialized the datasource objects
in the constructor where I need them. I'm using Tomcat 5.5.17.
As I have experienced the constructor does not get activated when a
object is replicated, so
my idea is to implement readObject() for initializing of the datasource
in the replicated
object. But I don't get access to what is defined in context.xml, only
to what is defined
in server.xml. It looks like this is not what I should expect. So I
wonder if there is a
different approach to initialize datasource in a replicated object.
One solution would be to put the contents of context.xml into
server.xml, but I
don't quite like the sound of that.
I hope some can enlighten me on this.
Regards
Dag Bjerkeli
Here is some output to illustrate the problem:
Output in tomcat1 when a object is constructed:
DB:: DataLogDAO constructor
DB:: Got context java:
DB:: got name comp
Output in tomcat2 when object is replicated:
DB:: DataLogDAO readObject
DB:: Got context java:
DB:: got name UserDatabase
DB:: got name jdbc
DB:: got name simpleValue
DB:: Err with context Name comp is not bound in this Context
javax.naming.NameNotFoundException: Name comp is not bound in this Context
The relevant code in class DataLogDAO:
private transient DataSource dsR = null;
private transient DataSource dsW = null;
public DataLogDAO() throws Exception {
System.out.println("DB:: DataLogDAO constructor ");
this.generateConnections();
}
private void readObject(java.io.ObjectInputStream in) throws
IOException, ClassNotFoundException {
System.out.println("DB:: DataLogDAO readObject");
in.defaultReadObject();
try {
this.generateConnections();
} catch(Exception e) {
System.out.println("DB:: Err with context " + e.getMessage());
e.printStackTrace();
}
}
private void generateConnections() throws Exception {
if( dsR == null) {
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
String ctxname = ctx.getNameInNamespace();
System.out.println("DB:: Got context " + ctxname);
NamingEnumeration en = ctx.listBindings(ctxname);
while ( en.hasMore()) {
Binding b = (Binding) en.next();
System.out.println("DB:: got name " + b.getName());
}
dsR = (DataSource) ctx.lookup(IConstants.DATASOURCE_READER);
dsW = (DataSource) ctx.lookup(IConstants.DATASOURCE_WRITER);
}
}
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]