Hi ,
I have already deployed an
EJB jar (stateful session bean) file with Weblogic5.1 as App server.I wish to call thazt EJB from a
servlet client.Ths code is as follows
package examples.sampleejb;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
import javax.ejb.*;
import java.rmi.*;
public class client extends HttpServlet {
private static final
String CONTENT_TYPE = "text/html";
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**Process the HTTP Get request*/
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Hello its here");
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String s = "";
try
{
Context ctx = getInitialContext();
Object obj = ctx.lookup("sample");
sampleHome home = (sampleHome) PortableRemoteObject.narrow(obj, sampleHome.class);
sampleRemote remote = home.create();
s = remote.say("Mary");
}
catch (Exception e)
{
e.printStackTrace();
}
out.println("<html>");
out.println("<head><title>client</title></head>");
out.println("<body>");
out.println(s);
out.println("</body></html>");
}
static public Context getInitialContext() throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
return new InitialContext(p);
}
/**Clean up resources*/
public void destroy() {
}
}
=====================================================
The error on the weblogic server is as shown below.
============================================================
Sun Jan 14 16:28:24 GMT+05:30 2001:
<ServletContext-General> samp: init
Hello its here
java.lang.ClassCastException: examples.sampleejb.sampleBeanHomeImpl_ServiceStub
at examples.sampleejb.client.service(client.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:105)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)
===============================================================
Pl tell me where I am wrong in the servlet code
Thanx in advance