On Aug 20, 2008, at 6:47 PM, David Blevins wrote:

When webbaps boot, we export all the Tomcat configured resources as OpenEJB <Resource> objects so they are available for injection. What we don't do is log a message when we do that which would be really handy right now.... at least I don't think we do (maybe on debug?)

I'll implement that this weekend when I take a look at the other Tomcat bugs.

<Resource
   name="bean/ParamsFactory"
   auth="Container"
   type="sample.jndi.ResourceBean"
   factory="sample.jndi.GenericObjectFactory"
                value="ContextResource"
   />

This is the code we use when importing resources into OpenEJB:

    public void addResource(ContextResource resource) {
        try {
Context globalNamingContext = standardServer.getGlobalNamingContext(); Object value = globalNamingContext.lookup(resource.getName());
            String type = resource.getType();
            bindResource(resource.getName(), value, type);
        } catch (NamingException e) {
logger.error("Unable to lookup Global Tomcat resource " + resource.getName(), e);
        }
    }

    private void bindResource(String name, Object value, String type) {
        ResourceInfo resourceInfo = new ResourceInfo();
        resourceInfo.id = name;
        resourceInfo.service = "Resource";
        resourceInfo.types.add(type);
        PassthroughFactory.add(resourceInfo, value);
Assembler assembler = (Assembler) SystemInstance .get().getComponent(org.apache.openejb.spi.Assembler.class);

        try {
            assembler.createResource(resourceInfo);
        } catch (OpenEJBException e) {
logger.error("Unable to bind Global Tomcat resource " + name + " into OpenEJB", e);
        }
    }

So the resource ID should be the name of the resource in the Tomcat resource declaration, and the type we use for auto match should be the type from the Tomcat resource declaration. One complication I don't remember testing for is that this resource uses an ObjectFactory. Now that I think about it, maybe we should delay lookup in the Tomcat JNDI tree until the resource is lookup in our JNDI.

Is there is JIRA or test case for this?

-dain

Reply via email to