2 Replies Latest reply on Jan 10, 2012 3:55 AM by jharting

    How to manage conversation with restful application

    diegocoronel

      Hi,


      Im using Rest in my application and im trying to begin a conversation but i cant because im getting this error:




      org.jboss.resteasy.spi.UnhandledException: javax.enterprise.context.ContextNotActiveException: Conversation Context not active when method called on conversation Transient conversation
      


      so, is there any way to enable it?


      Env:
      JBoss 7.0.2 and all tec. inside it, like JPA2, EJB and REST.



      ty

        • 1. Re: How to manage conversation with restful application
          diegocoronel

          Hi, i did a filter to enable conversation and everything is working as expected, but i wanna know if can i have any problems or memory leaks with my solution:




          @WebFilter( urlPatterns = "/rest/*")
          public class RestFilter implements Filter {
          
               @Override
               public void destroy() {
                    
               }
          
               @Override
               public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
                    String cid = ( String ) arg0.getParameterMap().get("cid")[0];
                    ConversationContext conversationContext = instance().select(HttpConversationContext.class).get();
                    
                    if ( !conversationContext.isActive() ) {
                         try {
                              conversationContext.activate( cid );     
                         } catch ( NonexistentConversationException non ) {
                              
                         }
                    }
                    arg2.doFilter(arg0, arg1);
                    conversationContext.invalidate();
                    conversationContext.deactivate();
               }
          
               @Override
               public void init(FilterConfig arg0) throws ServletException {
                    
               }
               
                private static Instance<Context> instance() {
                  return Container.instance().deploymentManager().instance().select(Context.class);
               }
          
          }
          



          This filter is applied only for my rest services.

          • 2. Re: How to manage conversation with restful application
            jharting

            FYI, Weld 2 (not released yet) has conversation support for every Servlet request. See WeldListener for details.