12 Replies Latest reply on Sep 27, 2011 4:45 AM by superfis

    Errai RPC calls + Seam Catch module - how?

    superfis

      Hi,

      I'd like to have active Seam Catch module on server side (deployed on jboss as7) to handle exceptions, wrap them into custom exceptions and rethrow for being handled on client side (communication method: Errai RPC calls). Is it possible?

      I can do it when I use JSF sites but Errai RPC calls don't activate Catch module.

        • 1. Re: Errai RPC calls + Seam Catch module - how?
          csa

          We don't currently support integration with Seam Catch. You're more than welcome to write an extension if you want to give it a try.

          • 2. Re: Errai RPC calls + Seam Catch module - how?
            superfis

            Christian, thank you for your answer.

             

            I tried to give it a try (I mean CDI extension) but I'm completelly lost in Errai area. My approach was to find all CDI beans with annotation @org.jboss.errai.bus.server.annotations.Service and dynamically add interceptors to all methods which can be called from GWT by Errai RPC, and in the interceptor calling original methods in try-catch block and in case of throwed exceptions, wrap it and send further with:

             

            catchEvent.fire(new ExceptionToCatch(e));

             

            Unfortunatelly I noticed that service methodes called from Errai RPC are not called within managed context and neither interceptors nor other managed thing can be invoked.

            Could you give me some suggestion, if it's possible, how to approach this issue, please? I'm not a daily-developer of CDI extensions, so it is

            hard a bit for me to find a proper way

             

            I'll be thankful for any advise.

            • 3. Re: Errai RPC calls + Seam Catch module - how?
              lightguard

              I don't know anything about Errai, but if something needs to change in Catch I'm more than happy to add an hook or other mechanism to help make this easier.

              • 4. Re: Errai RPC calls + Seam Catch module - how?
                csa

                Slawomir, yes you're right. When Errai receives the message from the client, it invokes the enpoint method directly using Reflection. That's why your interceptor is not invoked.

                 

                I will take a look at this next week to see how to best make this work.

                 

                Jason, thanks for offering your help!

                • 5. Re: Errai RPC calls + Seam Catch module - how?
                  superfis

                  Christian,

                   

                  I'm looking forward to the messages in this topic.

                   

                  Thanks, Slawek

                  • 6. Re: Errai RPC calls + Seam Catch module - how?
                    csa

                    I took a look at this now. Errai CDI and Seam Catch integrate well already. So, nothing needs to be done or change in Catch.

                     

                    Slawek, if you use Errai CDI and fire the ExceptionToCatch event (from your e.g. @ApplicationScoped bean) all the corresponding Seam Catch Handlers will be executed.

                     

                    So, the question really is whether or not we can make this work with Errai RPC. I'll post an update soon.

                    • 7. Re: Errai RPC calls + Seam Catch module - how?
                      superfis

                      Yes, working with Errai CDI (communication by events) is quit comfortable, but the question is how to activate Seam Catch (and other CDI things) using Errai RPC calls.

                      • 8. Re: Errai RPC calls + Seam Catch module - how?
                        csa

                        Yes, this also works for Errai-RPC. Just add the @Service (org.jboss.errai.bus.server.annotations.Service) annotation to your @ApplicationScoped bean:

                         

                        {code:java}@Service

                        @ApplicationScoped

                        public class SimpleCDIService implements SimpleService {

                        ...

                        }{code}

                         

                        where SimpleService is your remote (org.jboss.errai.bus.server.annotations.Remote) interface.

                         

                        {code:java}@Remote

                        public interface SimpleService {

                        ...

                        }{code}

                         

                        You can then use Errai-RPC to invoke all methods of SimpleService. Further, you can fire CDI events from within these methods as they are implemented in the @ApplicationScoped SimpleCDIService. Your Seam Catch handlers will be activated.

                         

                        Given you started from our Erra-CDI archetype, you can use the jboss7 profile (mvn -Pjboss7 clean install) to build your app. I just successfully tested this on AS7. However, this currently does not work in dev mode (hosted mode) due to a classloading issue. We will look into that.

                        • 9. Re: Errai RPC calls + Seam Catch module - how?
                          superfis

                          Thank you Christian for your checking.

                          You are right that fireing events from inside of service methods do the work, but I'm interested in catching exceptions raised naturally (not as explicitly triggered by Seam Catch event)... e.g. AuthenticationException raised by @LoggedIn annotation added to called service method.

                          • 10. Re: Errai RPC calls + Seam Catch module - how?
                            csa

                            Update: we just published new snapshots that fix the hosted mode problem mentioned above.

                            • 11. Re: Errai RPC calls + Seam Catch module - how?
                              csa

                              Slawek, I see these as two independent issues:

                               

                              -) Integration with Seam Catch (which works now using Errai CDI / Errai RPC)

                              -) Interceptors for Errai RPC calls (which I agree would be handy)

                               

                              I have created a feature request for 2.0 to support RPC method interceptors: https://issues.jboss.org/browse/ERRAI-147

                               

                              For now, you will have to use an alternative approach to implement your crosscutting concern. You could look into AspectJ and apply compile-time weaving for instance.

                              • 12. Re: Errai RPC calls + Seam Catch module - how?
                                superfis

                                Hi Christian,

                                 

                                Thank you very much for your activities in the subject.

                                I'll handle exceptions forwarding to GWT in some way for now, and waiting for version 2.0 with interceptors