ejb test client problem with context and lookup

What can i do in this situation? (I use Sun Application Server 8.1) :

In this piece of code in a ejb test client:

Hashtable env =new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");

env.put(Context.PROVIDER_URL,"iiop://127.0.0.1:4700");

//get naming context

Context context =new InitialContext(env);

//look up jndi name

Object ref = context.lookup("JNDIName");

I have an error in a lookup, and i tried ejb/JNDIName, java:comp/env/ejb/JNDIName but ... the error is in all situations:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]

at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:44)

at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:453)

at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:492)-- Failed initializing bean access.

Thanks

[1218 byte] By [santiago747a] at [2007-10-2 13:11:39]
# 1

It looks like your JNDI name is not bound in the context. Some entities registered in JNDI (like DataSources, for example) might be visible only if you're running inside the same JVM as the JNDI directory (in-memory JNDI). DataSources created in Tomcat container are visible only to servlets deployed there, for example. External client will not see them.

If you want to see what's available in your JNDI registry use this code:

public void listJndiTree(InitialContext context,String root) {

NamingEnumeration<NameClassPair> list;

NameClassPair pair;

try {

list = context.list(root);

if (list != null) {

while (list.hasMore()) {

pair = list.next();

System.out.println("name="+pair.getName());

System.out.println("class="+pair.getClassName());

}

}

} catch (Exception x) {

x.printStackTrace();

}

}

Call this method after you create JNDI context (before lookup). Empty root string should print all entities at root level, then "ejb" should print everything in ejb/*, etc.

HTH,

Mark

markcitizena at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

We recommend using the no-arg InitialContext constructor when writing a stand-alone client that accesses EJBs within SUN AS 8.x.As long as appserv-rt.jar is in your client's classpath, the correct naming provider will be bootstrapped. You can set

-Dorg.omg.CORBA.ORBInitialHost=<host> and

-Dorg.omg.CORBA.ORBInitialPort=<port>

when starting the client JVM.These default to localhost and 3700.

Accessing the java:comp/env context would only work from within a J2EE component. A stand-alone java client is not portable and doesn't have access to a J2EE component environment, so its only option is to access the global JNDI name of the remote ejb.

--ken

ksaksa at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi Ken thanks for answer me. but i tried to use the no arg initial context :

Context context = new InitialContext();

Object ref = context.lookup("JNDIName");

I have an error in the lookup, using sun application server 8.1:

com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl <init>

WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700"

org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No

santiago747a at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Mark, I use this method but my jndi name isn磘 in the jndi memory. What can i do to include my jndi in the memory?Thanks
santiago747a at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

> Hi Ken thanks for answer me. but i tried to use the

> no arg initial context :

> Context context = new InitialContext();

> Object ref = context.lookup("JNDIName");

>

> I have an error in the lookup, using sun application

> server 8.1:

Double-check that the server is running. If so, is it running on the

same machine as the client? Also double-check the port number of

the orb's naming service in the server by looking in

domains/domain1/config/domain.xml. You should see a line that

looks like :

<iiop-listener address="0.0.0.0" enabled="true" id="orb-listener-1" port="3700" security-enabled="false"/>

The default port is 3700 but if the number you have is different you'll

need to specify it as a -D property when starting the client JVM. Assuming

your port is 3800 and the server is running on host Foo, add the following

two properties to the java command that starts your client :

-Dorg.omg.CORBA.ORBInitialHost=Foo

-Dorg.omg.CORBA.ORBInitialPort=3800

--ken

>

> com.sun.corba.ee.impl.transport.SocketOrChannelConnect

> ionImpl <init>

>

> WARNING: "IOP00410201: (COMM_FAILURE) Connection

> failure: socketType: IIOP_CLEAR_TEXT; hostname:

> localhost; port: 3700"

>

> org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code:

> 201 completed: No

ksaksa at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Hi Ken, I use the port 3700 in the domain.xml, but now, the problem is that:

javax.naming.NameNotFoundException: JNDIName not found

at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:185)

at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:157)

at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:101)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)-- Failed initializing bean access.

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:123)

at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:648)

at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:192)

at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1709)

at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1569)

at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:951)

at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:181)

at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:721)

at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:469)

at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1258)

at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:409)

-- Initializing bean access.

What can i do to include my jndi name?

santiago747a at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

Hi Santiago,

Did your ejb application successfully deploy? What is the jndi-name of the Remote ejb you are attempting to lookup?It should be specified in the jndi-name element of the sun-ejb-jar.xml packaged within your ejb-jar. Here's an example :

<sun-ejb-jar>

<enterprise-beans>

<ejb>

<ejb-name>FooBean</ejb-name>

<jndi-name>ejb/FooBean</jndi-name>

</ejb>

</enterprise-beans>

</sun-ejb-jar>

There is no defaulting of jndi-names in AS 8.x.In AS 9.x, available via Glassfish and the recently released beta version of the Java EE 5 SDK, the ejb container will default the

jndi-name of an ejb to the fully-qualified name of its Home interface.

--ken

ksaksa at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
Hi Ken.My application deploy successfully, and I check the sun-ejb-jar.xml and my jndi name is in the file. .... I tried to create another ejb in the same project but i have the same problem, what can i do?Thanks
santiago747a at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

Please post your sun-ejb-jar.xml and the source code for the lookup portion of your client program.

You can also check the admin console through your browser at <server_host>:4848. Click on

Application Server. There's a JNDI Browsing tab under the General tab that should show all the global jndi names known to the app server.

ksaksa at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10

this is the code:

public void initialize() {

long startTime = 0;

if (logging) {

log("Initializing bean access.");

startTime = System.currentTimeMillis();

}

try {

//get naming context

Context context = new InitialContext();

//look up jndi name

Object ref = context.lookup("Prueba");

//look up jndi name and cast to Home interface

pruebaHome = (PruebaHome) PortableRemoteObject.narrow(ref,

PruebaHome.class);

if (logging) {

log(

"Succeeded initializing bean access through Home interface.");

long endTime = System.currentTimeMillis();

log("Execution time: " + (endTime - startTime) + " ms.");

}

} catch (Exception e) {

if (logging) {

log("Failed initializing bean access.");

}

e.printStackTrace();

}

}

And this is the sun-ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_2_1-1.dtd">

<sun-ejb-jar>

<enterprise-beans>

<unique-id>0</unique-id>

<ejb>

<ejb-name>Prueba</ejb-name>

<jndi-name>Prueba</jndi-name>

<pass-by-reference>false</pass-by-reference>

<is-read-only-bean>false</is-read-only-bean>

<refresh-period-in-seconds>-1</refresh-period-in-seconds>

<cmt-timeout-in-seconds>0</cmt-timeout-in-seconds>

<gen-classes/>

</ejb>

</enterprise-beans>

</sun-ejb-jar>

santiago747a at 2007-7-13 10:40:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...