glassfish
  1. glassfish
  2. GLASSFISH-18406

@EJB injection fails but JNDI lookup works in web service class in Glassfish

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1.2_b23
    • Fix Version/s: 4.1.1
    • Component/s: web_services
    • Labels:
      None
    • Environment:

      Glassfish 3.1.2 beta built 2012-02-14, Windows 7 pro 64-bit, JDK 1.6

      Description

      I have a @WebService class that injects an @EJB. The EJB is packaged in a .jar file which is in the same .war file as the web service classes. The @EJB injection always fails, but I can do a JNDI lookup on the EJB. I've tried making the EJB and its interface @Remote, but that didn't matter. Injection still fails and JNDI lookup still works.

      I'm using a version 3.0 web.xml. There's no ejb deployment descriptor in the ejb.jar file, but that is not suppose to matter in EJB 3.1.

      EJB class and interface packaged in a .jar in the .war file:

      //@Remote
      public interface ReportServiceI {

      public String testAlive();
      }

      @Stateless
      //@Remote (ReportServiceI.class)
      public class ReportService implements ReportServiceI

      {...}

      Web Service class:

      @WebService(
      targetNamespace = "http://www.reps.corp.com/services/reports/ReportService",
      portName="ReportPort",
      serviceName="ReportService",
      endpointInterface="com.corp.reps.reports.ws.server.ReportServiceWSI")

      public class ReportServiceWS implements ReportServiceWSI {

      public static Logger logger = Logger.getLogger(ReportServiceWS.class);

      // These all fail
      // @EJB
      // @EJB(beanInterface=ReportServiceI.class)
      // @EJB(lookup="java:global/repsreports/ReportService")
      ReportServiceI reportService;

      public String testAlive() {

      // this works
      try

      { InitialContext context = new InitialContext(); reportService = (ReportServiceI)context.lookup("java:global/repsreports/ReportService"); }

      catch (NamingException ex)

      { logger.error(ex); return "InitialContext.lookup() failed."; }

      ...

      }

        Issue Links

          Activity

          Hide
          Cheng Fang added a comment -

          If you make ReportServiceWS into EJB by adding @Stateless, does the injection work?

          Show
          Cheng Fang added a comment - If you make ReportServiceWS into EJB by adding @Stateless, does the injection work?
          Hide
          dwschulze added a comment -

          Putting @Stateless on ReportServiceWS doesn't make any difference. All 3 forms of @EJB injection fail and the JNDI lookup succeeds.

          I also want to avoid making ReportServiceWS a SessionBean for security reasons. The @WebService will be the only publicly visible interface into the system and I'm going to put WS-Security on those.

          Show
          dwschulze added a comment - Putting @Stateless on ReportServiceWS doesn't make any difference. All 3 forms of @EJB injection fail and the JNDI lookup succeeds. I also want to avoid making ReportServiceWS a SessionBean for security reasons. The @WebService will be the only publicly visible interface into the system and I'm going to put WS-Security on those.
          Hide
          Cheng Fang added a comment -

          Thanks for trying it. Can you attach a test app?

          Show
          Cheng Fang added a comment - Thanks for trying it. Can you attach a test app?
          Hide
          dwschulze added a comment -

          I'll have to rename things (scrub proprietary names etc.).

          Show
          dwschulze added a comment - I'll have to rename things (scrub proprietary names etc.).
          Hide
          dwschulze added a comment -

          With Glassfish 3.1 or 3.1.2 running type mvn install in the top level reports project.

          There is a Swing client in the reports.gui project. The main class is ReportsGUI. Run this GUI. Click on the second tab "Message Success Rate". Press the "Test Connectivity" button to verify that @EJB injection works.

          The server side code is currently doing JNDI lookup which works. Comment out the init() method and uncomment one of the @EJB annotations to observe failure.

          Show
          dwschulze added a comment - With Glassfish 3.1 or 3.1.2 running type mvn install in the top level reports project. There is a Swing client in the reports.gui project. The main class is ReportsGUI. Run this GUI. Click on the second tab "Message Success Rate". Press the "Test Connectivity" button to verify that @EJB injection works. The server side code is currently doing JNDI lookup which works. Comment out the init() method and uncomment one of the @EJB annotations to observe failure.
          Hide
          Cheng Fang added a comment -

          I was able to reproduce the issue.

          Note: need to use mvn 3.x to run the sample (mvn 2.2.1 failed). I also added some debug statement in @PostConstruct and @EJB setter method that can be displayed in server.log right after 'mvn install', without having to run the gui.

          From my testing, @EJB injection into WebService class is not happening. That may explain why there is no injection-related errors or warnings.

          Could be related to the two very old issues GLASSFISH-2190 and GLASSFISH-2105.

          Show
          Cheng Fang added a comment - I was able to reproduce the issue. Note: need to use mvn 3.x to run the sample (mvn 2.2.1 failed). I also added some debug statement in @PostConstruct and @EJB setter method that can be displayed in server.log right after 'mvn install', without having to run the gui. From my testing, @EJB injection into WebService class is not happening. That may explain why there is no injection-related errors or warnings. Could be related to the two very old issues GLASSFISH-2190 and GLASSFISH-2105 .
          Hide
          Cheng Fang added a comment -

          assign to web services team to evaluate potential regression.

          Show
          Cheng Fang added a comment - assign to web services team to evaluate potential regression.
          Hide
          Bhakti Mehta added a comment -

          Assigning to Lukas from the webservices team

          Show
          Bhakti Mehta added a comment - Assigning to Lukas from the webservices team
          Hide
          Lukas Jungmann added a comment -

          EJB injection in non-jsr109 deployment, which your app is using (it includes sun-jaxws.xml), is undefined, AFAIK => switching to enhancement

          to "get around" this or better - implement your ws correctly - remove "proprietary" sun-jaxws.xml from your webapp as well as all relevant elements from web.xml (listener-class, servlet-class etc), they're not needed if you're deploying your app on glassfish

          Show
          Lukas Jungmann added a comment - EJB injection in non-jsr109 deployment, which your app is using (it includes sun-jaxws.xml), is undefined, AFAIK => switching to enhancement to "get around" this or better - implement your ws correctly - remove "proprietary" sun-jaxws.xml from your webapp as well as all relevant elements from web.xml (listener-class, servlet-class etc), they're not needed if you're deploying your app on glassfish

            People

            • Assignee:
              Lukas Jungmann
              Reporter:
              dwschulze
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: