Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be c

843830Jun 28 2009 — edited Jun 28 2009
i am new to EJB 3.0
i am using - eclipes GANYMADE
- JBoss AS 5 beta 4
- Java 1.6

i wrot the Ejbs , and the client and i found this exception
Exception in thread "main" java.lang.ClassCastException
	at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
	at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
	at MainClient.main(MainClient.java:19)
Caused by: java.lang.ClassCastException: org.jnp.interfaces.NamingContext cannot be cast to org.omg.CORBA.Object
	... 3 more
EJB interface
package ejb.test;
import javax.ejb.Remote;

@Remote
public interface TimerService {
	public String getTime();

}
Bean
package ejb.test;

import java.util.Calendar;
import java.util.Formatter;

import javax.ejb.Stateless;

@Stateless
public class TimerServiceBean implements TimerService {

	@Override
	public String getTime() {
		Formatter fmt = new Formatter();
        Calendar cal = Calendar.getInstance();
        fmt.format("%tr", cal);
        return fmt.toString();
	}

}
Client
import java.util.Properties;

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import ejb.test.TimerService;

public class MainClient {
	public static void main(String[] args) throws Exception{
		Properties env = new Properties();
		
		env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
        env.put("java.naming.provider.url", "jnp://localhost:1099");
        env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
        env.put("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");
		InitialContext ctx = new InitialContext(env);
		
		Object object = ctx.lookup("TimerServiceBean");
		TimerService timeService =(TimerService) PortableRemoteObject.narrow(object, TimerService.class); 
			
        String time = timeService.getTime();
        System.out.println("time " + time);	
	}
}
how could i solve this problem?!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2009
Added on Jun 28 2009
2 comments
1,021 views