12 Replies Latest reply: Apr 21, 2012 2:49 PM by cybian RSS

    Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null

    cybian
      There have been many posts about using Jersey with Weblogic and EJB Injection, but most are a year old or so. I've seen many solutions, but nothing seems to work and now I going in circles. The problem might be as easy that 10.3.5 does not support EJB 3.1, which I heard 12c does. I created a very simple Jersey Resource that needs to inject two EJBs that do some data commitment. The two EJBs are using Annotations with Stateless. Pretty simple and the Weblogic console seems them as EJBs. Here is a quick snipped of the EJBs that are in a EJB jar (Typing by hand and not cutting and pasting(ignore spelling):

      UserSessionBean.java
      @Stateless
      public class UserSessionBean implements UserSession {

      @PersistenceContext
      private EntityManager em;

      [...]
      }

      FnodSessoniBean.java
      @Stateless
      public class FnodSessioBean implements FnodSession {

      @PersistenceContext
      private EntityManager em;
      [...]
      }

      Pretty simple EJBs using Annotations and the Weblogic server picks them up as EJBs.

      Now my Jersey Resource class. I'm trying to Inject the two EJBs into the Resource. I've read tons of post about how to do this. From simple Annotations, to modifying the web.xml to creating a class to load the Context. Nothing has worked and after this weekend I am going in circles. Here is a snipped of the FnodResource Jersey class.

      FnodResource.class
      @Path("/fnodcase")
      @Stateless
      public class FnodResource (

      @EJB
      private UserSession userSession;
      @EJB
      private FnodSession fnodSession

      [...]
      }

      Now I've read about problems with servlets having problems with wiring EJBs. This can be true since the @Stateless annotation about the FnodResource does not register with Weblogic. Basically the end result is when I try to hit the method in one of the EJB sessions, it returns null always. What is the proper way of trying to inject EJBs into Jersey, which seem to not get implemented in Weblogic?
        • 1. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
          gimbal2
          The problem might be as easy that 10.3.5 does not support EJB 3.1, which I heard 12c does.
          Ding ding ding. Injections only work in server managed resources; JAX-RS was added to the JEE 6 spec (weblogic 12).
          • 2. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
            cybian
            Has there been a common workaround solution for this?
            • 3. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
              gimbal2
              The classic - in stead of using injections, use JNDI lookups.
              • 4. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                cybian
                I thought about trying the JDNI route, but decided on installing 12c. WLS now sees the Resource as a EJB, but still the other injected EJBs are still NPEs when using the method in the resource.
                • 5. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                  gimbal2
                  That is very odd. You don't have anything legacy descriptor files floating around right? What if you strip off the JAX-RS stuff and just try to use it as an EJB - do the injections then work?
                  • 6. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                    cybian
                    I don't have any legacy descriptor files.It's definitely something with the project build since WLS sees all the beans I(including the Jersey Resource class, but the context does not seem to be right since the injected EJBs always throw a NPE. Which usually means it's not wired up correctly and the EJBs are not in the context of the EAR application. I was told to hold off on troubleshoot and finish another piece of the project. I will definitely be revisiting this issue in around two days.
                    • 7. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                      cybian
                      While we are awaiting approval for going to 12c, I finally was able to do the old jdni context lookup. It took a few researches, but finally I found another forum post where someone from oracle mentioned that you cannot do jdni lookup on local beans even if they are in the same ear. You have to make them remote. Plus he gave the exact string that is used for looking up the EJB, which the Internet gives tons of different examples on what the string should be. In the end I am able to use them in the Jersey resource.
                      • 8. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                        cybian
                        After getting everything to work, I am told to refactor everything to SOAP because they do not want to do JDNI lookup. Correct me if I am wrong, but everything I read, I will still have to do JDNI lookup in WebServices with EJBs in other jars in the ear. I really do not want to refactor everything to a SOAP interface only to prove that you have to use JDNI lookup in your WebServices to inject you Local Stateless EJBs from another jar in the ear. Is this correct? Also I have been trying to find concrete documentation from Oracle that explains the problem with injecting EJBs from another jar in a type of web service in the same ear. We also use JSF 2.0 with Managed Beans injecting other EJBs. I came across why that works and it's because WebLogic's JSF 2.0 implementation actually has a class that is specifically designed to inject EJBs into the ManagedBean.

                        If I am off base and you can inject EJBs into a SOAP web service then I would be most appreciative to see a link. But most importantly if I can't, I would like to find documentations and/or links that explain why you can't inject EJBs into web services and you need to make your EJBs Remote even if they are in the same ear and you have use JDNI lookup.
                        • 9. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                          cybian
                          The reason I am making this unanswered is to find documentation or links from Oracle on why you have to use JDNI lookup. Not having Jersey in the explanation would be ideal.
                          • 10. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                            gimbal2
                            Let me be blunt; All of that seems like complete nonsense to me.

                            - you can lookup local beans, especially if they are in the same ear. You just need the proper JNDI name, which is server specific before JEE6.
                            - injecting resources into JSF managed beans, including EJBs, is part of the JEE5 spec; its not server specific in any way.
                            - you can inject JAX-WS webservice resources using the specific @WebServiceRef annotation; this also works in JEE5
                            • 11. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                              cybian
                              You can be blunt, since it is complete nonsense. I wrote a quick WebService and the Local EJBs from the other jar injected fine. So it looks like I will be refactoring my Client & WebService away from Jersey. I haven't had to use SOAP in years, but the refactoring seems easy enough.
                              • 12. Re: Weblogic 10.3.5, Jersey 1.12 and EJB Injection - EJB's are alway null
                                cybian
                                Then here is a quick question. I tried to keep it REST using JAX-WS WebSericeProvider. The task was supposed to be pretty simple. It needed to be stateless, the payload was driven off of a XML schema, which provided excellent validation. But I ran into the same problem with injecting EJBs from another jar into the WS. I searched Google and the only information that kept coming up was with GlassFish's JIRA ticketing system where the same problem came up back in 2008. They considered it a bug and fixed it.

                                The only other information that came up is [Web Services for Java EE, Version 1.3 Doc|http://download.oracle.com/otn-pub/jcp/websvcs-1.3-mrel2-evaluate-oth-JSpec/websvcs-1_3-final-spec.pdf?AuthParam=1334961490_d5d73f42ccdff2d151135a24668abb08] and on page 41 focuses on WebServiceProviders as service implementation beans. Maybe there is something wrong with my implementation of the WebServiceProvider, but again it seemed to be pretty straight forward. I'm not sure if I should keep wasting time to see if the provider will work or refactor it yet again using WebService and SOAP, which I think the SOAP payload is a little overkill for what I am trying to accomplish.