5 Replies Latest reply on Feb 23, 2011 3:02 PM by Bojan Kovacevic

    Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)

    Francois Swiegers Newbie

      Good day,

      I am using SFSB together with the ConversationScope in order to have reentrant access to the same SFSB instance from a Hessian client, like so:

      public class MySfsb {
        @Inject Conversation conversation;
        public void start() {

      I then use the CID conversation parameter to propagate my request from my remote Hession client, using a request paramater.

      This all works in Jboss 6 M5 and Glassfish 3.1 build 28. However, from build 31 onwards, Glassfish is using Weld 1.1.0-Beta2, and now the Conversation context in Glassfish is not active anymore for the above scenario:

      org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
           at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:639)
           at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:73)
           at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:48)

      What is the right way to use the conversation scope in a JavaEE 6 application that does not use JSF, but has a servlet entry point? I looked at Seam-Remoting, but the trunk version still uses Weld 1.0.1's ConversationManager, which I can't find in Weld 1.1.0-Beta2. I also looked at the ConversationContext from Weld SPI, like so:

      public class MyHessionEntryPoint extends HessianServlet {
      private ConversationContext conversationContext;
        public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException {
        String id = request.getParameter("cid");
        if (id != null) {
        } else {
        super.service(request, response);

      With this code, the ConversationScope is active again, but my long running conversations do not get restored upon activate(cid), resulting in NullPointerExceptions in my SFSB.

      Is there some documentation that explains how to activate and manage conversations?

        • 1. Re: Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)
          Francois Swiegers Newbie

          OK, to simplify a bit, I took a look at the ExecutorHandler from Seam Remoting (the real latest one from 
          github), and according to how they do things, the following should work:

          public class MyServlet extends HttpServlet {
               private static final long serialVersionUID = 1L;
               ConversationContext conversationContext;
               Conversation conversation;
               BeanManager beanManager;
               protected void service(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException, IOException {
                    String cid = request.getParameter("cid");
                    try {
                         Bean<?> bean = beanManager.getBeans(MyConversation.class)
                         CreationalContext<?> ctx = beanManager
                         MyConversation mc = (MyConversation) beanManager.getReference(bean,
                                   MyConversation.class, ctx);
                         String out = mc.increment();
                                   "Value for " + conversation.getId() + " is : " + out);
                    } finally {
               public static class MyConversation implements Serializable {
                    private static final long serialVersionUID = 1L;
                    Conversation conversation;
                    private int num;
                    public String increment() {
                         if (conversation.isTransient()) {
                         return String.valueOf(num++);

          The above servlet should allow the user to increment the value in a conversation by simply appending the cid parameter to the servlet URL.

          However, it simply does not work. The


          method simply creates a new conversation, regardless of whether that conversation ID was generated and made non-transient in a previous request.

          Does Weld support conversations from servlets? I don't mind doing a little non-portable tap-dancing, but if Weld does not currently support this, can you please let me know?


          • 2. Re: Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)
            Francois Swiegers Newbie

            Just an update to this, I made the above code work by simply adding


            as the first statement in my servlet. It seems that the ConversationManager requires the session to be instantiated before calling the deactivate() method, which is reasonable. It is only in small example apps that the session would not be created by the time the conversation is deactivated. :)

            • 3. Re: Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)
              Cloves Almeida Newbie

              Yet, this is a hard to debug problem. Should be part of the Javadoc.

              • 4. Re: Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)
                Sergio Samayoa Newbie
                FWIW, Same with Tomcat 7 + weld 1.1.0CR1, I mean:


                • 5. Re: Conversation Scope in Weld 1.1.0-Beta2 (with Glassfish 3.1)
                  Bojan Kovacevic Newbie

                  Thanks for the tip. Really helpful.
                  I like when people share their findings. :)