Error in create method on Home Interface!

Hi,
   I have made a somple stateless session bean and deployed on JRun4.0. While running the client I am getting error in calling crate method on home interface. The code is like this:

Context ctx          = getInitialContext();
 Object o = ctx.lookup("demo.DemoHome");
DemoHome dhome = (DemoHome)
               PortableRemoteObject.narrow(o, DemoHome.class);

Demo demo = dhome.create();//getting error here

The error is:

java.rmi.RemoteException: null; nested exception is:
        java.lang.NullPointerException
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:127)
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:80)
        at jrunx.rmi.Invocation.invoke(Invocation.java:302)
        at jrunx.rmi.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:177)
        at jrun.ejb.invocation.ClientInvocationHandlerImpl.invoke(ClientInvocationHandlerImpl.java:2
15)
        at $Proxy2.demoSelect(Unknown Source)
        at ejb.demo.DemoClient.main(DemoClient.java:58)
Caused by: java.lang.NullPointerException
        at jrun.ejb.interceptors.InvokerInterceptor.invokeObjectMethod(InvokerInterceptor.java:139)
prateekkumarAsked:
Who is Participating?
 
girionisConnect With a Mentor Commented:
What I suggest we do is to trace the error from the start. Can you do this and tell us the output:

Context ctx          = getInitialContext();
System.out.println("ctx: " + ctx);
 Object o = ctx.lookup("demo.DemoHome");
System.out.println("o: " + o);
DemoHome dhome = (DemoHome)
               PortableRemoteObject.narrow(o, DemoHome.class);
System.out.println("dhome: " + dhome);
Demo demo = dhome.create();//getting error here

0
 
girionisCommented:
Probably the "dhome" variable is null. Are you getting any other exceptions?
0
 
girionisCommented:
>  Object o = ctx.lookup("demo.DemoHome");

This lookup looks weird, you need to look for the EJB reference using the standard syntax:

java:comp/demo/DemoHome
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
expertmbCommented:
Lookup the bean using it's deployment id
0
 
expertmbCommented:
have a look at
ejb-jar.xml

<ejb-name>Demo</ejb-name>
0
 
prateekkumarAuthor Commented:
The ejb-jar is like this:

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>demo.DemoHome</ejb-name>
      <home>ejb.demo.DemoHome</home>
      <remote>ejb.demo.Demo</remote>
      <ejb-class>ejb.demo.DemoBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>

To add more about this question, I am getting these error when calling a method on "demo" object. I tried to print the objects and got these results:

DemoHome dhome = (DemoHome) PortableRemoteObject.narrow(o, DemoHome.class);
System.out.println("===========here1111==========" + dhome);//it is printing Demo.jar#demo.DemoHome

Demo demo = dhome.create();
System.out.println("===========here2222==========" + demo);// it is also printing Demo.jar#demo.DemoHome

// Here is the call that executes the method on the // server side object System.out.println("The result is " + demo.demoSelect());// here getting all those errors...
0
 
girionisCommented:
> <ejb-name>demo.DemoHome</ejb-name>

Try to change it to:

<ejb-name>DemoHome</ejb-name>

and access it like:

Object o = ctx.lookup("java:comp/DemoHome");

and tell us if this helps.

0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Demo demo = dhome.create();//getting error here

Shouldn't you be casting it too? Demo demo = ( Demo ) dhome.create () ;

Anyway, I don't think that dhome is null because the message says:

java.lang.NullPointerException
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:127)
0
 
girionisCommented:
> Shouldn't you be casting it too? Demo demo = ( Demo ) dhome.create () ;

It shouldn't, the create method returns an object of the home type anyway.
0
 
prateekkumarAuthor Commented:
Hi girionis,
   I changed the ejb-name as DemoHome but the error is same.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> It shouldn't, the create method returns an object of the home type anyway.

Yeah, you're right. Its been more than a year since I touched J2EE and have forgotten lots :-( unfortunately, this .NET thing that I'm being forced to work on doesn't suit me as I'd expected.

Prateek, can you post your updated XML?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I had something similar to this which worked:

<ejb-jar id="ejb-jar_ID">
      <display-name>wfejb</display-name>
      <enterprise-beans>
            <session id="FileMatchService">
                  <ejb-name>FileMatchService</ejb-name>
                  <home>com.citigroup.wfl.id.ejb.filematchservice.FileMatchServiceHome</home>
                  <remote>com.citigroup.wfl.id.ejb.filematchservice.FileMatchService</remote>
                  <ejb-class>com.citigroup.wfl.id.ejb.filematchservice.FileMatchServiceBean</ejb-class>
                  <session-type>Stateless</session-type>
                  <transaction-type>Container</transaction-type>
            </session>
      </enterprise-beans>
</ejb-jar>

FileMatchServiceHome objFileMatchServiceHome = ( FileMatchServiceHome ) ctx.lookup ( sJNDIName ) ;
FileMatchService objFileMatchService = ( FileMatchService ) objFileMatchServiceHome.create () ;
0
 
girionisCommented:
What is the "sJNDIName"'s value? Maybe it will give us some clues as to what is going wrong.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Well, it was "WFInd.FileMatchService".
0
 
Mayank SAssociate Director - Product EngineeringCommented:
ejb-jar-bnd.xmi:

<?xml version="1.0" encoding="UTF-8"?>
<ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbbnd="ejbbnd.xmi" xmlns:ejb="ejb.xmi" xmi:id="EJBJarBinding_1059548815063">
      <ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>
      <ejbBindings xmi:id="EnterpriseBeanBinding_1059548815063" jndiName="WFInd.FileMatchService">
      <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#RemoteInterface"/>
      </ejbBindings>
</ejbbnd:EJBJarBinding>
0
 
prateekkumarAuthor Commented:
Hi,
   Finaly I am able to run this small EJB code..:) I don't know what exactly was wrong but I used this DD finally:

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>DemoHome</ejb-name>
      <home>ejb.demo.DemoHome</home>
      <remote>ejb.demo.Demo</remote>
      <ejb-class>ejb.demo.DemoBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>

  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>DemoHome</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>

</ejb-jar>

Also I changed setSessionContext method from :
public void setSessionContext(SessionContext ctx) {    
    if (verbose)
      System.out.println("setSessionContext called");
    this.ctx = ctx;
    props = ctx.getEnvironment();
  }
 
To:
public void setSessionContext(javax.ejb.SessionContext ctx) {
    this.ctx = ctx;
  }


Thanks to all.
0
 
girionisCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.