Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / October 2003

Tip: Looking for answers? Try searching our database.

JBoss and Tomcat errors

Thread view: 
Steve Nakhla - 21 Oct 2003 15:26 GMT
I'm rather new to EJB programming, so please bear with me.  I've
installed JBoss 3.2.1 along with Tomcat 4.1, and have been going
through some tutorials to create a stateless session bean.  However,
I've been receiving some error messages, and wanted to make sure I
have everything configured properly.

All of the tutorials I've seen have something similar to the
following:

       try
       {
           InitialContext ctx = new InitialContext();
           Object objRef = ctx.lookup("test/MyTestSessionBean");
           testBean =
(MyTestSessionHome)PortableRemoteObject.narrow(objRef,
MyTestSessionHome.class);
       }
       catch (Exception e)
       {
           e.printStackTrace();
           System.out.println("EXCEPTION:  " + e.getMessage());
       }

However, when I run my servlet that is calling a method on the session
bean, I get a null pointer exception.

But, if I change it to the following:

       Properties p = new Properties();
       p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       p.setProperty("java.naming.provider.url","jnp://localhost:1099");
       p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       p.setProperty("jnp.socketFactory","org.jnp.interfaces.TimedSocketFactory");

       try
       {
           InitialContext ctx = new InitialContext(p);
        ......

everything works fine.  I'm guessing that somehow my naming schemas
are not setup in Tomcat correctly, but I don't know how to correct it.
Can anyone give me any guidance on this?  Thanks very much!

Steve Nakhla
Christopher Blunck - 22 Oct 2003 04:57 GMT
> I'm rather new to EJB programming, so please bear with me.  I've
> installed JBoss 3.2.1 along with Tomcat 4.1, and have been going
[quoted text clipped - 38 lines]
> are not setup in Tomcat correctly, but I don't know how to correct it.
>  Can anyone give me any guidance on this?  Thanks very much!

Hi Steve-

You are correct in your later implementation (using the Properties class).
Remember that what you're doing here is accessing a remote object (namely
your Session Bean).  In order to access a remote object, you're going to
have to provide a network address of some sort, right?  

Looking at your top code, it couldn't possibly work because you never
provide a network endpoint to talk to (jnp://localhost:1099).  The other
information you provide via your Properties instance assists the
InitialContext class in determining exactly how to communicate (on the
wire) with the remote endpoint.

The latter is always the way I do it.

-c
John C. Bollinger - 22 Oct 2003 15:05 GMT
>>I'm rather new to EJB programming, so please bear with me.  I've
>>installed JBoss 3.2.1 along with Tomcat 4.1, and have been going
[quoted text clipped - 21 lines]
>>However, when I run my servlet that is calling a method on the session
>>bean, I get a null pointer exception.

[...]

> Looking at your top code, it couldn't possibly work because you never
> provide a network endpoint to talk to (jnp://localhost:1099).  The other
> information you provide via your Properties instance assists the
> InitialContext class in determining exactly how to communicate (on the
> wire) with the remote endpoint.

The OP's first code usually works (and can be more efficient) when the
servlet container is in the in the same J2EE server (software, not
hardware) as the EJB container.  This would probably be the case for the
JBoss / Tomcat cobundles, for instance, but not for JBoss and Tomcat
installed seperately on the same machine.  When the servlet and EJB
containers are colocated in the same server (software), the default
configuration of an InitialContext provided by the server is normally
correct for the two to communicate.

John Bollinger
jobollin@indiana.edu
Marek Lange - 22 Oct 2003 19:55 GMT
Steve Nakhla schrieb:

> I'm rather new to EJB programming, so please bear with me.  I've
> installed JBoss 3.2.1 along with Tomcat 4.1, and have been going
[quoted text clipped - 8 lines]
>         {
>             InitialContext ctx = new InitialContext();

This should work when you use the JBoss/Tomcat bundle. Post the code to
show the location of the Exception.

-marek


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.