File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes PLEASE, I need help with this.............. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "PLEASE, I need help with this.............." Watch "PLEASE, I need help with this.............." New topic

PLEASE, I need help with this..............

Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Anybody!!! Please help me with this......

See this Previous Post
Still Struggling,
Tualha Khan

SCJP2, BEA WLS 6.0, DB2 UDB 7.1
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Tualha,
How about this?
Properties env = new java.util.Properties();
env.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url", "iiop://" + host + ":"+port);
InitialContext initial = new javax.naming.InitialContext(env);
Object objref = ic.lookup("DisplayJNDI");

I really hope this works.

Shin Hashitani

/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> *<br /> * <a href="" target="_blank" rel="nofollow"></a><br />*/
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
OK, Thanks a tonne, I will try this once I reach my home in the evening. But where do I read all this stuff from? Is it in some document or in some tutorial, or on some site?
Thanks & Bye,
Tualha Khan
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Shin!! I am sorry to say but I did not see the face of success after coding the servlet the way you told me. Here is my servlet code snippet: (below that is the exception trace)
System.out.println("Servlet Entered");
System.out.println("HTML Content Type Set");
System.out.println("PrintWriter Object Created");
Properties p=new Properties();
p.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
System.out.println("p.put(1) Created");
p.put("java.naming.provider.url", "iiop://localhost:1050");
System.out.println("p.put(2) Created");
InitialContext initial=new InitialContext(p);
System.out.println("Context Object Created");
Object objref=initial.lookup("DisplayWEBJNDI");
System.out.println("Lookup Done Successfully");
DisplayHome home=(DisplayHome)PortableRemoteObject.narrow(objref, DisplayHome.class);
System.out.println("Home Object Created");
Display ref=home.create();
System.out.println("Remote Object Created");
out.println("<html><title>The Results Page</title>");
out.println("<h1>The Client Side Response is: ");
System.out.println("Responses Done");
System.out.println("Output Stream Flushed");
System.out.println("Remote Object Removed");
Exception here:
Servlet Entered
HTML Content Type Set
PrintWriter Object Created
p.put(1) Created
p.put(2) Created
Context Object Created
Lookup Done Successfully
Exception in Servlet Client Code: javax.naming.NameNotFoundException [Root excep
tion is org.omg.CosNaming.NamingContextPackage.NotFound]
javax.naming.NameNotFoundException. Root exception is org.omg.CosNaming.NamingC
at org.omg.CosNaming._NamingContextExtStub.resolve(_NamingContextExtStub
at com.sun.jndi.cosnaming.CNCtx.callResolve(
at com.sun.jndi.cosnaming.CNCtx.lookup(
at com.sun.jndi.cosnaming.CNCtx.lookup(
at javax.naming.InitialContext.lookup(
at DisplayServletClient.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServl
at org.apache.catalina.servlets.InvokerServlet.doGet(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationF
at org.apache.catalina.core.ApplicationFilterChain$
at Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
and a long trace of catalina exception trace.
What else could have gone wrong??
Still trying!!
Tualha Khan
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
In the exception trace disregard the statement
Lookup Done Successfully

It was just a debugging statement mistakenly put before the actual lookup was performed..... really really sorry for this error. Rest of the code is absolutely in sync.
Thanks & Bye,
Tualha Khan
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Tualha,
I am sorry to hear that the above code didn't work. The error says that some package is not found. I found above code at here:
This is a tutorial for Forte for Java. Forte has J2EE RI plugin, and since it's developed by Sun, I hoped that same method worked. I think Forte has something else installed and the package is in CLASSPATH. I checked both J2EE RI and Forte folders, and looks like "cosnaming.jar" is missing from RI. If you can find that file, and put it in CLASSPATH, it might work...
Also, I found this:
It's BBS, and discussing about JNDI initial context setting for RI.
One guy says that you don't need artument in the constructor. I am wondering if that's true...

Some things to consider:
1.I just installed j2EE RI, and there is a file named at
%J2EE_HOME%\lib\classes directory.
Inside, I got two lines:
Do you have the same entries? Or different?
factory name is com.sun.enterprise.naming.SerialInitContextFactory, so you might want to try that. Or maybe this file enable to use the default constructor in J2EE RI, like the guy in BBS said. I am not sure.
2.In error code, org.apache.catalina.servlets.InvokerServlet.serveRequest in error stack. Does that mean that J2EE RI use Tomcat? (Or I could be totally wrong.) I looked through Tomcat documentaion, and all examples I could find use the default constructor for InitialContext. You might want to check their documentation, too.
I am sorry that I can't give you a precise solution to your problem.
I am also learning WebLogic and EJB, and probably we both have similer level of understanding in this thing.
If I find something else, I'll post it here.
By the way,
I try things on WebLogic. It's an evaluation version(Well, obviously I can't afford one.), but I reinstall every 30 days, and it's not so tough. Once you get used to it, you know what you have to save and reinstall. And installation process is fairly easy and quick.
If your ultimate goal is to develop on WebLogic, you might want to consider switching to WebLogic.
Oh, I almost forgot:
This is a tutorial for J2EE RI from Sun.
Good luck,
and please let me know if you find something.

Shin Hashitani
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Dear Shin,
Well, glad to know that things are rolling again for my stranded learning process. I have not searched for "cosnaming.jar" file as of yet, since I am at my work place at the moment.
Secondly, I am not very sure, but I read it somewhere (maybe in some post of some article, 3 or 4 days back) that if, the server bean and the client are physically on the same machine, then in case of J2EE RI, there is no need for any arguments in the constructor of InitialContext.
I had earlier tried those entries in the jndi.proerties file (<J2EE_HOME>\lib\Classes) directory, as the arguments for the Properties object's put(), but it still did not work.
Thirdly, yes very true, I also believe that this RI is somewhere in the core, based on tomcat. I have not seen the docs of tomcat yet, will do so tonite.
Finally, as far as weblogic is concerned, I have successfully, deployed simple servlets on it. But I have not had an experience of EJB's yet. I have gone through the official documentation files. Everything seems to be fine with me, the interfaces, the deployment descriptors specific to weblogic, jar file, the ejbc tool etc etc. BUT, I am still unclear about what my sequence of bundling/creating the application.ear file should be. At the moment, I will/have tried the following sequence of steps:
1) Create Remote, Home, Bean, and Client Java files.
2) Compile all the files individually.
3) Now, all my class files are in the same directory.
4) Creating the deployment descriptor ejb-jar.xml
5) Creating weblogic specific deployment descriptor.
5.5) Creating the application.xml deployment descriptor.
6) Combining everything in the directory into a jar file, ie.:
Class files,
Java files,
Deployment descriptors
7) Running weblogic.ejbc compiler tool to generate the stubs and skeletons.
8) Renaming the jar file to an ear file.
The above steps I have tried and tried and have been unsuccessful as of now. I am very unclear about what files should go to my clients jar file, whether, I need to explicitly make the jar or the weblogic container will generate one for me, where and how ahould my application-client.xml file be, etc etc.
I have read those bea documentations, but so far nothing has turned up. Tonite, maybe tomorrow night, I will once again try to get dirty with the stuff. Once again thanks a tonne for clearing a lot many doubts in nooks and corners.
Thanks & Regards,
Tualha Khan
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Tualha,
I have looked through your posting one more time in order to understand the nature of the problem. I was kind of looking for a "quick fix" that let you bypass some configuration process problems. (Well, I am not that familiar with all config process, either.) But, probably that wasn't such a good idea.
The main point is that
Your console app works. And InitialContext() does find initial context. But not if it's servlet.
Maybe it's a good idea to go through web application deployment process one more time.
I thought you might have already tried this million times, but please bear with me.
I was meaning to try Tomcat, so it was a good opportunity for me to read through some documents:
I think these two are the ones you need.
1.The InitialContext is configured as a web application is initially deployed, and is made available to web application components (for read-only access).
2.A web application is defined as a hierarchy of directories and files in a standard layout. Such a hierarchy can be accessed in its "unpacked" form, where each directory and file exists in the filesystem separately, or in a "packed" form known as a Web ARchive, or WAR file.
3.In order to be executed, a web application must be deployed on a servlet container. This is true even during development.
4.Copy unpacked directory hierarchy into a subdirectory in directory $CATALINA_HOME/webapps/. Tomcat will assign a context path to your application based on the subdirectory name you choose. (We will use this technique in the build.xml file that we construct, because it is the quickest and easiest approach during development. Be sure to restart Tomcat after installing or updating your application.)
The document mentioned server.xml which contains some deployment information, and in fact there is server.xml file in %J2EE_HOME%\conf directory.
Probably J2EE RI server customize some deployment method for its Tomcat part, so you have to use deploytool. But I think the problem lies in web component deployment, and once you can deploy it, InitialContext() will find you an actual initial context. That's an impression I got from reading Tomcat document.
I guess I can never get you a clear answer.
But I think you can get it right by trying deploytool a little more. Actually it was intuitive and kind of fun to use. (Well, I couldn't get it right either, but still.)

By the way,
I got a book titled "Enterprise Java Beans, 3rd Edition." This book offers "workbook" which is specific to a particular vendor. They have WebLogic and WebSphere book.
All source code and PDF version of the workbook(Not printable) are available free for download. The source code use Ant utility and use automatic deploy feature of WebLogic. I didn't know how to use Ant, but this sample codes helped me a great deal developing application on WebLogic. I don't think you need a book to try those sample apps. The workbook, and code itself, explains what the sample apps try to do.
You might want to check that out.

Good luck,
and let me know if you find something.

Shin Hashitani
I agree. Here's the link:
subject: PLEASE, I need help with this..............
Similar Threads
unary +/- and ++/-- question
help I am having trouble getting the field to fill in
How can I debug it ?
Unable to find setter method -exception with custom tag
Can any1 explain this??