Re: Custom Resource Factory

2008-08-23 Thread Dain Sundstrom

On Aug 22, 2008, at 4:30 PM, Dain Sundstrom wrote:


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.


Implemented.  Here is an example message from the openejb.log file:

2008-08-23 16:01:28,113 - INFO  - Importing a Tomcat Resource with id  
'UserDatabase' of type 'org.apache.catalina.UserDatabase'.



As for the other problem we are only importing global resources.   
It is a bit more tricky to import application level resources, because  
Tomcat does not differentiate between actual resource instances and  
references to global resources.  I'll take a look at that next week,  
unless someone else beats me to it.


-dain


Re: Custom Resource Factory

2008-08-22 Thread Dain Sundstrom

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



Re: Custom Resource Factory

2008-08-19 Thread lupu.slobodu

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) 
Is there a chance that I could add such a definition?


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-nameCalculatorImpl/ejb-name
business-localsample.CalculatorLocal/business-local
ejb-classsample.CalculatorImpl/ejb-class
transaction-typeContainer/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.

 

Re: Custom Resource Factory

2008-08-12 Thread lupu.slobodu

If I declare my session bean in ejb-jar.xml, together with the
resource-env-ref like this

session
ejb-nameCalculatorImpl/ejb-name
business-localsample.CalculatorLocal/business-local
ejb-classsample.CalculatorImpl/ejb-class
transaction-typeContainer/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.



Re: Custom Resource Factory

2008-08-12 Thread David Blevins

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-nameCalculatorImpl/ejb-name
   business-localsample.CalculatorLocal/business-local
   ejb-classsample.CalculatorImpl/ejb-class
   transaction-typeContainer/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.






Re: Custom Resource Factory

2008-08-11 Thread David Blevins


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