• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting exception while bean look up by PortableRemoteObject.narrow

 
Jaya Pankaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.ClassCastException
java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at SessionBean.SessionBeanCall.main(SessionBeanCall.java:54)
Caused by: java.lang.ClassCastException: $Proxy0
... 3 more


getting exception while running the below code:

InitialContext jndiContext = new InitialContext(env);
System.out.println("Got context");

// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("Customer");
System.out.println("Got reference");

// Get a reference from this to the Bean's Home interface

//CustomerLocal home = (CustomerLocal)
/* System.out.println("home class : "+ CustomerLocal.class);*/
System.out.println("Reference : "+ ref.toString());
CustomerLocal obj = (CustomerLocal) PortableRemoteObject.narrow (ref, CustomerLocal.class);
System.out.println(obj.getClass());
System.out.println("Looked up by narrow interface");
// Create an Interest object from the Home interface
CustomerRemote customer = obj.create();
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PortableRemoteObject is used only for remote interfaces as far as I've seen. Why do you need it for a local interface?

And welcome to the Ranch!
 
Jaya Pankaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CustomerLocal is just a interface name while it has extended by EJBHome. I have not used local interface in my application and I used Jboss4.2 for deployment.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you are using the correct JNDI name to do the lookup? Have you checked the jmx-console's JNDIView MBean to confirm the JNDI name for your bean?
 
Jaya Pankaj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<!-- <ejb-jar version="2.1"> -->
<enterprise-beans>
<session>
<ejb-name>CustomerBean</ejb-name>
<home>SessionBean.CustomerLocal</home>
<remote>SessionBean.CustomerRemote</remote>
<ejb-class>SessionBean.CustomerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>


and this my jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>CustomerBean</ejb-name>
<jndi-name>Customer</jndi-name>
</session>
</enterprise-beans>
</jboss>

What else I need to configure using Eclipse and runing a stateless ejb.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic