You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Fumo, Vince" <Vi...@acs-inc.com> on 2004/01/30 19:24:31 UTC
DBCP Registering a PoolingDataSource in JNDI
I'm trying to register a valid PoolingDataSource in JNDI using the following
method and code:
private final static String INITIAL_CONTEXT_FACTORY =
"com.sun.jndi.fscontext.RefFSContextFactory";
private final static String FACTORY_URL = "file:/D:/jndi";
public static void register(PoolingDataSource datasource, String
bindName) throws Exception {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, FACTORY_URL);
Context context = null;
try {
context = new InitialContext(env);
}
catch (NamingException e) {
String msg = "Could not initialize the context : " +
e.getMessage();;
_log.error(msg);
e.printStackTrace();
throw new Exception(msg);
}
try {
context.rebind(bindName, datasource);
}
catch (NamingException e) {
String msg = "Could not bind the datasource : " +
e.getMessage();
_log.error(msg);
e.printStackTrace();
throw new Exception(msg);
}
}
The problem happens with the call to context.rebind. Apparantly JNDI is
complaining as follows:
javax.naming.OperationNotSupportedException: Can only bind References or
Referenceable objects
at
com.sun.jndi.fscontext.RefFSContext.addObjectToBindings(RefFSContext.java:47
9)
at
com.sun.jndi.fscontext.RefFSContext.bindObject(RefFSContext.java:337)
at com.sun.jndi.fscontext.RefFSContext.rebind(RefFSContext.java:189)
at com.sun.jndi.fscontext.FSContext.rebind(FSContext.java:194)
at javax.naming.InitialContext.rebind(Unknown Source)
Any ideas on what's wrong?
Vincent Fumo
Software Engineer
ACS State and Local Solutions
Government Systems
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: DBCP Registering a PoolingDataSource in JNDI
Posted by Dirk Verbeeck <di...@pandora.be>.
I created the following subclass:
class ReferencablePoolingDataSource extends PoolingDataSource
implements Referenceable
and the exception goes away.
Tomcat initializas its JNDI tree using a Reference and a
ObjectFactory, that's also a way to do it.
-- Dirk
Fumo, Vince wrote:
> I'm trying to register a valid PoolingDataSource in JNDI using the following
> method and code:
>
> private final static String INITIAL_CONTEXT_FACTORY =
> "com.sun.jndi.fscontext.RefFSContextFactory";
> private final static String FACTORY_URL = "file:/D:/jndi";
>
> public static void register(PoolingDataSource datasource, String
> bindName) throws Exception {
> Hashtable env = new Hashtable();
> env.put(Context.INITIAL_CONTEXT_FACTORY,
> INITIAL_CONTEXT_FACTORY);
> env.put(Context.PROVIDER_URL, FACTORY_URL);
>
> Context context = null;
> try {
> context = new InitialContext(env);
> }
> catch (NamingException e) {
> String msg = "Could not initialize the context : " +
> e.getMessage();;
> _log.error(msg);
> e.printStackTrace();
> throw new Exception(msg);
> }
>
> try {
> context.rebind(bindName, datasource);
> }
> catch (NamingException e) {
> String msg = "Could not bind the datasource : " +
> e.getMessage();
> _log.error(msg);
> e.printStackTrace();
> throw new Exception(msg);
> }
> }
>
> The problem happens with the call to context.rebind. Apparantly JNDI is
> complaining as follows:
>
> javax.naming.OperationNotSupportedException: Can only bind References or
> Referenceable objects
> at
> com.sun.jndi.fscontext.RefFSContext.addObjectToBindings(RefFSContext.java:47
> 9)
> at
> com.sun.jndi.fscontext.RefFSContext.bindObject(RefFSContext.java:337)
> at com.sun.jndi.fscontext.RefFSContext.rebind(RefFSContext.java:189)
> at com.sun.jndi.fscontext.FSContext.rebind(FSContext.java:194)
> at javax.naming.InitialContext.rebind(Unknown Source)
>
> Any ideas on what's wrong?
>
> Vincent Fumo
> Software Engineer
> ACS State and Local Solutions
> Government Systems
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org