File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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 /> * hashitani@quants.co.jp<br /> * <a href="http://www.quants.co.jp" target="_blank" rel="nofollow">www.quants.co.jp</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
Hey,
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");
response.setContentType("text/html");
System.out.println("HTML Content Type Set");
out=response.getWriter();
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("<body<hr>");
out.println("<h1>The Client Side Response is: ");
out.println(ref.display());
out.println("</h1>");
out.println("<hr>");
out.println("</body></html>");
System.out.println("Responses Done");
out.flush();
System.out.println("Output Stream Flushed");
ref.remove();
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
ontextPackage.NotFound
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHe
lper.java:34)
at org.omg.CosNaming._NamingContextExtStub.resolve(_NamingContextExtStub
.java:400)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:368)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:417)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:395)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at DisplayServletClient.service(DisplayServletClient.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServl
et.java:428)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java
:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationF
ilterChain.java:197)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilt
erChain.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:172)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
====================
and a long trace of catalina exception trace.
What else could have gone wrong??
Still trying!!
Thanks,
Tualha Khan
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
SORRY,
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:
http://forte.sun.com/ffj/articles/TPandAS_printer.html
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:
http://p2p.wrox.com/archive/j2ee/2001-05/15.asp
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 jndi.properties at
%J2EE_HOME%\lib\classes directory.
Inside, I got two lines:
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
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:
http://java.sun.com/j2ee/tutorial/
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,
Hey,
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:
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/appdev/deployment.html
http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html
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,
http://www.titan-books.net/web61worfore.html
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.
Sincerely,

Shin Hashitani
 
I agree. Here's the link: http://aspose.com/file-tools
 
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??