Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-957

Support transaction interceptor with JavaBeans and custom servlets

    Details

    • Type: Feature Request
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      I'm using <web:context-filter url-pattern="/files/*"/> and a custom FileServlet:

      This works:

      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

      String id = request.getParameter("fileId");

      NodeDAO nodeDAO = (NodeDAO) org.jboss.seam.Component.getInstance("nodeDAO");

      org.jboss.seam.wiki.core.node.File file;
      UserTransaction userTx = null;
      try

      { userTx = Transactions.getUserTransaction(); userTx.begin(); file = (id != null && !"".equals(id)) ? nodeDAO.findFile(Long.getLong(id)) : null; userTx.commit(); }

      catch (Exception ex) {
      try

      { if (userTx != null) userTx.rollback(); }

      catch (Exception rbEx)

      { rbEx.printStackTrace(); }

      throw new RuntimeException(ex);
      }

      This doesn't work because no JTA transaction is active when my JavaBean DAO is called (all methods there are annotated @Transactional):

      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

      String id = request.getParameter("fileId");

      NodeDAO nodeDAO = (NodeDAO) org.jboss.seam.Component.getInstance("nodeDAO");

      org.jboss.seam.wiki.core.node.File file = (id != null && !"".equals(id)) ? nodeDAO.findFile(Long.getLong(id)) : null;

      The Seam (seamspace) examples use EJB components, so this probably never came up before.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                gavin.king Gavin King
                Reporter:
                christian.bauer Christian Bauer
              • Votes:
                2 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: