• Post Reply Bookmark Topic Watch Topic
  • New Topic

NoInitialContextException  RSS feed

 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a junit test class for a stateless ejb that access another stateless ejb. I have this error when I try to bind the class manually to jndi from the test.


my code is as follows..


is there any thing else that I need to do.

could somebody please help me..

thanks..
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanth,

You will have to place a jndi.properties file in the JUnit test client's classpath, with appropriate server specific entries in that file. These properties will be required to create the InitialContext. The file contents are application server specific. Which application server are you using?

The other option is to pass these properties through the InitialContext's constructor which accepts a Hashtable.
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jai,
I am using Jboss I tried to pass the property values but that did not work..

caould you please help me with an example...

Thanks,
Samanth..
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Another option can be writing a Cactus test instead of JUnit which will run on the server side. Extend the ServletTestCase for this while writing the test case class.

regards,
amit
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jai,
This is what I get when I do what you said..

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]



please correct if I am doing something wrong here...
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samanth,

If you are using JBoss, then the property values that you passed were incorrect. Have a look at I get NoInitialContextException for the correct values.



And make sure you have the JBoss related jar file(s) in the client classpath. I usually place the jbossall-client.jar (which you can find in the %JBOSS_HOME%/client folder) in the client classpath. That jar has all required JBoss specific class files to be used by the client.
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Thanks for your valuable information. I never needed to bind the ejb to jndi because I was using EJB3.0 and all I needed was to inject the ejb object into the other ejb and get that object, because I lookup based on the condition that the object is null if it is not null then I just return the object.

Thanks once again...

Samanth.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!