Simple SessionBean --- ClassCastException
bronks Aug 18, 2006 8:29 AMHi!
I am using the JBossIDE 1.5.1 and JBossAS 4.04.
I have coded a simple SessionBean and a Servlet. Please take a look at the code below.
The deployment of the ejb.jar seems to be ok: [ProxyFactory] Bound EJB Home 'Hello' to jndi 'ejb/Hello'
When i am accessing the servlet i am getting an java.lang.ClassCastException in the servlet at line marked with ">>>>>>>".
I have spent 4 hour and can not find a mistake.
Please take a look at my code an tell me what is wrong.
Thanks
Bronks
package testProjekt;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
/**
* @ejb.bean name="Hello"
* display-name="Name for Hello"
* description="Description for Hello"
* jndi-name="ejb/Hello"
* type="Stateless"
* view-type="remote"
*/
public class HelloBean implements SessionBean {
public HelloBean() {
super();
// TODO Auto-generated constructor stub
}
public void setSessionContext(SessionContext ctx)
throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/**
* Default create method
*
* @throws CreateException
* @ejb.create-method
*/
public void ejbCreate() throws CreateException {
// TODO Auto-generated method stub
}
/**
* Business method
* @ejb.interface-method view-type="remote"
* @generated
*/
public String hello() {
return new String("Hello ...!");
}
}
package web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import testProjekt.*;
/**
* @web.servlet
* name="testservlet"
* display-name="Test Servlet"
* description="Servlet for testing"
*
* @web.servlet-mapping
* url-pattern="/testservlet"
*
*/
public class TestServlet extends HttpServlet implements
javax.servlet.Servlet{
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException {
PrintWriter out = resp.getWriter();
out.println("Executing the servlet");
try {
InitialContext context = new InitialContext(System.getProperties());
>>>>>>> HelloHome home = (HelloHome) context.lookup(HelloHome.JNDI_NAME);
Hello bean = home.create();
String testtext = bean.hello();
out.println(testtext);
}catch(Exception e){e.printStackTrace();}
}
}