I kind of succeeded solving this by defining a new service provider, so my
resource gets injected.
Maybe I didn't do it quite right though, because it works only if I declare
my to be injected property of type java.lang.Object like this:
@Resource(name = "configParams")
public Object configParams;
The actual injected value is still of type sample.jndi.ResourceBean.
If I declare the injected property consistent with the type of the injected
value like this:
@Resource(name = "configParams")
public sample.jndi.ResourceBean configParams;
it fails like below
javax.ejb.EJBException: An unexpected exception occured while invoking the
setSessionContext method on the Stateful SessionBean instance; nested
exception is:
org.apache.xbean.recipe.MissingAccessorException:
org.apache.xbean.recipe.StaticRecipe can not be assigned or converted to
sample.jndi.ResourceBean: public sample.jndi.ResourceBean
sample.CalculatorImpl.configParams
at
org.apache.openejb.core.ivm.EjbHomeProxyHandler._invoke(EjbHomeProxyHandler.java:213)
at
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:321)
at
org.apache.openejb.util.proxy.Jdk13InvocationHandler.invoke(Jdk13InvocationHandler.java:49)
at $Proxy42.create(Unknown Source)
at
org.apache.openejb.core.ivm.naming.BusinessLocalReference.getObject(BusinessLocalReference.java:33)
at
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:150)
at javax.naming.InitialContext.lookup(Unknown Source)
this is my service provider definition
<ServiceProvider id="Default Params"
service="Resource"
types="sample.jndi.ResourceBean, ResourceBean"
factory-name="create"
class-name="sample.jndi.GenericObjectFactory">
</ServiceProvider>
and here the deploy config
<Resource id="configParams" type="sample.jndi.ResourceBean">
</Resource>
David Blevins wrote:
>
>
> On Aug 19, 2008, at 2:56 PM, lupu.slobodu wrote:
>
>>
>> I am not sure about this, but it looks like the container is
>> checking for a
>> service provider definition in service-jar.xml compatible with my
>> type(that
>> would be "sample.jndi.ResourceBean")
>
> We definitely do do that. But we only do that as a fallback if we
> can't find an already configured <Resource> that supplies the type you
> need (in this case sample.jndi.ResourceBean). 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?)
>
> Theoretically if it was imported by OpenEJB it would show up under
> java:openejb/Resource/. You might try listing that context and seeing
> if it's there.
>
> Here's a neat little chunk of code to help:
>
> public static void contextToMap(Context context, String baseName,
> Map<String,Object> results) throws NamingException {
> NamingEnumeration<Binding> namingEnumeration =
> context.listBindings("");
> while (namingEnumeration.hasMoreElements()) {
> Binding binding = namingEnumeration.nextElement();
> String name = binding.getName();
> String fullName = baseName + name;
> Object object = binding.getObject();
> results.put(fullName, object);
> if (object instanceof Context) {
> contextToMap((Context) object, fullName + "/",
> results);
> }
> }
> }
>
> Hopefully I can poke at this Friday.
>
> -David
>
>
>>
>> David Blevins wrote:
>>>
>>> That definitely should work. Let me see if I can't reproduce this.
>>>
>>> -David
>>>
>>> On Aug 12, 2008, at 1:45 PM, lupu.slobodu wrote:
>>>
>>>>
>>>> If I declare my session bean in ejb-jar.xml, together with the
>>>> resource-env-ref like this
>>>>
>>>> <session>
>>>> <ejb-name>CalculatorImpl</ejb-name>
>>>> <business-local>sample.CalculatorLocal</business-local>
>>>> <ejb-class>sample.CalculatorImpl</ejb-class>
>>>> <transaction-type>Container</transaction-type>
>>>>
>>>> <resource-env-ref>
>>>> <description>
>>>> Object factory for MyBean 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>
>>>> </session>
>>>>
>>>>
>>>> it crashes at deploy time like this:
>>>>
>>>> org.apache.openejb.OpenEJBException: No provider available for
>>>> resource-ref
>>>> 'null' of type 'sample.jndi.ResourceBean' for 'CalculatorImpl'.
>>>> at
>>>> org
>>>> .apache
>>>> .openejb.config.AutoConfig.autoCreateResource(AutoConfig.java:
>>>> 1292)
>>>> at
>>>> org.apache.openejb.config.AutoConfig.getResourceId(AutoConfig.java:
>>>> 1285)
>>>> at
>>>> org.apache.openejb.config.AutoConfig.getResourceId(AutoConfig.java:
>>>> 1236)
>>>> at
>>>> org
>>>> .apache
>>>> .openejb.config.AutoConfig.processResourceRef(AutoConfig.java:
>>>> 781)
>>>> at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:706)
>>>> at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:133)
>>>> at
>>>> org.apache.openejb.config.ConfigurationFactory
>>>> $Chain.deploy(ConfigurationFactory.java:148)
>>>> at
>>>> org
>>>> .apache
>>>> .openejb
>>>> .config
>>>> .ConfigurationFactory
>>>> .configureApplication(ConfigurationFactory.java:
>>>> 440)
>>>> at
>>>> org
>>>> .apache
>>>> .openejb
>>>> .tomcat.catalina.TomcatWebAppBuilder.start(TomcatWebAppBuilder.java:
>>>> 233)
>>>> at
>>>> org
>>>> .apache
>>>> .openejb
>>>> .tomcat
>>>> .catalina
>>>> .GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:58)
>>>> at
>>>> org
>>>> .apache
>>>> .catalina
>>>> .util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>>>> at
>>>> org.apache.catalina.core.StandardContext.start(StandardContext.java:
>>>> 4252)
>>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
>>>> 1045)
>>>> at org.apache.catalina.core.StandardHost.start(StandardHost.java:
>>>> 719)
>>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:
>>>> 1045)
>>>> at
>>>> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:
>>>> 443)
>>>> at
>>>> org.apache.catalina.core.StandardService.start(StandardService.java:
>>>> 516)
>>>> at
>>>> org.apache.catalina.core.StandardServer.start(StandardServer.java:
>>>> 710)
>>>> at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>>>> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>>>>
>>>> David Blevins wrote:
>>>>>
>>>>>
>>>>> On Aug 8, 2008, at 11:11 AM, lupu.slobodu wrote:
>>>>>
>>>>>>
>>>>>> 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.
>>>>>
>>>>> If you can look it up from a Servlet, we're not too far! Post the
>>>>> ejb-
>>>>> jar.xml you using if you can. You would need an identical
>>>>> resource-
>>>>> env-ref in there for your session bean.
>>>>>
>>>>> -David
>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Custom-Resource-Factory-tp18852971p18952298.html
>>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Custom-Resource-Factory-tp18852971p19059489.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
>
>
>
--
View this message in context:
http://www.nabble.com/Custom-Resource-Factory-tp18852971p19106570.html
Sent from the OpenEJB User mailing list archive at Nabble.com.