On Jun 18, 2009, at 2:42 PM, Allan Lykke Christensen wrote:

Hi all,

I've just started using OpenEJB 3.1.1 for unit testing an EJB3 Maven project that will be deployed in a GlassFish environment. OpenEJB has really simplified unit testing of EJB3s and will be saving me a lot of time in the future, however I've run into a problem when testing code using LDAP connections.

Problem: In one of my stateless bean I'm injecting an LDAP connection (DirContext) that is registered with a JNDI name in GlassFish:

@Resource(name = "ldap/userDirectory")
private DirContext ldapConn;

Whenever I run a unit test with the above code I get the following error:

WARN - Jar not loaded. classpath.ear. No provider available for resource-ref 'null' of type 'javax.naming.directory.DirContext' for 'UserServiceBean'. org.apache.openejb.OpenEJBException: No provider available for resource-ref 'null' of type 'javax.naming.directory.DirContext' for 'UserServiceBean'. at org .apache.openejb.config.AutoConfig.autoCreateResource(AutoConfig.java: 1342) at org.apache.openejb.config.AutoConfig.getResourceId(AutoConfig.java: 1335) at org.apache.openejb.config.AutoConfig.getResourceId(AutoConfig.java: 1286) at org .apache.openejb.config.AutoConfig.processResourceRef(AutoConfig.java: 799) at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:724) at org.apache.openejb.config.AutoConfig.deploy(AutoConfig.java:133) at org.apache.openejb.config.ConfigurationFactory $Chain.deploy(ConfigurationFactory.java:247) at org .apache .openejb .config .ConfigurationFactory.configureApplication(ConfigurationFactory.java: 601) at org .apache .openejb .config .ConfigurationFactory.configureApplication(ConfigurationFactory.java: 551) at org .apache .openejb .config .ConfigurationFactory .getOpenEjbConfiguration(ConfigurationFactory.java:380) at org .apache .openejb .assembler.classic.Assembler.getOpenEjbConfiguration(Assembler.java: 292) at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java: 271)
       at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:137)
       at org.apache.openejb.OpenEJB.init(OpenEJB.java:286)
       at org.apache.openejb.OpenEJB.init(OpenEJB.java:265)

I tried looking into ways of injecting the DirContext, but with no luck.

Anybody know how to go about this? Any help is much appreciated.

Hi Allen,

DirContext isn't one of the required java ee types such as DataSource or UserTransaction, so I'm guessing that there must be some sort of LDAP J2EE Connector for it. If that's the case it should be easy to hook up in OpenEJB as well. If not then it's a vendor specific feature, which we'd be more than happy to support as well provided we can get enough information on how it should work so we can code it up.

Let us know.

-David

PS Thanks for the tweet!

Reply via email to