Topic
  • 6 replies
  • Latest Post - ‏2013-08-26T07:59:22Z by mgn2009
mgn2009
mgn2009
15 Posts

Pinned topic CDI differences between Liberty and Full WAS

‏2013-08-22T15:19:29Z |

Tried to deploy the Registration Application described in the Lab: "Lab: Accelerate Your Web App Development!" on full WAS profile 8.5.5.0 

Link to the Lab: https://www.ibmdw.net/wasdev/docs/lab-accelerate-your-web-app-development/

It turned out that CDI doesn't work. To solve the issue I had to change the @Inject annotations to @EJB annotations in all Servlets. Why CDI doesn't work in the same way for both profiles (Liberty and Full)? It was supposed to be principal rule that any application developed on Liberty profile can run in Full profile without any changes in the code. 

  • bergmark
    bergmark
    42 Posts
    ACCEPTED ANSWER

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-23T14:35:40Z  
    • mgn2009
    • ‏2013-08-23T12:21:00Z

    Yes, 

    1. I completed the lab and it worked fine on Liberty Profile.

    2. Then I deployed the same application on Full Profile where it turned out that CDI didn't work:

    - the application contained two Servlets where  the @Inject annotations were used. The issue was that EJBs weren't injected to Servlets and I simply got java.lang.NullPointerException in places where EJB's method was called.

    ...

    @Inject 

    RegistrationBean rb;

    rb.register(name, email); // àNullPointerException

    - I tried to investigate the issue with the InfoCenter section: "Troubleshooting contexts and dependency injection". I could see some CDI traces with relevant EJB:

    [8/22/13 15:54:01:406 CEST] 0000007e WASEJBMDOrche >  createManagedObjectFactory: com.ibm.ws.metadata.ejb.WASEJBMDOrchestrator$JCDIManagedObjectFactoryImpl@796437da[class com.ibm.websphere.sample.registration.ejb.RegistrationBean] Entry

    [8/22/13 15:54:01:511 CEST] 0000007e JCDIComponent 3   storeCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    [8/22/13 15:59:32:066 CEST] 00000056 WASJCDIHelper 3   releaseCreationalContext : com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2

    [8/22/13 15:59:32:066 CEST] 00000056 JCDIComponent 3   releaseCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    However EJB was not injected with the @Inject annotation to the Servlet.

    3. In the end I changed all @Inject annotations to the @EJB annotations in my Servlets. Then the application started working correctly.

    Please find attached the EAR file (Java source files are inside).  To install the application on Full Profile, the Derby data source (jndi="jdbc/DerbyDataSource") needs to be created.

    According to the InfoCenter section: "Troubleshooting contexts and dependency injection" both annotations should work. However the @Inject annotation doesn't work on Full Profile.

    I tested the attached ear one of my Full Profile systems, and it appears to have worked without switching out the @Inject for @Ejb inside of the AddAttendee Servlet.

    Is there any chance that you might have clicked the metadata complete flag for the web.xml when you deployed the application on Full Profile?

    The only other thing I can think to try is to ensure I am trying the application on the exact same level of Full Profile as you.  Your full profile system was 8.5.5.0?

  • bergmark
    bergmark
    42 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-22T16:22:31Z  

    CDI should behave the same way on both profiles, and we certainly support CDI injection into Servlets in both Full Profile and Liberty Profile.

    Could you provide a little more information about what you tried.  You completed the lab and had a working application on Liberty Profile, but that same application didn't work on Full Profile?  Were there any errors in the log on Full Profile?

  • mgn2009
    mgn2009
    15 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-23T12:21:00Z  

    Yes, 

    1. I completed the lab and it worked fine on Liberty Profile.

    2. Then I deployed the same application on Full Profile where it turned out that CDI didn't work:

    - the application contained two Servlets where  the @Inject annotations were used. The issue was that EJBs weren't injected to Servlets and I simply got java.lang.NullPointerException in places where EJB's method was called.

    ...

    @Inject 

    RegistrationBean rb;

    rb.register(name, email); // àNullPointerException

    - I tried to investigate the issue with the InfoCenter section: "Troubleshooting contexts and dependency injection". I could see some CDI traces with relevant EJB:

    [8/22/13 15:54:01:406 CEST] 0000007e WASEJBMDOrche >  createManagedObjectFactory: com.ibm.ws.metadata.ejb.WASEJBMDOrchestrator$JCDIManagedObjectFactoryImpl@796437da[class com.ibm.websphere.sample.registration.ejb.RegistrationBean] Entry

    [8/22/13 15:54:01:511 CEST] 0000007e JCDIComponent 3   storeCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    [8/22/13 15:59:32:066 CEST] 00000056 WASJCDIHelper 3   releaseCreationalContext : com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2

    [8/22/13 15:59:32:066 CEST] 00000056 JCDIComponent 3   releaseCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    However EJB was not injected with the @Inject annotation to the Servlet.

    3. In the end I changed all @Inject annotations to the @EJB annotations in my Servlets. Then the application started working correctly.

    Please find attached the EAR file (Java source files are inside).  To install the application on Full Profile, the Derby data source (jndi="jdbc/DerbyDataSource") needs to be created.

    According to the InfoCenter section: "Troubleshooting contexts and dependency injection" both annotations should work. However the @Inject annotation doesn't work on Full Profile.

    Attachments

  • bergmark
    bergmark
    42 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-23T14:35:40Z  
    • mgn2009
    • ‏2013-08-23T12:21:00Z

    Yes, 

    1. I completed the lab and it worked fine on Liberty Profile.

    2. Then I deployed the same application on Full Profile where it turned out that CDI didn't work:

    - the application contained two Servlets where  the @Inject annotations were used. The issue was that EJBs weren't injected to Servlets and I simply got java.lang.NullPointerException in places where EJB's method was called.

    ...

    @Inject 

    RegistrationBean rb;

    rb.register(name, email); // àNullPointerException

    - I tried to investigate the issue with the InfoCenter section: "Troubleshooting contexts and dependency injection". I could see some CDI traces with relevant EJB:

    [8/22/13 15:54:01:406 CEST] 0000007e WASEJBMDOrche >  createManagedObjectFactory: com.ibm.ws.metadata.ejb.WASEJBMDOrchestrator$JCDIManagedObjectFactoryImpl@796437da[class com.ibm.websphere.sample.registration.ejb.RegistrationBean] Entry

    [8/22/13 15:54:01:511 CEST] 0000007e JCDIComponent 3   storeCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    [8/22/13 15:59:32:066 CEST] 00000056 WASJCDIHelper 3   releaseCreationalContext : com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2

    [8/22/13 15:59:32:066 CEST] 00000056 JCDIComponent 3   releaseCreationalContext {com.ibm.websphere.sample.registration.ejb.RegistrationBean@346c13a2 --> org.apache.webbeans.context.creational.CreationalContextImpl@dcb8741e}

    However EJB was not injected with the @Inject annotation to the Servlet.

    3. In the end I changed all @Inject annotations to the @EJB annotations in my Servlets. Then the application started working correctly.

    Please find attached the EAR file (Java source files are inside).  To install the application on Full Profile, the Derby data source (jndi="jdbc/DerbyDataSource") needs to be created.

    According to the InfoCenter section: "Troubleshooting contexts and dependency injection" both annotations should work. However the @Inject annotation doesn't work on Full Profile.

    I tested the attached ear one of my Full Profile systems, and it appears to have worked without switching out the @Inject for @Ejb inside of the AddAttendee Servlet.

    Is there any chance that you might have clicked the metadata complete flag for the web.xml when you deployed the application on Full Profile?

    The only other thing I can think to try is to ensure I am trying the application on the exact same level of Full Profile as you.  Your full profile system was 8.5.5.0?

  • mgn2009
    mgn2009
    15 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-23T15:57:19Z  
    • bergmark
    • ‏2013-08-23T14:35:40Z

    I tested the attached ear one of my Full Profile systems, and it appears to have worked without switching out the @Inject for @Ejb inside of the AddAttendee Servlet.

    Is there any chance that you might have clicked the metadata complete flag for the web.xml when you deployed the application on Full Profile?

    The only other thing I can think to try is to ensure I am trying the application on the exact same level of Full Profile as you.  Your full profile system was 8.5.5.0?

    Thank you for your post. I uninstalled the application completely and then installed again but this time from the Admin Console. After this the application worked fine. It seems that that issue appears only after installing from WebSphere Application Server Developer Tools for Eclipse.

    It was my environment:

    ************ Start Display Current Environment ************
    WebSphere [IBMJAVA7 7.0.4.1 gm1318.03]Platform 8.5.5.0 [ND 8.5.5.0 gm1319.01][WXS 8.6.0.2 cf21323.07120159] Host Operating System is Windows 7, version 6.1
    Java version = 1.7.0, Java Compiler = j9jit26, Java VM name = IBM J9 VM

    ...

    WDT V9

  • e_yuen
    e_yuen
    27 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-23T20:07:26Z  
    • mgn2009
    • ‏2013-08-23T15:57:19Z

    Thank you for your post. I uninstalled the application completely and then installed again but this time from the Admin Console. After this the application worked fine. It seems that that issue appears only after installing from WebSphere Application Server Developer Tools for Eclipse.

    It was my environment:

    ************ Start Display Current Environment ************
    WebSphere [IBMJAVA7 7.0.4.1 gm1318.03]Platform 8.5.5.0 [ND 8.5.5.0 gm1319.01][WXS 8.6.0.2 cf21323.07120159] Host Operating System is Windows 7, version 6.1
    Java version = 1.7.0, Java Compiler = j9jit26, Java VM name = IBM J9 VM

    ...

    WDT V9

    It looks like you are using ND version of the server.   Are you using an unmanaged ND server or a managed node?  The WebSphere Application Server Developer Tools for Eclipse only works with an unmanaged ND server.  If you happens to be using a managed ND node, please try again with an unmanged node.  

    In case you are still having problem when using an unmanaged ND server, you can try changing the publishing mode to use "Run server with resources on Server" to see if that makes a difference?  To change it, you can open the server editor by double click the server on the Servers view, then you can find the settings under the "Publishing settings for WebSphere Application Server".  If the application has already been added to the server before changing the settings, make sure you remove the application from the server, do a publish and add it back.

    Elson

     

  • mgn2009
    mgn2009
    15 Posts

    Re: CDI differences between Liberty and Full WAS

    ‏2013-08-26T07:59:22Z  
    • e_yuen
    • ‏2013-08-23T20:07:26Z

    It looks like you are using ND version of the server.   Are you using an unmanaged ND server or a managed node?  The WebSphere Application Server Developer Tools for Eclipse only works with an unmanaged ND server.  If you happens to be using a managed ND node, please try again with an unmanged node.  

    In case you are still having problem when using an unmanaged ND server, you can try changing the publishing mode to use "Run server with resources on Server" to see if that makes a difference?  To change it, you can open the server editor by double click the server on the Servers view, then you can find the settings under the "Publishing settings for WebSphere Application Server".  If the application has already been added to the server before changing the settings, make sure you remove the application from the server, do a publish and add it back.

    Elson

     

    My installation is ND. However, for development I use the standalone Application Server profile with development performance tuning settings. In addition, my publishing settings were set to the "Run server with resources on Server" option.