2 Replies Latest reply on Feb 8, 2016 5:09 AM by dode

    Getting different instances of @RequestScoped bean during remote EJB call

    dode

      On WildFly 10.0.0.Final, I have a simple SLSB firing a CDI event:

       

      @Stateless
      @Remote(CDITestRemote.class)
      @Local(CDITestLocal.class)
      public class CDITestBean implements CDITestRemote, CDITestLocal {

         @Inject
         private Event<IVolumeEvent> events;

         @Override
         public String insert(final String value) {
           final IVolumeEvent event = new VolumeEvent();
           events.fire(event);

           return String.format("value: %s", value);
         }
      }

       

      and an @ApplicationScoped "CDI event observer" for the type of events fired by the EJB:

       

      @ApplicationScoped
      public class VolumeEventObserver {

         private Logger logger = LoggerFactory.getLogger(VolumeEventObserver.class);

         @Inject
         private TransactionHandler txHandler;

         public void inProgress(
             @Observes(during = TransactionPhase.IN_PROGRESS) final IVolumeEvent event) {
           logger.info("@Observes progress() {}", String.valueOf(txHandler.getUUID()));
         }

         public void afterSuccess(
             @Observes(during = TransactionPhase.AFTER_SUCCESS) final IVolumeEvent event) {
           logger.info("@Observes success() {}", String.valueOf(txHandler.getUUID()));
         }

         public void afterFailure(
             @Observes(during = TransactionPhase.AFTER_FAILURE) final IVolumeEvent event) {
           logger.info("@Observes failure() {}", String.valueOf(txHandler.getUUID()));
         }
      }

       

      TransactionHandler is a @RequestScoped CDI bean:

       

      @RequestScoped

      public class TransactionHandler {

         

          private UUID uuid = UUID.randomUUID();

         

          public UUID getUUID() {

              return uuid;

          }

      }

       

      If I now make a remote EJB call to CDITestRemote, I get different instances of TransactionHandler during the same request (same thread, same transaction):

       

      18:09:54,372 INFO  [VolumeEventObserver] (default task-19) @Observes progress() 193aa274-8f5e-462a-89ca-9b827b4ed9ba

      18:09:54,388 INFO  [VolumeEventObserver] (default task-19) @Observes success() beb1a62b-ad74-4477-888a-880dd6db3ce1

       

      The WELD reference however states:

       

      The request and application scopes are also active:

       

      I tried the same in TomEE and there it works as expected:

       

      @Observes progress() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7

      @Observes success() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7

       

      Could this be a WELD bug?