Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in EJB reference Example

 
Suresh Babu Shanmugam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am preparing for SCBCD 1.3. reading HFEJB. Just tried to simulate EJB reference(Using Remote Interface). using RI JSDEEK 1.3

Client ====> ReferBean ===>CommonBean

Following is the code for CommonBean

CommonBean.java
===============
package headcommon;
import javax.naming.*;
import java.rmi.*;
import javax.ejb.*;
public class CommonBean implements SessionBean{
SessionContext ctx=null;
public void setSessionContext(SessionContext ctx){this.ctx=ctx;}
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void ejbCreate(){}
public String getValue(){return "Fantastic";}
}
===================================================
Common.java
===========
package headcommon;
import javax.ejb.*;
import java.rmi.*;
public interface Common extends EJBObject{
public String getValue() throws RemoteException;
}
===================================================
CommonHome.java
===============
package headcommon;
import javax.ejb.*;
import java.rmi.*;
public interface CommonHome extends EJBHome{
public Common create() throws CreateException, RemoteException;
}
===========================================================
Deployed this Common Bean in RI Server with JNDI as ejb/Common. I test with client, working fine
============================================================

Following is the code for Refer Bean
============================
ReferBean.java
==============
package headthird;
import javax.naming.*;
import java.rmi.*;
import javax.ejb.*;
import headcommon.*;
import javax.rmi.*;
public class ReferBean implements SessionBean{
SessionContext ctx=null;
public void setSessionContext(SessionContext ctx){this.ctx=ctx;}
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void ejbCreate(){}
public String getAdvice(){
String adv="No Advice";
try{
System.out.println("Step 1");
Context context = new InitialContext();
System.out.println("Step 2");
Object obj = context.lookup("java:comp/env/ejb/Another");
System.out.println("Step 3");
CommonHome home = (CommonHome)PortableRemoteObject.narrow(obj,CommonHome.class);
System.out.println("Step 4");
Common advice=home.create();
System.out.println("Step 5");
adv=advice.getValue();
System.out.println("Step 6");
System.out.println(adv);
System.out.println("Step 7");
}catch(Exception e){
e.printStackTrace();
}
return adv;
}
=========================================================
Refer.java
==========
package headthird;
import java.rmi.*;
import javax.ejb.*;
public interface Refer extends EJBObject{
public String getAdvice() throws RemoteException;
}
=========================================================
ReferHome.java
==============
package headthird;
import java.rmi.*;
import javax.ejb.*;
public interface ReferHome extends EJBHome{
public Refer create() throws CreateException, RemoteException;
}
=========================================================

While deploying Refer Bean, I mapped this ejb/Another to ejb/Common. I have Refer Client, which fetches the remote reference to Refer bean and calls getAdvice(), which calls getValue() method in Common Bean(Check Code). I am getting Exception like this

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: headcommon.CommonHome
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemExceptio
n(ShutdownUtilDelegate.java:64)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at headthird._Refer_Stub.getAdvice(Unknown Source)
at ReferClient.go(ReferClient.java:22)
at ReferClient.main(ReferClient.java:10)
Caused by: java.rmi.RemoteException: headcommon.CommonHome
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:389)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:431)
at headthird.ReferBean_EJBObjectImpl.getAdvice(ReferBean_EJBObjectImpl.j
ava:26)
at headthird._ReferBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(Ge
nericPOAServerSC.java:520)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(Gen
ericPOAServerSC.java:210)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAS
erverSC.java:112)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProces
sor.java:84)
at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP
ool.java:99)
=======================
In Server log(C:\j2sdkee1.3.1\logs\jawaharb\j2ee\j2ee\error.log)

Logging for J2EE Server Version: 1.3.1-b17 started at: Thu Jan 18 19:22:26 IST 2007..
Using the Java HotSpot(TM) Client VM and the version number 1.4.2_10 from Sun Microsystems Inc..
VM is using the classpath: C:\j2sdkee1.3.1\lib\system\cloudscape.jar;C:\j2sdkee1.3.1\lib\system\tools.jar;C:\j2sdkee1.3.1\lib\cloudscape\RmiJdbc.jar;C:\j2sdkee1.3.1\lib\cloudscape\cloudclient.jar;C:\j2sdkee1.3.1\lib\classes;C:\j2sdkee1.3.1\classes;C:\j2sdkee1.3.1\lib\j2ee.jar;C:\j2sdkee1.3.1\lib\toolclasses;C:\j2sdkee1.3.1\lib\j2eetools.jar;C:\j2sdkee1.3.1\lib\locale;;C:\j2sdk1.4.2_10\lib\tools.jar;C:\j2sdkee1.3.1\lib\jhall.jar .
J2EE Home Directory has been set to: C:\j2sdkee1.3.1.


javax.ejb.EJBException: headcommon.CommonHome
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:1560)
at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer.java:1407)
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx(BaseContainer.java:1354)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:1253)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:403)
at headthird.ReferBean_EJBObjectImpl.getAdvice(ReferBean_EJBObjectImpl.java:26)
at headthird._ReferBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)

java.rmi.RemoteException: headcommon.CommonHome
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:389)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:431)
at headthird.ReferBean_EJBObjectImpl.getAdvice(ReferBean_EJBObjectImpl.java:26)
at headthird._ReferBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)



I dont know y it is happening

CAN SOMEONE HELP ME TO FIX THIS

Suresh
SCJP 1.4
 
Suresh Babu Shanmugam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is coming from line(BOLD)

ReferBean.java
==============
package headthird;
import javax.naming.*;
import java.rmi.*;
import javax.ejb.*;
import headcommon.*;
import javax.rmi.*;
public class ReferBean implements SessionBean{
SessionContext ctx=null;
public void setSessionContext(SessionContext ctx){this.ctx=ctx;}
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void ejbCreate(){}
public String getAdvice(){
String adv="No Advice";
try{
System.out.println("Step 1");
Context context = new InitialContext();
System.out.println("Step 2");
Object obj = context.lookup("java:comp/env/ejb/Another");
System.out.println("Step 3");
CommonHome home = (CommonHome)PortableRemoteObject.narrow(obj,CommonHome.class);
System.out.println("Step 4");
Common advice=home.create();
System.out.println("Step 5");
adv=advice.getValue();
System.out.println("Step 6");
System.out.println(adv);
System.out.println("Step 7");
}catch(Exception e){
e.printStackTrace();
}
return adv;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic