Here it is what I've been trying:

1)Resource Factory configuration in tomcat context.xml

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

2)test web application's  web.xml

<resource-env-ref>
  <description>
    Object factory for ResourceBean instances.
  </description>
  <resource-env-ref-name>
     bean/ParamsFactory
  </resource-env-ref-name>
  <resource-env-ref-type>
    sample.jndi.ResourceBean
  </resource-env-ref-type>
</resource-env-ref>


I can look it up successfully from a servlet like this

                Context initCtx = new InitialContext();
                Context envCtx = (Context) initCtx.lookup("java:comp/env");
                ResourceBean bean = (ResourceBean) 
envCtx.lookup("bean/ParamsFactory");


The same look up fails  when performed inside a session bean.

I tried to integrate the declarations in the openejb web module web.xml
descriptor also but with no success.

I didn't do anything like this before in Tomcat or any EJB container but it
looks to me like a clean and portable solution for loading application
configuration parameters which happen to be in xml format.



David Blevins wrote:
> 
> 
> On Aug 7, 2008, at 8:32 AM, lupu.slobodu wrote:
> 
>>
>> I dont know if the custom injection is flexible enough.I need to be  
>> able to
>> load multiple xml configuration files.Is it possible with the custom
>> injection mechanism? If I use the openejb embedded in tomcat,  you  
>> think it
>> is possible to plugin the  ObjectFactory in the tomcat jndi and look  
>> it up
>> from a openejb session bean?
> 
> We've coded up the tomcat integration to be able to support that.  So  
> if you add an ObjectFactory to Tomcat, OpenEJB will pick it up and add  
> it like it was an <Resource> declaration in the openejb.xml file.
> 
> So if you had a META-INF/context.xml file in your webbapp for Tomcat  
> like the following:
> 
> <Context>
>    <Resource
>        name="resourcebean"
>        auth="Container"
>        type="org.superbiz.servlet.ResourceBean"
>        factory="org.apache.naming.factory.BeanFactory"
>        value="ContextResource"/>
> </Context>
> 
> You should be able to have it injected like so:
> 
>    @Resource ResourceBean byBean;
> 
> Let us know if that does or doesn't work.  We need more examples of  
> this.
> 
> As a side question, are you currently doing something like this in  
> Tomcat now or are you looking for a more general purpose "define  
> objects in xml and inject them" solution?  We've had some ideas in  
> this area.
> 
> 
> -David
> 
> 
>>
>>
>> David Blevins wrote:
>>>
>>>
>>> On Aug 6, 2008, at 7:54 AM, lupu.slobodu wrote:
>>>
>>>> How can one configure a custom resource factory(implementation of  
>>>> the
>>>> javax.naming.spi.ObjectFactory interface). The custom resource  
>>>> factory
>>>> should be injectable into a stateless.
>>>
>>> We don't have anything for pluging in an
>>> javax.naming.spi.ObjectFactory, but we do have the ability for you to
>>> plug in your own java.beans.PropertyEditor and have custom resources
>>> injected that way.
>>>
>>> See this example for details:
>>> http://openejb.apache.org/3.0/custom-injection.html
>>>
>>> -David
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Custom-Resource-Factory-tp18852971p18873168.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Custom-Resource-Factory-tp18852971p18896653.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to