• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB problem in JNDI lookup

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
G'day
Just doing self study on EJB base on "Head First EJB", and I face a problem on page Page 58 in JNDI when create EJB client. Pls help.
The EJB session bean deploy success to SUN App server, problem I face is the client to connect it via JNDI.
Context ic = new InitialContext();
Object o = ic.lookup("Advisor");
Well, first of all, it complain:
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(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:32)
at AdviceClient.main(AdviceClient.java:26)
Then I find out actulay it looking for jndi.properties from classpath. Then beside j2ee.jar, I also put the appserv-rt.jar from %J2EE_HOME%/lib to class path.
Note: appserv-rt.jar contain jndi.properties which contain below 2 line:
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
The problem temp solve, but it give me anotehr exception, seem like it having connect failure cause can't find SerialContextProvider.
Any help?
May 11, 2004 11:52:22 PM com.sun.corba.ee.impl.legacy.connection.SocketFactoryConnectionImpl <init>
WARNING: ORBUTIL.connectFailure
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:1739)
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:1757)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryConnectionImpl.<init>(SocketFactoryConnectionImpl.java:74)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryContactInfoImpl.createConnection(SocketFactoryContactInfoImpl.java:77)
at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:152)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:121)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:214)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:112)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:58)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:126)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:39)
at AdviceClient.main(AdviceClient.java:26)
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:520)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryConnectionImpl.<init>(SocketFactoryConnectionImpl.java:58)
... 11 more
Caused by: java.net.ConnectException: Connection refused: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:460)
at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:511)
... 12 more
javax.naming.CommunicationException: Can't find SerialContextProvider [Root exception is org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No]
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:66)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:126)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at AdviceClient.go(AdviceClient.java:39)
at AdviceClient.main(AdviceClient.java:26)
Caused by: org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:1739)
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:1757)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryConnectionImpl.<init>(SocketFactoryConnectionImpl.java:74)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryContactInfoImpl.createConnection(SocketFactoryContactInfoImpl.java:77)
at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:152)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:121)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:214)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:112)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:58)
... 4 more
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:520)
at com.sun.corba.ee.impl.legacy.connection.SocketFactoryConnectionImpl.<init>(SocketFactoryConnectionImpl.java:58)
... 11 more
Caused by: java.net.ConnectException: Connection refused: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:460)
at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:511)
... 12 more
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You got the first exception because you were not specifying the properties which are needed to create initial context. But you have figured it out. But you still haven't specified the provider URL. You can probably do it the way I have shown below or by setting it in properties file.

Hashtable namingEnvironment = new Hashtable();
namingEnvironment.put( DirContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
namingEnvironment.put(
DirContext.PROVIDER_URL, "localhost:1099");
Context ic = new InitialContext(namingEnvironment);
But the second exception you are getting is because the Context factory which you have specified is probably not supported by your application server. Kindly find out from the server docs what naming service it supports. For a jboss server you can use the factory class which I have specified.
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx for reply
U means difference app server will require differece lookup patter?
The lookup I follow the book 'Head First EJB", and I just new to EJB so I not very familiar with that... But that book also seem using Sun One App Server
Well, I using Sun Applicaiton Server version 8 wich came with J2EE SDK. From J2EE tutorial from Sun, the lookup format seem like:
java:comp/env/
I had try but also give connection refuse error.
note: the port I use is 4849 for app server, should I specify this when create context?
Pls help... else I not able continue for "Head First EJB"
Thx
Rgds,
Song Jing
 
Ankur Srivastava
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put only the JNDI lookup specific code in your client program and see if your are able to get the HomeInterface object. This will help us to figure out if it is the lookup issue or something else.
And just make sure that you have put the xml files which contain the lookup information in your jar file.
 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!!!
You must have got a jar file while deploying your bean.
In fact while deploying, the server asks to create one jar file (you have to
check the checkbox)which would be used by ur's client.

This jar file contains the stub implementation code, using which the
client can access the Home.

So just add this jar too , to you classpath...
I hope it will solve your's problem...
or at least you may get another exception
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankur Srivastava and Mishra Anshu,

G'day

Thx for reply and help.

Finaly I had solve the problem yesterday night.

Well, I had include the generated client file to classpath. The problem still there... Anyway I manage to solve it at last. The cause of problem is because:
- I got 2 SUN app server 8 (one came with J2EE and the other is with Sun Java Creator Studio) run in difference port.
- I deploy the EJB session bean to 4849 (the one came with Sun Java Creator Studio). But the jar files (appserv-rt.jar and j2ee.jar) I put in classpath is from the other app server (the one came with J2EE).
- Because the jar files I put in classpath contain jndi.properties and other properties files specific to the second app server, so that why when I run EJB client, it always get connection refuse (because the 4848 app server is not running).

By the way, actualy I also had try to speciify the app server I want to use in JDNI context init, it still not working due to the jar files I mount contain difference app server info?

Anyway, it work now. Thx for help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic