13 Replies Latest reply on Feb 5, 2013 1:39 AM by rahul22

    Handling NonexistentConversationException with Seam 3

    pgmjsd

      I wrote up a wiki page about my workaround for handling NonexistentConversationException more gracefully (like Seam 2):


      Handling NonexistentConversationException Gracefully


      Comments/questions/ideas are welcome!

        • 1. Re: Handling NonexistentConversationException with Seam 3
          lightguard

          Looks good, thanks Joshua!

          • 2. Re: Handling NonexistentConversationException with Seam 3
            hantsy

            Looks great, but this solution is dependent on the weld specific API.

            • 3. Re: Handling NonexistentConversationException with Seam 3
              pgmjsd

              hantsy bai wrote on Dec 21, 2011 03:24:


              Looks great, but this solution is dependent on the weld specific API.


              Correct.  However, it's a Weld bug that I'm working around. ;)

              • 4. Re: Handling NonexistentConversationException with Seam 3
                blabno

                Joshua, thanks for contribution. Configuring exception handling in Seam3 requires much more work than in Seam2 where we could define redirection + message for different exceptions in single pages.xml.


                Probably we could create annotation that would decorate ViewConfig enum i.e.: @Redirect(exceptionClass,message)

                • 5. Re: Handling NonexistentConversationException with Seam 3
                  lightguard

                  That could certainly be done, and there may be something similar, IIRC, in the Servlet code in Solder.

                  • 6. Re: Handling NonexistentConversationException with Seam 3
                    lucaster.luca.cavagnoli.gmail.com

                    Joshua, I read your wiki and tried to apply your workaround, but it doesn't work...


                    Your wiki reads:



                    Now, when the bad conversation id is encountered, the message will show up in the logs and the view will render.

                    Actually, the view does not get rendered with the code tou provided till that point! Instead, you get a HTTP Status 500.


                    Then, you suggest to do the following:


                    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,"No conversation!", exception.getMessage());
                    final FacesContext facesContext = FacesContext.getCurrentInstance();
                    facesContext.addMessage(null, msg);        facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext,null,"error");
                    



                    Where is this snipped of code supposed to belong? In the onNonexistentConversation() method?


                    The 1st instruction doesn't match the method signature. I suppose exception = evt.getException();


                    The 3rd and 4th instructions will cause NullPointerException because facesContext is null.


                    Also, what versions of Solder and JBoss AS did you test your workaround against? I'm using Solder 3.1.0.Final and JBoss AS 7.0.2.Final by the way.

                    • 7. Re: Handling NonexistentConversationException with Seam 3
                      pgmjsd

                      Luca Cavagnoli wrote on Jan 06, 2012 09:03:


                      Joshua, I read your wiki and tried to apply your workaround, but it doesn't work...

                      Your wiki reads:

                      Now, when the bad conversation id is encountered, the message will show up in the logs and the view will render.

                      Actually, the view does not get rendered with the code tou provided till that point! Instead, you get a HTTP Status 500.


                      The view rendered for me without errors.   I'm using:



                      • Seam 3.1.0.Beta1

                      • JBoss AS 7.0.2.Final 

                      • WAR deployment



                      There might be some differences in your environment that are causing this to behave differently.



                      Then, you suggest to do the following:

                      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,"No conversation!", exception.getMessage());
                      final FacesContext facesContext = FacesContext.getCurrentInstance();
                      facesContext.addMessage(null, msg);        facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext,null,"error");
                      



                      Where is this snipped of code supposed to belong? In the onNonexistentConversation() method?


                      Yes.  I've updated the page with the full method listing to avoid confusion.




                      The 1st instruction doesn't match the method signature. I suppose exception = evt.getException();



                      Yes.




                      The 3rd and 4th instructions will cause NullPointerException because facesContext is null.

                      Also, what versions of Solder and JBoss AS did you test your workaround against? I'm using Solder 3.1.0.Final and JBoss AS 7.0.2.Final by the way.


                      Actually, the 4th line won't execute because of the NPE. :)


                      The fact that FacesContext.getCurrentInstance() is returning null leads me to believe that something else is going on in your environment.   I'm not sure what that might be.   That's part of JSF, so it is not a Seam 3 issue.

                      • 8. Re: Handling NonexistentConversationException with Seam 3
                        lucaster.luca.cavagnoli.gmail.com

                        I have WAR deployment too.
                        I changed my configuration to match yours. Now I have the following Maven dependencies:




                        • org.jboss.spec : jboss-javaee-6.0 : 1.0.0.Final (pom) (provided)


                        • org.jboss.seam.solder : seam-solder : 3.1.0.Beta1 (runtime)


                        • org.jboss.seam.catch : seam-catch : 3.1.0.Beta2 (runtime)


                        • org.jboss.weld : weld-core:1.1.2.Final (complie)



                        Now, deployment fails with:


                        java.lang.ClassNotFoundException: org.jboss.logmanager.Logger$AttachmentKey



                        What are your dependencies, exactly?


                        Looking at your updated code, I notice an error: the line


                        import org.jboss.seam.logging.Logger:



                        should be


                        import org.jboss.seam.solder.logging.Logger;



                        • 9. Re: Handling NonexistentConversationException with Seam 3
                          pgmjsd

                          Luca Cavagnoli wrote on Jan 06, 2012 14:41:


                          I have WAR deployment too.
                          I changed my configuration to match yours. Now I have the following Maven dependencies:



                          • org.jboss.spec : jboss-javaee-6.0 : 1.0.0.Final (pom) (provided)


                          • org.jboss.seam.solder : seam-solder : 3.1.0.Beta1 (runtime)


                          • org.jboss.seam.catch : seam-catch : 3.1.0.Beta2 (runtime)


                          • org.jboss.weld : weld-core:1.1.2.Final (complie)



                          Now, deployment fails with:

                          java.lang.ClassNotFoundException: org.jboss.logmanager.Logger$AttachmentKey





                          You need to tell JBoss AS to give your application access to the org.jboss.logmanager stuff.   My WEB-INF/jboss-deployment-structure.xml looks like this:


                          <?xml version="1.0" encoding="UTF-8"?>
                          <jboss-deployment-structure>
                              <deployment>
                                <dependencies>
                                  <module name="org.jboss.logmanager"/>
                                  <module name="org.slf4j"/>
                                </dependencies>
                              </deployment>
                          </jboss-deployment-structure>
                          



                          I use both Seam Solder Logging and SLF4J.  You don't have to use it.



                          What are your dependencies, exactly?

                          Looking at your updated code, I notice an error: the line

                          import org.jboss.seam.logging.Logger:



                          should be

                          import org.jboss.seam.solder.logging.Logger;






                          That's what happens when you copy paste stuff from some random wiki into your code. ;)


                          Sorry, I'm using 3.1.0.Beta2, where org.jboss.seam.logging.Logger is the correct class.  My dependencies are:


                          $ mvn dependency:list | grep seam
                          [INFO]    org.jboss.seam.catch:seam-catch:jar:3.1.0.Beta2:runtime
                          [INFO]    org.jboss.seam.catch:seam-catch-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.faces:seam-faces:jar:3.1.0.Beta2:runtime
                          [INFO]    org.jboss.seam.faces:seam-faces-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.international:seam-international:jar:3.1.0.Beta2:runtime
                          [INFO]    org.jboss.seam.international:seam-international-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.persistence:seam-persistence:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.persistence:seam-persistence-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.servlet:seam-servlet:jar:3.1.0.Beta2:runtime
                          [INFO]    org.jboss.seam.servlet:seam-servlet-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.solder:seam-solder:jar:3.1.0.Beta2:runtime
                          [INFO]    org.jboss.seam.solder:seam-solder-api:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.solder:seam-solder-logging:jar:3.1.0.Beta2:compile
                          [INFO]    org.jboss.seam.transaction:seam-transaction-api:jar:3.1.0.Beta2:compile
                          



                          I use seam-bom to set all the versions:


                             <dependencyManagement>
                                  <dependencies>
                                      <!-- Use seam-bom to define all the versions so we don't have to -->
                                      <dependency>
                                          <groupId>org.jboss.seam</groupId>
                                          <artifactId>seam-bom</artifactId>
                                          <version>${version.seam}</version>
                                          <scope>import</scope>
                                          <type>pom</type>
                                      </dependency>
                          ... blah blah blah ...
                          


                          • 10. Re: Handling NonexistentConversationException with Seam 3
                            lucaster.luca.cavagnoli.gmail.com

                            The main difference between our configurations was seam-faces.


                            So, I tried again you workaround with my configuration (3.1.0.Final), but adding the following dependencies:


                            <dependency>
                                 <groupId>org.jboss.seam.faces</groupId>
                                 <artifactId>seam-faces-api</artifactId>
                                 <version>${seam.version}</version>
                                 <scope>compile</scope>
                            </dependency>
                            <dependency>
                                 <groupId>org.jboss.seam.faces</groupId>
                                 <artifactId>seam-faces</artifactId>
                                 <version>${seam.version}</version>
                                 <scope>runtime</scope>
                            </dependency>
                            <dependency>
                                 <groupId>org.jboss.seam.international</groupId>
                                 <artifactId>seam-international-api</artifactId>
                                 <version>${seam.version}</version>
                                 <scope>compile</scope>
                            </dependency>
                            <dependency>
                                 <groupId>org.jboss.seam.international</groupId>
                                 <artifactId>seam-international</artifactId>
                                 <version>${seam.version}</version>
                                 <scope>runtime</scope>
                            </dependency>
                            <dependency>
                                 <groupId>joda-time</groupId>
                                 <artifactId>joda-time</artifactId>
                                 <version>1.6.2</version>
                            </dependency>
                            <dependency>
                                 <groupId>com.ocpsoft</groupId>
                                 <artifactId>prettyfaces-jsf2</artifactId>
                                 <version>3.3.2</version>
                            </dependency>



                            And it worked! ;)

                            • 11. Re: Handling NonexistentConversationException with Seam 3
                              pgmjsd

                              Good.  I'll update it when I get a chance to upgrade the Seam version.

                              • 12. Re: Handling NonexistentConversationException with Seam 3
                                filosofisto

                                Hi Joshua, I have same problem:

                                 

                                When try conversationContext.activate(null) in my Handler, I received a "Context alread active" Exception!!!

                                 

                                Caused by: java.lang.IllegalStateException: Context is already active

                                          at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:227) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                                          at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:175) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]

                                          at com.stesa.siam.exception.ExceptionHandler.handleConstraintViolationException(ExceptionHandler.java:57) [classes:]

                                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_09-icedtea]

                                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_09-icedtea]

                                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_09-icedtea]

                                          at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_09-icedtea]

                                          at org.jboss.solder.reflection.Reflections.invokeMethod(Reflections.java:474) [solder-api-3.1.0.Final.jar:3.1.0.Final]

                                 

                                I'm using

                                 

                                weld-api 1.1.Final

                                seam 3.1.0.Final (bom)

                                 

                                Those things beacame Seam3 hard

                                • 13. Re: Handling NonexistentConversationException with Seam 3
                                  rahul22

                                  hi joshua ,

                                   

                                  can you bring some light on https://community.jboss.org/message/795894#795894 ???/

                                   

                                  Thanks