[jboss-user] [EJB 3.0] - JBoss 5.0.0.CR1 - EJB Lookup Successful but ClassCastExcept

zampu007 do-not-reply at jboss.com
Thu Jul 31 12:40:23 EDT 2008


Trying out simple prototype

---- SETUP ------

enterpriseproject.ear contains
   DynamicWebProject.ear
    EjbProject.jar

DynamicWebProject.ear contains
    SecondServlet

EjbProject.jar contains 
   ThirdSessionBean (Bean Implementation)
   ThirdSession (business interface)

------- ThirdSessionBean Snippet -----

package com.tsb.test;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote(ThirdSession.class)

public class ThirdSessionBean implements ThirdSession{
	public String sayHello(String name) {
		return "Hello From Third Session Bean " + name + " ";
	}

}

------ ThirdSession Snippet -------

package com.tsb.test;

/* This is the business interface */


public interface ThirdSession 
 {
	public String sayHello(String name);
	

}

--- SecondServlet Snippet -------


		final String jndiName = "enterpriseproject/ThirdSessionBean/remote";
			
			try {
			    Context ic;
				ic = new InitialContext();	
				System.out.println("onject returned is " + ic.lookup(jndiName));
				//SecondSessionTestRemote foo = (SecondSessionTestRemote) ic.lookup(jndiName);
				
//				ThirdSession foo = (ThirdSession) ic.lookup(jndiName);
				Object foo1 = ic.lookup(jndiName);
				
				org.jboss.ejb3.proxy.JBossProxy zoo = (org.jboss.ejb3.proxy.JBossProxy) foo1;
				
				System.out.println("This works");
				
				
				ThirdSession foo = (ThirdSession) foo1;
				
				String s = foo.sayHello("Hello Foo on JBoss!");
				System.out.println(foo + " echo returned " + s);
				 
			
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

--------------------- end of code snippets -------

JNDIView of the EJB is 

Global JNDI Namespace


  +- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
  +- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
  +- UserTransactionSessionFactory (proxy: $Proxy83 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
  +- console (class: org.jnp.interfaces.NamingContext)
  |   +- PluginManager (proxy: $Proxy81 implements interface org.jboss.console.manager.PluginManagerMBean)
  +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
  +- enterpriseproject (class: org.jnp.interfaces.NamingContext)
  |   +- ThirdSessionBean (class: org.jnp.interfaces.NamingContext)
  |   |   +- remote (proxy: $Proxy112 implements interface com.tsb.test.ThirdSession,interface org.jboss.ejb3.proxy.JBossProxy)
  +- topic (class: org.jnp.interfaces.NamingContext)
  +- queue (class: org.jnp.interfaces.NamingContext)
  |   +- ExpiryQueue (class: org.jboss.jms.destination.JBossQueue)
  |   +- DLQ (class: org.jboss.jms.destination.JBossQueue)
  +- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
  +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
  +- jmx (class: org.jnp.interfaces.NamingContext)
  |   +- invoker (class: org.jnp.interfaces.NamingContext)
  |   |   +- RMIAdaptor (proxy: $Proxy80 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
  |   +- rmi (class: org.jnp.interfaces.NamingContext)
  |   |   +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
  +- ClusteredXAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
  +- TomcatAuthenticators (class: java.util.Properties)
  +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)

--------------- Eclipse Console -------

12:05:18,856 INFO  [JBossASKernel] Created KernelDeployment for: EJBProject.jar
12:05:18,856 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=enterpriseproject.ear,jar=EJBProject.jar,name=ThirdSessionBean,service=EJB3
12:05:18,856 INFO  [JBossASKernel]   with dependencies:
12:05:18,856 INFO  [JBossASKernel]   and demands:
12:05:18,856 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService
12:05:18,857 INFO  [JBossASKernel]   and supplies:
12:05:18,857 INFO  [JBossASKernel] 	Class:com.tsb.test.ThirdSession
12:05:18,857 INFO  [JBossASKernel] 	jndi:ThirdSessionBean
12:05:18,857 INFO  [JBossASKernel] 	jndi:enterpriseproject/ThirdSessionBean/remote-com.tsb.test.ThirdSession
12:05:18,857 INFO  [JBossASKernel] 	jndi:enterpriseproject/ThirdSessionBean/remote
12:05:18,857 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=enterpriseproject.ear,jar=EJBProject.jar,name=ThirdSessionBean,service=EJB3) to KernelDeployment of: EJBProject.jar
12:05:18,967 INFO  [EJBContainer] STARTED EJB: com.tsb.test.ThirdSessionBean ejbName: ThirdSessionBean
12:05:19,012 INFO  [TomcatDeployment] deploy, ctxPath=/DynamicWebProject, vfsUrl=enterpriseproject.ear/DynamicWebProject.war
12:06:44,247 INFO  [TomcatDeployment] undeploy, ctxPath=/DynamicWebProject, vfsUrl=enterpriseproject.ear/DynamicWebProject.war
12:06:44,256 INFO  [EJBContainer] STOPPED EJB: com.tsb.test.ThirdSessionBean ejbName: ThirdSessionBean
12:06:44,624 INFO  [STDOUT] ======> Creating interceptor metadata bridge
12:06:44,650 INFO  [JBossASKernel] Created KernelDeployment for: EJBProject.jar
12:06:44,651 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=enterpriseproject.ear,jar=EJBProject.jar,name=ThirdSessionBean,service=EJB3
12:06:44,651 INFO  [JBossASKernel]   with dependencies:
12:06:44,651 INFO  [JBossASKernel]   and demands:
12:06:44,651 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService
12:06:44,651 INFO  [JBossASKernel]   and supplies:
12:06:44,651 INFO  [JBossASKernel] 	Class:com.tsb.test.ThirdSession
12:06:44,651 INFO  [JBossASKernel] 	jndi:ThirdSessionBean
12:06:44,651 INFO  [JBossASKernel] 	jndi:enterpriseproject/ThirdSessionBean/remote-com.tsb.test.ThirdSession
12:06:44,651 INFO  [JBossASKernel] 	jndi:enterpriseproject/ThirdSessionBean/remote
12:06:44,651 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=enterpriseproject.ear,jar=EJBProject.jar,name=ThirdSessionBean,service=EJB3) to KernelDeployment of: EJBProject.jar
12:06:44,759 INFO  [EJBContainer] STARTED EJB: com.tsb.test.ThirdSessionBean ejbName: ThirdSessionBean
12:06:44,785 INFO  [TomcatDeployment] deploy, ctxPath=/DynamicWebProject, vfsUrl=enterpriseproject.ear/DynamicWebProject.war
12:07:30,999 INFO  [STDOUT] onject returned is jboss.j2ee:ear=enterpriseproject.ear,jar=EJBProject.jar,name=ThirdSessionBean,service=EJB3
12:07:31,000 INFO  [STDOUT] This works
12:07:31,000 ERROR [[SecondServlet]] Servlet.service() for servlet SecondServlet threw exception
java.lang.ClassCastException: $Proxy112 cannot be cast to com.tsb.test.ThirdSession
	at SecondServlet.doGet(SecondServlet.java:55)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)

---------------- Question --------

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4167981#4167981

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4167981



More information about the jboss-user mailing list