Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic