This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes getting exception while bean look up by PortableRemoteObject.narrow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "getting exception while bean look up by PortableRemoteObject.narrow" Watch "getting exception while bean look up by PortableRemoteObject.narrow" New topic
Author

getting exception while bean look up by PortableRemoteObject.narrow

Jaya Pankaj
Greenhorn

Joined: Dec 06, 2010
Posts: 3
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

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!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jaya Pankaj
Greenhorn

Joined: Dec 06, 2010
Posts: 3
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

Joined: Jul 20, 2005
Posts: 9924
    
158

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?


[My Blog] [JavaRanch Journal]
Jaya Pankaj
Greenhorn

Joined: Dec 06, 2010
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting exception while bean look up by PortableRemoteObject.narrow
 
Similar Threads
exception error!!
error on running an ejb application
NoInitialContextException
java.lang.No Class Def Found Error
Naming Context problem