aspose file tools*
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
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: 29249
    
139

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: 9318
    
109

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting exception while bean look up by PortableRemoteObject.narrow
 
Similar Threads
exception error!!
java.lang.No Class Def Found Error
NoInitialContextException
Naming Context problem
error on running an ejb application