12 Replies Latest reply on Feb 17, 2011 10:16 AM by lightguard

    Seam Catch doesn't Catch

    marx3

      I tried to fire example from Seam Catch documentation. Apart form event.proceed not compilable (probably API has changed to exclude this method) it compiled and deployed properly. Hovewer nothing is catched. I generate simple exception in managed bean, exception is shown on the web, but exception handler doesn't execute - I see nothing in Jboss log. Here is my class:




          public void logException(
                  @Handles(during = TraversalMode.BREADTH_FIRST, precedence = 100) final CaughtException<Exception> event) {
              // System.out.println("Something bad happened: " + evt.getException().getMessage());
              System.out.println("!!!!!!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!");
              ExceptionStack c = event.getExceptionStack();
              System.out.println("Caught exception (" + (c.getIndex() + 1) + " in stack of " + c.getCauseElements().size()
                      + ") => " + event.getException().getClass().getSimpleName() + "(\"" + event.getException().getMessage()
                      + "\") ");
          }
      


      and here is my bean


      @SessionScoped
      @Named
      public class Login implements Serializable {
          public void makeError() throws Exception {
              System.out.println("I do Exception");
              throw new Exception("test");
      }
      



      Ps. As I remember, in near future (today?) it is planned to release new versions of Seam package?





        • 1. Re: Seam Catch doesn't Catch
          lightguard

          Sorry Catch isn't working for you, it should be working just fine, let's see if we can figure out what's going on.



          Marek Nazarko wrote on Feb 10, 2011 05:58:


          I tried to fire example from Seam Catch documentation. Apart form event.proceed not compilable (probably API has changed to exclude this method) it compiled and deployed properly. Hovewer nothing is catched. I generate simple exception in managed bean, exception is shown on the web, but exception handler doesn't execute - I see nothing in Jboss log. Here is my class:



              public void logException(
                      @Handles(during = TraversalMode.BREADTH_FIRST, precedence = 100) final CaughtException<Exception> event) {
                  // System.out.println("Something bad happened: " + evt.getException().getMessage());
                  System.out.println("!!!!!!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!");
                  ExceptionStack c = event.getExceptionStack();
                  System.out.println("Caught exception (" + (c.getIndex() + 1) + " in stack of " + c.getCauseElements().size()
                          + ") => " + event.getException().getClass().getSimpleName() + "(\"" + event.getException().getMessage()
                          + "\") ");
              }
          



          Do you have the @HandlesException annotation on this class? If not then your handler will not be picked up. Sorry about the proceed() being renamed, I missed in the docs with the last release, it's now called markHandled(). It's still the default and not required should you want the default behavior.



          and here is my bean

          @SessionScoped
          @Named
          public class Login implements Serializable {
              public void makeError() throws Exception {
                  System.out.println("I do Exception");
                  throw new Exception("test");
          }
          



          Ps. As I remember, in near future (today?) it is planned to release new versions of Seam package?


          What other modules are you using?  If you are using Seam Servlet or Seam Faces then this should be picked up and passed to Catch, if not then you'll need to fire the event:

          @Inject Event <ExceptionToCatch> event
           ... 
          event.fire(new ExceptionToCatch(new Exception()));

          • 2. Re: Seam Catch doesn't Catch
            marx3

            Thank you for response. I didn't have Seam Faces (no mention in doc as it's requirements). I've tried to add it, but I probably need to wait for new versions, because there is mix of versions in repository. Some requires Seam Solder Beta 1, some 2. New versions require sometimes even Beta 4...

            • 3. Re: Seam Catch doesn't Catch
              ssachtleben.ssachtleben.gmail.com

              I'm currently runing two setups with snapshots (except rest isnt working as snapshot for me):


                 <properties>
                    <seam.bom.version>3.0.0.b08</seam.bom.version>
                    <seam.solder.version>3.0.0-SNAPSHOT</seam.solder.version>
                    <seam.catch.version>3.0.0-SNAPSHOT</seam.catch.version>
                    <seam.config.version>3.0.0-SNAPSHOT</seam.config.version>
                    <seam.faces.version>3.0.0-SNAPSHOT</seam.faces.version>
                    <seam.international.version>3.0.0-SNAPSHOT</seam.international.version>
                    <seam.persistence.version>3.0.0-SNAPSHOT</seam.persistence.version>
                    <seam.rest.version>3.0.0.Beta1</seam.rest.version>
                    <seam.security.version>3.0.0-SNAPSHOT</seam.security.version>
                    <seam.servlet.version>3.0.0-SNAPSHOT</seam.servlet.version>
                  </properties>



              or version before seams heavenly changed and some versions where temporarly incompatible:


                 <properties>
                    <seam.bom.version>3.0.0.b09</seam.bom.version> 
                    <seam.solder.version>3.0.0.Beta4</seam.solder.version>
                    <seam.catch.version>3.0.0.Beta1</seam.catch.version>
                    <seam.config.version>3.0.0.Beta3</seam.config.version>
                    <seam.faces.version>3.0.0.Beta2</seam.faces.version>
                    <seam.international.version>3.0.0.Beta1</seam.international.version>
                    <seam.persistence.version>3.0.0.Beta4</seam.persistence.version>
                    <seam.security.version>3.0.0.Beta1</seam.security.version>
                    <seam.servlet.version>3.0.0.Beta2</seam.servlet.version>
                  </properties>



              Both version settings work fine with this dependency mapping (u just get the defined versions):


                    <dependency>
                       <groupId>org.jboss.seam.solder</groupId>
                       <artifactId>seam-solder-api</artifactId>
                       <version>${seam.solder.version}</version>
                    </dependency>   
                    
                    <dependency>
                       <groupId>org.jboss.seam.solder</groupId>
                       <artifactId>seam-solder-impl</artifactId>
                       <version>${seam.solder.version}</version>
                    </dependency>         
                     
                    <dependency>
                       <groupId>org.jboss.seam.faces</groupId>
                       <artifactId>seam-faces-api</artifactId>
                       <version>${seam.faces.version}</version>
                                       <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.international</groupId>
                                                 <artifactId>seam-international</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>                              
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                              
                                            <exclusion>
                                                 <groupId>org.jboss.weld</groupId>
                                                 <artifactId>weld-extensions</artifactId>
                                            </exclusion>                                   
                                       </exclusions>          
                    </dependency>
                     
                    <dependency>
                       <groupId>org.jboss.seam.faces</groupId>
                       <artifactId>seam-faces-impl</artifactId>
                       <version>${seam.faces.version}</version>
                       <scope>runtime</scope>
                                       <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.international</groupId>
                                                 <artifactId>seam-international</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>                              
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                              
                                            <exclusion>
                                                 <groupId>org.jboss.weld</groupId>
                                                 <artifactId>weld-extensions</artifactId>
                                            </exclusion>                                   
                                       </exclusions>          
                    </dependency>       
                    
                    <dependency>
                       <groupId>org.jboss.seam.international</groupId>
                       <artifactId>seam-international-api</artifactId>
                       <version>${seam.international.version}</version>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>          
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                 
                                       </exclusions>         
                    </dependency>      
                             
                    <dependency>
                       <groupId>org.jboss.seam.international</groupId>
                       <artifactId>seam-international-impl</artifactId>
                       <version>${seam.international.version}</version>
                       <scope>runtime</scope>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>          
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                 
                                       </exclusions>         
                    </dependency>                 
                             
                             <dependency>
                               <groupId>org.jboss.seam.persistence</groupId>
                               <artifactId>seam-persistence-api</artifactId>
                               <version>${seam.persistence.version}</version>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                      
                                       </exclusions>                     
                             </dependency>
                             
                             <dependency>
                               <groupId>org.jboss.seam.persistence</groupId>
                               <artifactId>seam-persistence-impl</artifactId>
                               <version>${seam.persistence.version}</version>
                               <scope>runtime</scope>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                      
                                       </exclusions>                     
                             </dependency>               
              
                             <dependency>
                                <groupId>org.jboss.seam.security</groupId>
                                <artifactId>seam-security-api</artifactId>
                                <version>${seam.security.version}</version>          
                                        <exclusions>                         
                                            <exclusion>
                                                 <groupId>org.jboss.seam.persistence</groupId>
                                                 <artifactId>seam-persistence</artifactId>
                                            </exclusion>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>                                                                 
                                       </exclusions>                      
                             </dependency>
              
                             <dependency>
                                <groupId>org.jboss.seam.security</groupId>
                                <artifactId>seam-security-impl</artifactId>
                                <version>${seam.security.version}</version>
                                <scope>runtime</scope>
                                        <exclusions>               
                                            <exclusion>
                                                 <groupId>org.jboss.seam.international</groupId>
                                                 <artifactId>seam-international</artifactId>
                                            </exclusion>                                                   
                                            <exclusion>
                                                 <groupId>org.jboss.seam.persistence</groupId>
                                                 <artifactId>seam-persistence</artifactId>
                                            </exclusion>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>                                                                 
                                       </exclusions>                    
                             </dependency>
                    
                    <dependency>
                       <groupId>org.jboss.seam.rest</groupId>
                       <artifactId>seam-rest-api</artifactId>
                       <version>${seam.rest.version}</version>
                                       <exclusions>               
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                            
                                       </exclusions>           
                    </dependency>  
                    
                    <dependency>
                       <groupId>org.jboss.seam.rest</groupId>
                       <artifactId>seam-rest-impl</artifactId>
                       <version>${seam.rest.version}</version>
                       <scope>runtime</scope>
                                       <exclusions>               
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                            
                                       </exclusions>           
                    </dependency>      
                    
                    <dependency>
                       <groupId>org.jboss.seam.servlet</groupId>
                       <artifactId>seam-servlet-api</artifactId>
                       <version>${seam.servlet.version}</version>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                      
                                       </exclusions>           
                    </dependency>   
                    
                    <dependency>
                       <groupId>org.jboss.seam.servlet</groupId>
                       <artifactId>seam-servlet-impl</artifactId>
                       <version>${seam.servlet.version}</version>
                       <scope>runtime</scope>
                                        <exclusions>                    
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                      
                                       </exclusions>           
                    </dependency>                        
              
                    <dependency>
                       <groupId>org.jboss.seam.catch</groupId>
                       <artifactId>seam-catch-api</artifactId>
                       <version>${seam.catch.version}</version>
                                       <exclusions>               
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                            
                                       </exclusions>           
                    </dependency>  
                    
                    <dependency>
                       <groupId>org.jboss.seam.catch</groupId>
                       <artifactId>seam-catch-impl</artifactId>
                       <version>${seam.catch.version}</version>
                       <scope>runtime</scope>
                                       <exclusions>               
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                            
                                       </exclusions>           
                    </dependency>        
              
                    <dependency>
                       <groupId>org.jboss.seam.config</groupId>
                       <artifactId>seam-config-xml</artifactId>
                       <version>${seam.config.version}</version>
                       <scope>runtime</scope>
                       <exclusions>
                          <exclusion>
                             <groupId>javax.enterprise</groupId>
                             <artifactId>cdi-api</artifactId>
                          </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.weld</groupId>
                                                 <artifactId>weld-extensions</artifactId>
                                            </exclusion>     
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder</artifactId>
                                            </exclusion>                                 
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-api</artifactId>
                                            </exclusion>
                                            <exclusion>
                                                 <groupId>org.jboss.seam.solder</groupId>
                                                 <artifactId>seam-solder-impl</artifactId>
                                            </exclusion>                                                                                           
                       </exclusions>
                    </dependency>
              



              Hopefully it helps a bit!

              • 4. Re: Seam Catch doesn't Catch
                lightguard

                Marek Nazarko wrote on Feb 10, 2011 09:57:


                Thank you for response. I didn't have Seam Faces (no mention in doc as it's requirements). I've tried to add it, but I probably need to wait for new versions, because there is mix of versions in repository. Some requires Seam Solder Beta 1, some 2. New versions require sometimes even Beta 4...


                You don't need it, but Catch on it's own doesn't have integration with anything, that's up to the other modules, hence the need for Servlet, Faces or Rest modules.  If you want to use Catch stand-alone you need to fire the events like I talked about in the last post.

                • 5. Re: Seam Catch doesn't Catch
                  marx3

                  It's rather silly you have so many exclusions, Sebastian...
                  In second example <seam.rest.version>3.0.0.Beta1</seam.rest.version> or similair is missing
                  Anyway it doesn't work for me - it compile, but throws errors during deploy.
                  I see repositories has new Seam version - I would try to make somthing from it.

                  • 6. Re: Seam Catch doesn't Catch
                    marx3

                    I've installed everything from bom file revision 9: Seam Servlet, Seam Faces, Seam Catch etc. Only Seam Faces are from snapshot. It seems to probably works, because I see 10:29:02,922 INFO  [org.jboss.seam.faces.exception.CatchExceptionHandlerFactory] Catch integration enabled
                    but sysouts from my handling class still doesn't appear

                    • 7. Re: Seam Catch doesn't Catch
                      lightguard

                      If you could post your war up or email it to me, you can find my email at http://community.jboss.org/people/LightGuard

                      • 8. Re: Seam Catch doesn't Catch
                        marx3

                        I can't find your email anywhere.
                        I've uploaded war, inside are sources.
                        http://www.4shared.com/file/A0Cd6bmx/catchtest.html

                        • 9. Re: Seam Catch doesn't Catch
                          lightguard

                          Marek Nazarko wrote on Feb 11, 2011 10:00:


                          I can't find your email anywhere.
                          I've uploaded war, inside are sources.
                          http://www.4shared.com/file/A0Cd6bmx/catchtest.html



                          Okay, all good.  Remove the inner class that contains your handler definitions. You can also add back the first handler. AFAIK this is not a catch limitation, but probably something in the CDI spec as the inner class was not being picked up as a bean.

                          • 10. Re: Seam Catch doesn't Catch
                            marx3

                            OMG, copy-paste power... :) I didn't realised it's inner class... Thank you!

                            • 11. Re: Seam Catch doesn't Catch

                              Hi all,
                              please can you provide a simple catch exmaple using a servlet without seams servlet?
                              from now i dont understand why should i explicitely fire catch event?.
                              Thank you for your great work
                              Emeric

                              • 12. Re: Seam Catch doesn't Catch
                                lightguard

                                Catch works via CDI events, without Seam Servlet nothing fires the event that Catch observes.


                                Seam Servlet uses a Servlet Filter to put each request into a try / catch block and fires the event in the catch block. Without the event being fired Seam Catch doesn't have any idea about the exception.