Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB 3 issue : Not able to look up the Stateless session bean on WebLogic 10  RSS feed

 
Cotton Gear
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner in EJB 3 and trying to execute a simple EJB 3 Stateless session bean on WebLogic 10.

Here are the details of my code and the exceptions i get :

---------------------------------------------------------------------------
package com.mycompany.ejb3application.ejb.session;

import javax.ejb.Stateless;

@Stateless(name="UserSession", mappedName="UserSession")
public class UserSession implements UserSessionLocal, UserSessionRemote {

public void sayHello(){
System.out.println("..........Hello Sujith !!......");
}
}
---------------------------------------------------------------------------
package com.mycompany.ejb3application.ejb.session;

import javax.ejb.Remote;

@Remote
public interface UserSessionRemote {
//public void test();
public void sayHello();
}

---------------------------------------------------------------------------
package com.mycompany.ejb3application.ejb.session;

import javax.ejb.Local;

@Local
public interface UserSessionLocal {
//public void test();
public void sayHello();
}
---------------------------------------------------------------------------
package com.mycompany.ejb3applicationclient;

import java.util.Hashtable;

import javax.ejb.EJB;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;

import com.mycompany.ejb3application.ejb.session.UserSessionRemote;

public class Client {

@EJB(beanName = "UserSessionBean")
static UserSessionRemote userSessionRemote;

public static void main(String[] str) {
try{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
//Context compEnv = (Context) new InitialContext().lookup("java:comp/env");

// service = (HelloService)new
// InitialContext().lookup("java:comp/env/ejb/HelloService");

InitialContext context = new InitialContext(ht);
NamingEnumeration bindings = context.list(".");
System.out.println();
while (bindings.hasMore()) {
NameClassPair np = (NameClassPair )bindings.next();
System.out.println(np.getName() + ": " + np.getClassName());
}
System.out.println();

//context.list(name)

UserSessionRemote userSessionRemote = (UserSessionRemote)context.lookup("ejb3applicationejb3applicationEJB_jarUserSession_UserSessionRemote");
//UserSessionRemote userSessionRemote = (UserSessionRemote)context.lookup("UserSession#com.mycompany.ejb3application.ejb.session.UserSessionBean");
//UserSessionRemote userSessionRemote = (UserSessionRemote)compEnv.lookup("UserSessionBean/remote");
//UserSessionRemote userSessionRemote = (UserSessionRemote)context.lookup("java:comp/env/ejb/UserSessionBean");
userSessionRemote.sayHello();
}catch(Exception e){
System.out.println("Exception is :" +e );
e.printStackTrace();
}
}
}
---------------------------------------------------------------------------
JNDI Binding and the exceptions on the console :

java com.mycompany.ejb3applicationclient.Client

mejbmejb_jarMejb_EO: weblogic.rmi.cluster.ClusterableRemoteObject
ejb: weblogic.jndi.internal.ServerNamingNode
projDataSource: weblogic.rmi.cluster.ClusterableRemoteObject
weblogic: weblogic.jndi.internal.ServerNamingNode
cgDataSource: weblogic.rmi.cluster.ClusterableRemoteObject
javax: weblogic.jndi.internal.ServerNamingNode
ejb3applicationejb3applicationEJB_jarUserSession_UserSessionRemote: com.mycompany.ejb3application.ejb.session.UserSession_lw784g_UserSe
ssionRemoteImpl
cgDataSource-nonXA: weblogic.rmi.cluster.ClusterableRemoteObject

Exception is :java.lang.ClassCastException: com.mycompany.ejb3application.ejb.session.UserSession_lw784g_UserSessionRemoteImpl_1001_WLS
tub
java.lang.ClassCastException: com.mycompany.ejb3application.ejb.session.UserSession_lw784g_UserSessionRemoteImpl_1001_WLStub
at com.mycompany.ejb3applicationclient.Client.main(Client.java:40)
---------------------------------------------------------------------------

Thanks and Regards,
Aniket P
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Aniket P" please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!