Search in sources :

Example 1 with Incrementor

use of org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor in project wildfly by wildfly.

the class StatefulServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String module = getRequiredParameter(req, MODULE);
    String bean = getRequiredParameter(req, BEAN);
    HttpSession session = req.getSession(true);
    Incrementor incrementor = (Incrementor) session.getAttribute(BEAN);
    if (incrementor == null) {
        try (LocalEJBDirectory directory = new LocalEJBDirectory(module)) {
            incrementor = directory.lookupStateful(bean, Incrementor.class);
        } catch (NamingException e) {
            throw new ServletException(e);
        }
    }
    try {
        resp.setHeader(COUNT, String.valueOf(incrementor.increment()));
        session.setAttribute(BEAN, incrementor);
    } catch (NoSuchEJBException e) {
        resp.setHeader(COUNT, String.valueOf(0));
        session.removeAttribute(BEAN);
    }
    resp.getWriter().write("Success");
}
Also used : ServletException(javax.servlet.ServletException) NoSuchEJBException(javax.ejb.NoSuchEJBException) HttpSession(javax.servlet.http.HttpSession) Incrementor(org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor) NamingException(javax.naming.NamingException) LocalEJBDirectory(org.jboss.as.test.clustering.ejb.LocalEJBDirectory)

Aggregations

NoSuchEJBException (javax.ejb.NoSuchEJBException)1 NamingException (javax.naming.NamingException)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1 Incrementor (org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor)1 LocalEJBDirectory (org.jboss.as.test.clustering.ejb.LocalEJBDirectory)1