Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-2119

Portable war: Weld deployment on JBoss AS 7 should not require to remove the WeldListener line from the web.xml

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 7.1.0.Alpha1
    • Fix Version/s: 7.1.0.Beta1
    • Component/s: None
    • Labels:
      None

      Description

      When deploying on JBoss AS 7, the web.xml can't contain this:

        <listener>
          <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
        </listener>
      

      When deploying on any other app servers (JBoss AS 5.1 EAP, Tomcat 6, Jetty 6, ...) that code needs to be there.
      This makes for an unportable wars.

      Maven profiles cannot fix this in many cases:

      • You don't want to run your build 5 times to build 5 different wars. You run it once, build a generic war and use assembly descriptors to build 5 appserver specific wars from that.
      • When you're using GWT, you want run in GWT-hosted mode (which uses jetty 6) a lot. So the default web.xml needs to contain it.
      • When you're using arquillian-jboss7 (in maven and straight for your IDE), the default web.xml should not have it.
      • When you're deploying a generic war to nexus, the web.xml should contain it?

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            Take the pain away from the users.

            Solution proposal 1:
            WeldListener checks on what appserver/version it is and only activates itself if it's jetty, tomcat, jboss-5.1

            Solution proposal 2:
            WeldListener checks on what appserver/version it is and does not activates itself if it's jboss 6 or jboss 7

            Show
            ge0ffrey Geoffrey De Smet added a comment - Take the pain away from the users. Solution proposal 1: WeldListener checks on what appserver/version it is and only activates itself if it's jetty, tomcat, jboss-5.1 Solution proposal 2: WeldListener checks on what appserver/version it is and does not activates itself if it's jboss 6 or jboss 7
            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            Solution proposal 3:
            WELD-718 but that doesn't work on serlvet 2.5 containers such as tomcat and jetty. So I don't think its a good idea.

            Show
            ge0ffrey Geoffrey De Smet added a comment - Solution proposal 3: WELD-718 but that doesn't work on serlvet 2.5 containers such as tomcat and jetty. So I don't think its a good idea.
            Hide
            ge0ffrey Geoffrey De Smet added a comment - - edited

            Here's a workaround I wrote following solution 1 and 2.
            It works when weld-servlet.jar is excluded from the war on jboss 7 (which is very annoying to do). Note that SafeWeldListener is in my codebase (so not in weld-servlet.jar of course).

            /**
             * Workaround for https://issues.jboss.org/browse/WELD-983
             */
            public class SafeWeldListener implements ServletContextListener, HttpSessionListener, ServletRequestListener {
             
                private Boolean onJBoss7 = null;
                private ServletContextListener servletContextListener;
                private HttpSessionListener httpSessionListener;
                private ServletRequestListener servletRequestListener;
             
                private void checkOnJBoss(String serverInfo) {
                    onJBoss7 = serverInfo.startsWith("JBoss Web/7.");
                    if (!onJBoss7) {
                        // Note that weldListener is not a global variable to avoid a ClassNotFoundException on JBoss 7
                        Listener weldListener = new Listener();
                        servletContextListener = weldListener;
                        httpSessionListener = weldListener;
                        servletRequestListener = weldListener;
                    }
                }
             
                public void contextInitialized(ServletContextEvent sce) {
                    checkOnJBoss(sce.getServletContext().getServerInfo());
                    if (onJBoss7) {
                        return;
                    }
                    servletContextListener.contextInitialized(sce);
                }
             
                public void contextDestroyed(ServletContextEvent sce) {
                    if (onJBoss7) {
                        return;
                    }
                    servletContextListener.contextDestroyed(sce);
                }
             
                public void sessionCreated(HttpSessionEvent se) {
                    if (onJBoss7) {
                        return;
                    }
                    httpSessionListener.sessionCreated(se);
                }
             
                public void sessionDestroyed(HttpSessionEvent event) {
                    if (onJBoss7) {
                        return;
                    }
                    httpSessionListener.sessionDestroyed(event);
                }
             
                public void requestDestroyed(ServletRequestEvent event) {
                    if (onJBoss7) {
                        return;
                    }
                    servletRequestListener.requestDestroyed(event);
                }
             
                public void requestInitialized(ServletRequestEvent event) {
                    if (onJBoss7) {
                        return;
                    }
                    servletRequestListener.requestInitialized(event);
                }
             
            }
            

            Show
            ge0ffrey Geoffrey De Smet added a comment - - edited Here's a workaround I wrote following solution 1 and 2. It works when weld-servlet.jar is excluded from the war on jboss 7 (which is very annoying to do). Note that SafeWeldListener is in my codebase (so not in weld-servlet.jar of course). /** * Workaround for https://issues.jboss.org/browse/WELD-983 */ public class SafeWeldListener implements ServletContextListener, HttpSessionListener, ServletRequestListener {   private Boolean onJBoss7 = null; private ServletContextListener servletContextListener; private HttpSessionListener httpSessionListener; private ServletRequestListener servletRequestListener;   private void checkOnJBoss(String serverInfo) { onJBoss7 = serverInfo.startsWith("JBoss Web/7."); if (!onJBoss7) { // Note that weldListener is not a global variable to avoid a ClassNotFoundException on JBoss 7 Listener weldListener = new Listener(); servletContextListener = weldListener; httpSessionListener = weldListener; servletRequestListener = weldListener; } }   public void contextInitialized(ServletContextEvent sce) { checkOnJBoss(sce.getServletContext().getServerInfo()); if (onJBoss7) { return; } servletContextListener.contextInitialized(sce); }   public void contextDestroyed(ServletContextEvent sce) { if (onJBoss7) { return; } servletContextListener.contextDestroyed(sce); }   public void sessionCreated(HttpSessionEvent se) { if (onJBoss7) { return; } httpSessionListener.sessionCreated(se); }   public void sessionDestroyed(HttpSessionEvent event) { if (onJBoss7) { return; } httpSessionListener.sessionDestroyed(event); }   public void requestDestroyed(ServletRequestEvent event) { if (onJBoss7) { return; } servletRequestListener.requestDestroyed(event); }   public void requestInitialized(ServletRequestEvent event) { if (onJBoss7) { return; } servletRequestListener.requestInitialized(event); }   }
            Hide
            pmuir Pete Muir added a comment -

            It would be better to make this not needed on servlet containers

            Show
            pmuir Pete Muir added a comment - It would be better to make this not needed on servlet containers
            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            Another alternative on how to solve it:
            Create a dummy class with the same name on jboss 7 that does nothing.

            But if you can make it not needed on servlet containers (including servlet 2.5 containers!) then the better

            Show
            ge0ffrey Geoffrey De Smet added a comment - Another alternative on how to solve it: Create a dummy class with the same name on jboss 7 that does nothing. But if you can make it not needed on servlet containers (including servlet 2.5 containers!) then the better
            Hide
            swd847 Stuart Douglas added a comment -

            I moved this to an AS7 issue, as it is trivial to fix in the AS7 web integration code.

            Show
            swd847 Stuart Douglas added a comment - I moved this to an AS7 issue, as it is trivial to fix in the AS7 web integration code.

              People

              • Assignee:
                swd847 Stuart Douglas
                Reporter:
                ge0ffrey Geoffrey De Smet
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development