6 Replies Latest reply on Mar 30, 2007 12:36 PM by Gavin King

    Seam in a J2EE Environment

    neilac333 Novice

      I am new to Seam and have read quite a bit of material on the topic. While I have been remarkably impressed with the brilliant work by Gavin and his team, I have yet to find a lot of of strong references that convey the power of Seam in a J2EE environment. I think this is a big deficiency since I believe many developers will not have the luxury of utilizing the features of Java EE 5 (most notably EJB 3) for quite some time.

      I would welcome any feedback on references that discuss Seam in the context of pure POJOs (and not just a small chapter at the back in an otherwise Java EE 5 dominated Seam book). In the meantime, I have some specific questions:

      1) Can I use AOP concepts to perform logging and exception handling? I know that I can inject a Logger in Seam, but I would like to keep my business logic code free from logging code. Is JBoss AOP an option here?

      2) How can I inject an EJB 2.x EJB into a Seam-managed component? I am thinking particularly about a web service SLSB that could be utilized by a Seam component. This seems tough to me given that the container would have to do a JNDI lookup, generate a local interface to the web service, and inject it.

      3) How can I decide which object implementation I inject into a component? For example, if I have an interface called MyObject and two implementations classes called MyObjectImpl and MyObjectMock, how can I designate which one I inject depending on whether I am testing or whether I am in production.

      Any help with any of these questions is very much appreciated. Thank you very much.

        • 1. Re: Seam in a J2EE Environment
          Gavin King Master

          1) Depends what you mean. We currently have no special integration of JBoss AOP into Seam (though it is something we will probably do at some point in the future). However, by nature, JBoss AOP can enhance *any* class, it does not need to be any special kind of component. OTOH, most things that you might think you need AOP for can be accomplished via a Seam interceptor, which is just a MUCH easier construct. Add a meta-annotation to an annotation, then use the annotation on your Seam components. For things like logging, this is more than what you need...

          2) Yes, but you would need to write some kind of factory or manager component for the EJB 2 bean (this is not hard, but nor is it as simple as it could be if Seam had built-in support for EJB3). We don't have anything built-in to Seam today. However, if this is some kind of blocking issue for you, let us know and we will implement it, it is already on the todo list, but no-one asked for it yet.

          3) Depends. If you have the same interface, with multiple roles, you disambiguate via the component name. If you are simply trying to mock stuff out for tests, you use @Install(precedence=MOCK), which is IMO waywaywayway easier to use and more elegant than the XML-based solutions found in other IoC solutions. This is very well-covered in the latest reference docs for 1.2.1.


          • 2. Re: Seam in a J2EE Environment
            neilac333 Novice

            Thanks, Gavin. If I may ask some follow-ups on those points:

            1) Aren't Seam interceptors only relevant to EJB 3? It is my understanding that interceptors aren't available to POJO's except through AOP constructs.

            2) I definitely anticipate needing support for EJB 2 integration in the future given that I will have to interact with a web service layer, but the need for me isn't immediate. Certainly in the next few months though.

            3) I was looking at legacy docs, so I was unaware of the new precedence value called MOCK. Thanks for pointing that out.

            I must say that the only thing that rivals the creative effort behind Seam is your own personal attention to the needs of the Seam community. Kudos once again to you and your team.

            Thanks again.

            • 3. Re: Seam in a J2EE Environment
              Christian Bauer Master

              The reference documentation describes how Seam interceptors can be applied to regular JavaBean components, with the same semantics/annotations as in EJB 3.0.

              • 4. Re: Seam in a J2EE Environment
                Gavin King Master

                What exactly do you envisage needing in terms of the EJB2 integration?

                Remember, if the client is an EJB3 Seam component, you can easily inject an EJB2 bean using @EJB and call its methods. Beyond that, what are your requirements?

                Cheers.

                • 5. Re: Seam in a J2EE Environment
                  neilac333 Novice

                  Christian, I will check out the reference documentation to learn more about the application of Seam interceptors to regular JavaBean components.

                  Gavin, my client here has an enterprise authentication web service that I am hoping to leverage to facilitate authentication into the application I am building. I envisage using a Seam-managed POJO calling on an EJB 2.1 SLSB to make the authentication call. (This will all be deployed to WebLogic 9.2 incidentally.) It may very well be that the @EJB injection is sufficient. I will certainly take a look at that. Any further insight is appreciated.

                  Thanks.

                  • 6. Re: Seam in a J2EE Environment
                    Gavin King Master

                    Hum, no, sillyme, @EJB only works in EE5, of course, I got confused because of days between posts :-)

                    You can, however, use a normal JNDI lookup. If its only one or two spots in your code that you need this, just go down that route, you won't need anything else. OTOH, if you are calling *hundreds* or EJB2 beans, let me know.