aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes null pointer exception on jndi session bean call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "null pointer exception on jndi session bean call" Watch "null pointer exception on jndi session bean call" New topic
Author

null pointer exception on jndi session bean call

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 272
Hello. If somebody has a minute, I think I am having trouble getting a handle on a session bean via jndi. This is the session portion of a session-facade that I'm tinkering with (this began with a session bean example I found on the web, but instead of using the servlet and a direct entity bean call, I went for jsp and a session facade). The call to the session facade is located within a javabean that is loaded by jsp...

package com.turtle;

import java.sql.*;
import java.util.*;
import java.text.*;

public ArrayList runQuery() {

try {

javax.naming.InitialContext ctx = new javax.naming.InitialContext();

Object obj = ctx.lookup("TurtleFacade");

if(obj == null) {

System.out.println("OBJ IS NULL");
}

TurtleFacadeHome home = (TurtleFacadeHome)javax.rmi.PortableRemoteObject.narrow(obj, TurtleFacadeHome.class);

if(home == null) {

System.out.println("HOME IS NULL");
}
TurtleFacade tf = home.create();

System.out.println("It worked");
ArrayList turtle_array = tf.getTurtleEntity();

return turtle_array;

} catch (Exception e) {

System.out.println(e);

return null;

}

}

// CLASS CLOSE

}

I kept receivng a null pointer exception and after putting in these print statements, I am finding that the obj is null, pretty much right at the start of the call, it fails (OBJ IS NULL is printed to the console).

Is there something I am missing that should go into the web.xml for this application? I've been looking all over and can't get a definitive picture so far. Here is my web.xml...

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">


<web-app xmlns="http://caucho.com/ns/resin">
<database>
<jndi-name>jdbc/test</jndi-name>
<driver type="oracle.jdbc.driver.OracleDriver">
<url>jdbc :0racle:thin:@sbdoracle:1521 :0racle</url>
<user>user_name</user>
<password>user_password</password>
</driver>
</database>

<ejb-server config-directory="WEB-INF">
<jndi-name>java:comp/env/cmp</jndi-name>
<data-source>java:comp/env/jdbc/test</data-source>
<ejb-descriptor>WEB-INF/turtle.ejb</ejb-descriptor>
</ejb-server>

</web-app>

Thank you very much for reading this and thank you for any help.
[ March 07, 2005: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 272
oh, and here is the session snippet of my deployment descriptor...

<session>
<ejb-name>TurtleFacade</ejb-name>
<local-home>com.turtle.TurtleFacadeHome</local-home>
<local>com.turtle.TurtleFacade</local>
<ejb-class>com.turtle.TurtleFacadeBean</ejb-class>
<session-type>Stateless</session-type>
</session>

thank you again for reading this. I'll keep plugging at this and if I can get this going, I'll post what I did. Thank you for any help...
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Tom,

There are several things that I could suggest to you:
  • Make sure that your session bean was deployed properly.
  • Make sure the bean binds to the JNDI tree within the right context name (your server might have useful tools that can help you doing these two).
  • Make sure that you actually are not declaring ejb references because in that case you might lookup your bean like this:

  • Without being a resin user I�m littele bit intrigued by this declaration:


  • Which looks to me like a resin specific tag. Could this change the naming context for your beans? If the answer is yes then you might need to look up your bean like this:

    Which is a similar technique to using ejb references. Again having a snapshot of your server�s JNDI tree will help you run out this theory.

    See if any of these help.
    Regards.


    I think, therefore I exist -- Rene Descartes
    Tom Griffith
    Ranch Hand

    Joined: Aug 06, 2004
    Posts: 272
    Thank you Valentin. This did the trick...

    Object obj = ctx.lookup("java:comp/env/cmp/TurtleFacade");

    I think my problem is that I tend to associate ejb references with CMP entities. For whatever reason, I tend to forget about them with session beans.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: null pointer exception on jndi session bean call