This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exception on jndi session bean call

 
Tom Griffith
Ranch Hand
Posts: 275
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 275
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Tom Griffith
    Ranch Hand
    Posts: 275
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic