5 Replies Latest reply on Feb 8, 2013 10:41 AM by David Ward

    EJBs as Switchyard Service

    Travis De Silva Newbie



      I don't know if this is a stupid question but does switchyard recognize EJB3 services as SwitchYard services. In fact I was wondering why didn't the Switchyard project use EJB as their services without going with another switchyard propritory service. Is it because EJB's are not SCA complient?


      JBoss was one of the key players who got EJB to what it is today (EJB3/3.1 is awarsome) They are the ones that took the lead with EJB3, JPA, CDI and all the key JEE6 stuff.


      We are building a system where the core business services are in EJB. I currently expose it as REST services by annotating it with JAX-RS annotations.


      Ideally I would like to keep the EJB's pure without JAX-RS annotations but have a separate interface that is annotated with JAX-RS annotations and then bind the EJB to the REST interface. (similar concept to rest-bindings in the switchyard quickstart examples)


      In fact I could do the same and have a JAX-WS soap interface and expose the same EJB as SOAP web services.


      Any thoughts? How best can I expose my EJB's as REST and SOAP services at the same time? Should I look at using camel sevices or is there a switchyard way of doing it?




        • 1. Re: EJBs as Switchyard Service
          Keith Babo Master

          We implement a CDI extension which allows any bean with @Service to be registered as a service.  We also allow invocation of services from a bean using @Inject @Reference.  This should play nicely with EJBs.  Here's an example of a CDI-based service that uses injection:



          • 2. Re: EJBs as Switchyard Service
            Travis De Silva Newbie

            Yes I did see that example. But I am trying to get my head around why I need my bean to be stateless EJB's when I can do everything by keeping it as plain POJO's with a SwitchYard @Service annotation. Anyone can suggest what advanages I get by mixing EJB's and Switchyard services?


            Is it all that container managed stuff like JTA transastion management etc that EJB provide which in the case of Switchyard you have to do it explcitly?

            • 3. Re: EJBs as Switchyard Service
              Keith Babo Master

              This is just my opinion, but I think the line has blurred quite a bit between POJOs and EJBs in Java EE 6, particularly with the introduction of CDI.  I'm not saying this as a bad thing, I think it's merely a reflection of how much easier it's become to implement and deploy EJBs and how powerful CDI is in EE 6.  I would say that if you are starting a brand new application in SwitchYard, then look at using just CDI and see if it meets your needs.  If you are in a heterogeneous environment where you are using EJBs a lot and that's a better fit for your team, then go with that.

              1 of 1 people found this helpful
              • 4. Re: EJBs as Switchyard Service
                Travis De Silva Newbie

                Thanks Keith for your thoughts. Yes I agree. JEE6 is great but you get this EJB3/CDI confusion all the time. As you said we got to decide what is best and the reason that I think EJB3 is useful is because of some application container managed features that CDI might not have. But point taken. If we don't need those features, then we might as well just stick to CDI.

                • 5. Re: EJBs as Switchyard Service
                  David Ward Master

                  Agreed on all points, however think about what container-mananged features you might want.  Tranactions? We have that too. Security? Yup.