• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Step by steyp JNDI look up with jboss 7.1

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First of all I apologize if this was not the right place to puto this question, I am new to javaranch.
I have eclipse juno and jboss AS 7.1 final running on my machine and configured it through it (eclipse juno). I hava a simple stateless bean and its interface (in fact is exactly the same example from the book Enterprise Java Beans 3.1 6th Edition). Here is the code:

package beans;

public class CalculatorBeanBase implements CalculatorCommonBusiness{

public int add(int[] opers){

int sum = 0;
for(int c:opers){
sum+=c;
}
return sum;
}

}

package beans;

public interface CalculatorCommonBusiness {

public int add(int[] opers);

}

package beans;

public interface CalculatorRemoteBusiness extends CalculatorCommonBusiness {}

package beans;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

@Stateless
@LocalBean
public class SimpleCalculatorBean extends CalculatorBeanBase {}

I am trying to do the following JUnit testing, unfortunately the example mentions something like "using a standard jndi.properties file that we assume to be presente on the classpath" (here is my first problem, I have no idea what this means, I in fact did some research but I cant quite understand how it works, confuses me, and ultimately cant seem to make it work).

package beans;

import javax.naming.Context; import javax.naming.InitialContext;

import junit.framework.TestCase;

import org.junit.BeforeClass; import org.junit.Test;

public class CalculatorIntegrationTestCase {

private static Context namingContext;

private static SimpleCalculatorBean cal;

private static final String JNDI_NAME_CALC = "java:global/jndi.properties/SimpleCalculatorBean";

@BeforeClass
public static void obtainProxyReferences() throws Throwable
{
namingContext = new InitialContext();
cal = (SimpleCalculatorBean)namingContext.lookup(JNDI_NAME_CALC);

}
private void assertAdditionSucceeds(SimpleCalculatorBean cal){

final int[] oper = {2,3,4};
final int expectedSum = 9;
final int actualSum = cal.add(oper);

TestCase.assertEquals("Assert Failed!!. The actual value is not the expected",expectedSum, actualSum);

}
@Test
public void testAdditionUsingBusinessReference() throws Throwable
{
this.assertAdditionSucceeds(cal);
}

}

I need to know how that jndi. properties file works and how I have to set it up. (I read about this last issue, and I got the folloing .txt file and changed its extension to .jar, I dont know if that was right):

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

java.naming.provider.url=jpn://localhost:1099

java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Finally I put that .jar file into the classpath (DonĀ“t know if I did it right: rigth-click on project, build path, libraries, add external jars).

I did all the above stuff but I keep getting the following:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at beans.CalculatorIntegrationTestCase.obtainProxyReferences(CalculatorIntegrationTestCase.java:24) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Of course I published the Project (through eclipse though, project>run>run on server). Help would be appreciated
 
Jhonathan Ibanez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any help?, I'd appreciate it.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic