my dog learned polymorphism*
The moose likes JBoss/WildFly and the fly likes Step by steyp JNDI look up with jboss 7.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Step by steyp JNDI look up with jboss 7.1" Watch "Step by steyp JNDI look up with jboss 7.1" New topic
Author

Step by steyp JNDI look up with jboss 7.1

Jhonathan Ibanez
Greenhorn

Joined: Dec 17, 2012
Posts: 2

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 cpers){
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.namingrg.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

Joined: Dec 17, 2012
Posts: 2
Any help?, I'd appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Step by steyp JNDI look up with jboss 7.1