users@glassfish.java.net

GlassFish Cannot Find SFSBs After a RuntimeException

From: <glassfish_at_javadesktop.org>
Date: Thu, 26 Feb 2009 08:50:05 PST

Hello,

When an uncaught runtime exception is thrown in the middle of an SFSB operation, GlassFish cannot find that SFSB on consequent calls that are made from the same client (which is a servlet in my situation), and throws a javax.ejb.NoSuchEjbException.

I know it is acceptable because the client has lost the SFSB reference because of the runtime exception. But the problem does not disappear even when the calls are made from a new session (I assume a new session starts when a restart my browser and request the servlet again). GlassFish continues to complain of no such ejb.

The following example illustrates the problem.

@Local
public interface SimpleEjb {
&nbsp;&nbsp;String aMethod();
&nbsp;&nbsp;String bMethod();
}

@Stateful
public class SimpleEjbImpl implements SimpleEjb {
&nbsp;&nbsp;public String aMethod() {
&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("Deliberately thrown");
&nbsp;&nbsp;}

&nbsp;&nbsp;public String bMethod() {
&nbsp;&nbsp;&nbsp;&nbsp;return "SimpleEjb.bMethod";
&nbsp;&nbsp;}
}


This is my ejb component. When I request a servlet that calls aMethod; RuntimeException is thrown and operation fails. After that I restart my browser and request the same servlet, this time it should call bMethod, but a NoSucEjbException is thrown. Here is my servlet implementation:

public class SimpleServlet extends HttpServlet {
  
&nbsp;&nbsp;private static boolean isFirstRequest = true;
  
&nbsp;&nbsp;@EJB private SimpleEjb simpleEjb;

&nbsp;&nbsp;protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
&nbsp;&nbsp;&nbsp;&nbsp;String msg = null;
&nbsp;&nbsp;&nbsp;&nbsp;if(isFirstRequest) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isFirstRequest = false; // this is set before the exception is thrown
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;simpleEjb.aMethod(); // throws RuntimeException
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg = simpleEjb.bMethod();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;req.setAttribute("msg", msg);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rd.forward(req, res);
&nbsp;&nbsp;}
}

I have attached the ear that contains my ejb and web modules and source code.
[Message sent by forum member 'bsevindi' (bsevindi)]

http://forums.java.net/jive/thread.jspa?messageID=334037