tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas De Loof" <nicolas.del...@cgey.com>
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 ?

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


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"
                    type="javax.jms.QueueConnexionFactory"/>
          <ResourceParams name="jms/QueueConnexionFactory">
            <parameter>
              <name>factory</name>
              <value>com.cgey.JndiFederationFactory</value>
            </parameter>
            <parameter>
              <name>lookup</name>
              <value>urlQmgrLocal</value>
            </parameter>
            <parameter>
              <name>java.naming.factory.initial</name>
              <value>com.sun.jndi.fscontext.RefFSContextFactory</value>
            </parameter>
            <parameter>
              <name>java.naming.security.authentication</name>
              <value>none</value>
            </parameter>
            <parameter>
              <name>java.naming.provider.url</name>
              <value>file:///c:/MQSeries/jndi</value>
            </parameter>
          </ResourceParams>

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.

Nico.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message