tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas De Loof" <>
Subject Re: howto federate tomcat JNDI to another JNDI context ?
Date Tue, 27 Jan 2004 13:39:46 GMT
Hi mark,

I solved my JNDI federation problem and maybe you are interested to know how ?

    I want to get JMS ressources from JNDI. They're stored in a FileSystem JNDI
    and I need to federate it to Tomcat JNDI.

I added a custom factory to tomcat (in commons/classes):

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;

public class JndiFederationFactory implements ObjectFactory {

  public Object getObjectInstance(
        Object obj,
        Name name,
        Context nameCtx,
        Hashtable environment)
      throws NamingException {

      Reference ref = (Reference) obj;
      Enumeration addrs = ref.getAll();
      String lookup = null;
      Properties props = new Properties();
      while (addrs.hasMoreElements()) {
          RefAddr addr = (RefAddr) addrs.nextElement();
          String type = addr.getType();
          String value = (String) addr.getContent();
          if (type.equals("lookup")) {
              lookup = value;
          } else {
              props.put(type, value);
      InitialContext ctx = new InitialContext(props);
      if (lookup == null) {
        throw new NamingException("la propriété lookup doit être définie");
      return ctx.lookup(lookup);

I added IBM MQSeries/JMS client classes to commons/lib

I added this conf in server.xml :

          <Resource name="jms/QueueConnexionFactory" auth="Container"
          <ResourceParams name="jms/QueueConnexionFactory">

Using this, I can lookup in local JNDI from my webapp for "jms/QueueConnexionFactory" and
get the MQSeries
QueueConnexionFactory defined in a FileSystem JNDI Context. This is a pseudo JNDI Federation,
but it works fine.


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

View raw message