geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: how to run Ejb program on geronimo
Date Mon, 07 Apr 2008 15:40:41 GMT
Thank you for supplying the code you are actually running.  With this  
available the mistake is rather obvious:

//Object is a MEJBHome
                        Object object=ctx.lookup("ejb/mgmt/ 
MEJBRemoteHome");
//You are casting it to DemoHome
                         My.DemoHome ejbHome=(My.DemoHome) 
PortableRemoteObject.narrow(object,My.DemoHome.class);


The easiest way to determine the correct jndi name to look up is to  
examine the server log when you deploy your ejbs, as there will be  
log messages indicating where the ejbs are bound.
Many people find it more convenient to rely on the openejb transport  
and avoid corba and just cast the result of the jndi lookup rather  
than using PortableRemoteObject.narrow.  Both will  work using the  
proprietary openejb transport but the error messages from PRO.narrow  
can sometimes be difficult to decipher.

While I doubt it would make any difference in this use of PRO.narrow  
to perform a cast using the yoko corba implementation we ship with  
geronimo may produce fewer corba related errors.

thanks
david jencks

On Apr 6, 2008, at 11:43 PM, atul12345 wrote:

>
> Dear Sir,
>
>              Thanks for help but this is not my solution. Anyway  
> according
> to u i am showing the ENTIRE stack trace for this exception and  
> include the
> exact  source code........
>
>
> This is my Exception which is generated during the client program
> execute.......
> java.lang.ClassCastException
>          at
>   com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow 
> (PortableR
>          at
>  javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
>          at HelloWorld.main(HelloWorld.java:31)
>  Caused by: java.lang.ClassCastException: $Proxy0 cannot be cast to
>  org.omg.CORBA
>          at
>  com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableR
>          ... 2 more
>
>  Could anyone tell me what I’m doing wrong? Thanks a lot. Looking  
> forward to
> hearing from you.
>
> These are my code..........
>
> ********remote interface*******
> package My;
>
> import java.rmi.*;
>
> import javax.ejb.*;
>
> public interface DemoInter extends EJBObject
> {
> 	   public int add() throws RemoteException;
> }
>
> ************home interface***********
> package My;
>
> import javax.ejb.*;
> import java.rmi.*;
>
>
>
> public interface DemoHome extends EJBHome
> {
> public DemoInter create(int a, int b) throws
> CreateException,RemoteException;
> }
> *************bean class*************
>
> package My;
>
> import javax.ejb.*;
> import java.rmi.*;
>
> public class DemoBean implements SessionBean
> {
>  int a,b;
> private SessionContext context;
>    public void setSessionContext(SessionContext ctx){this.context=ctx}
>
>    public void ejbCreate( int a,int b)
>    {
> 		this.a=a;
> 		this.b=b;
>           	System.out.println("ejb Created");
>    }
>
>     public void ejbActivate(){System.out.println("ejbActivate()");}
>     public void ejbPassivate(){System.out.println("ejbPassivate()");}
>     public void ejbRemove(){System.out.println("distroyed");}
>     public int add() throws RemoteException
>     {
>            return(a+b);
>     }
> }
>
> **********ejb-jar.xml****************
> 	
>
> <ejb-jar id="ejb-jar_1" xmlns="http://java.sun.com/xml/ns/j2ee"
> 	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> 	 http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
> 	<description>Example of a session bean</description>
> 	<display-name>MyTimeBeanEJBName</display-name>
> 	<enterprise-beans>
> 		<session id="Session_MyTime">
> 			
> 			<ejb-name>My.DemoEJB</ejb-name>
> 			<home>My.DemoHome</home>
> 			<remote>My.DemoInter</remote>
> 			<ejb-class>My.DemoBean</ejb-class>
> 					
> 			<session-type>Stateful</session-type>
> 			<transaction-type>Container</transaction-type>
> 		</session>
> 	</enterprise-beans>
> </ejb-jar>
>
> *************openejb.xml***********
>
>
> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
> 	     xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
> 	     xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
> 	     xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
>   xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
> 	
> 	
>   <enterprise-beans>
>     <session>
> 	    <ejb-name>My.DemoEJB</ejb-name>
> 	    <jndi-name>ejb/mgmt/MEJBRemoteHome</jndi-name>
>     </session>
>   </enterprise-beans>
> </openejb-jar>
>
>
> ***********my client**************
>
>
>
>
> import java.util.*;
> import javax.rmi.PortableRemoteObject;
> import javax.naming.*;
> import javax.rmi.*;
> import My.*;
>
>
> public class Client {
>
> 	/**
> 	 * @param args
> 	 */
> 	public static void main(String[] args) {
> 		// TODO Auto-generated method stub
> 		try {
> 			
>                         Properties properties=new Properties();
> 	   		properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.RemoteInitialContextFactory");
> 	   		properties.put("java.naming.provider.url","ejbd://localhost: 
> 4201");
>
> 	   		Context ctx=new InitialContext(properties);
>                         System.out.println("ic = " + ctx);
>
> 			//MyTimeLocal myTimeLocal =
> (MyTimeLocal)context.lookup("java:comp/env/ejb/MyTimeBean");
>                        // My.DemoInter remoteObj
> =(My.DemoInter)ctx.lookup("ejb/mgmt/MEJBRemoteHome");
>                        Object object=ctx.lookup("ejb/mgmt/ 
> MEJBRemoteHome");
>                        // System.out.println("hello" +object);
>                         My.DemoHome ejbHome
> =(My.DemoHome)PortableRemoteObject.narrow(object,My.DemoHome.class);
> 	  		System.out.println("hello" +ejbHome);
>   			My.DemoInter obj1=ejbHome.create(4,5);
>  			System.out.println(obj1.add());
>
>
>
>
> 											
> 		} catch (Exception e) {
> 			System.out.println(e);
> 			// TODO: handle exception
> 		}
> 			
> 		
>
> 	}
>
> }
>
>
>

Mime
View raw message