Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2105

Getting different instances of @RequestScoped bean during same remote EJB call

    Details

    • Steps to Reproduce:
      Hide

      The SLSB:

      @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);
         }
      }
      

      The ApplicationScoped "observer":

      @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()));
         }
      }
      

      The injected RequestScoped bean:

      @RequestScoped
      public class TransactionHandler {
      
          private UUID uuid = UUID.randomUUID();
      
          public UUID getUUID() {
              return uuid;
          }
      }
      

      Making a single remote EJB call gives two different instances:

      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
      

      In TomEE it is the same instance:

      @Observes progress() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7
      @Observes success() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7
      
      Show
      The SLSB: @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); } } The ApplicationScoped "observer": @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())); } } The injected RequestScoped bean: @RequestScoped public class TransactionHandler { private UUID uuid = UUID.randomUUID(); public UUID getUUID() { return uuid; } } Making a single remote EJB call gives two different instances: 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 In TomEE it is the same instance: @Observes progress() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7 @Observes success() d583b6f8-02fc-45f7-80ca-6b0023cf7ac7

      Description

      From a plain SLSB, I am firing a certain type of CDI event. In an ApplicationScoped bean, I am observing these type of events in different transaction phases such as TransactionPhase.IN_PROGRESS and TransactionPhase.AFTER_SUCCESS. A RequestScoped bean is injected into the bean implementing the observer methods.

      If I now make a remote EJB call to the SLSB, I am getting different instances of the RequestScoped bean during the same request (same thread, same transaction) at the different transaction phases.

      The WELD reference however says:

      The request and application scopes are also active:
      during invocations of EJB remote methods,
      [...]

      So I'd expect to get the same instance of a RequestScoped bean during this request at any transaction phase.

      I've posted a question to the forum: https://developer.jboss.org/thread/267637

      In TomEE this scenario behaves as expected.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                dode Torsten Römer
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: