Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-5620

@Resource injection isn't done on static members

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 7.1.3.Final (EAP)
    • CDI / Weld
    • None

      There is a change in behaviour of:

      @Resource(mappedName = "java:/JmsXA")
      private static ConnectionFactory cf;
      

      In EAP6/AS7.1.2.Final this property is initialized but in EAP6.0.1.ER2/AS7.1.3.Final is not.

      This could also break backward compatibility. Is there a reason why this feature should not work?

      Used MDB:

      import java.util.concurrent.atomic.AtomicInteger;
      import javax.annotation.Resource;
      import javax.ejb.*;
      import javax.jms.*;
      import org.apache.log4j.Level;
      import org.apache.log4j.Logger;
      
      @MessageDriven(name = "mdb",
              activationConfig = {
                      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                      @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/InQueue")})
      @TransactionManagement(value = TransactionManagementType.CONTAINER)
      @TransactionAttribute(value = TransactionAttributeType.REQUIRED)
      public class LocalMdbFromQueue implements MessageDrivenBean, MessageListener {
      
          @Resource(mappedName = "java:/JmsXA")
          private static ConnectionFactory cf;
      
          @Resource(mappedName = "java:/jms/queue/OutQueue")
          private static Queue queue;
      
          public static AtomicInteger globalCounter = new AtomicInteger();
      
          private static final long serialVersionUID = 2770941392406343837L;
          private static final Logger log = Logger.getLogger(LocalMdbFromQueue.class.getName());
          private MessageDrivenContext context = null;
      
          public LocalMdbFromQueue() {
              super();
          }
      
          @Override
          public void setMessageDrivenContext(MessageDrivenContext ctx) {
              this.context = ctx;
          }
      
          public void ejbCreate() {
          }
      
          @Override
          public void ejbRemove() {
          }
      
          @Override
          public void onMessage(Message message) {
      
              Connection con = null;
              Session session;
      
              try {
                  long time = System.currentTimeMillis();
                  int counter = 0;
                  try {
                      counter = message.getIntProperty("count");
                  } catch (Exception e) {
                      log.log(Level.ERROR, e.getMessage(), e);
                  }
                  String messageInfo = message.getJMSMessageID() + ", count:" + counter;
                  log.log(Level.INFO, " Start of message: " + globalCounter.incrementAndGet() + ", message info:" + messageInfo);
      
                  con = cf.createConnection();
      
                  con.start();
      
                  session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
      
                  String text = message.getJMSMessageID() + " processed by: " + hashCode();
                  MessageProducer sender = session.createProducer(queue);
                  TextMessage newMessage = session.createTextMessage(text);
                  newMessage.setStringProperty("inMessageId", message.getJMSMessageID());
                  sender.send(newMessage);
      
                  log.log(Level.INFO, " End of " + messageInfo + " in " + (System.currentTimeMillis() - time) + " ms");
      
              } catch (Exception t) {
                  t.printStackTrace();
                  log.log(Level.FATAL, t.getMessage(), t);
      
              } finally {
      
                  if (con != null) {
                      try {
                          con.close();
                      } catch (JMSException e) {
                          log.log(Level.FATAL, e.getMessage(), e);
                      }
                  }
      
      
              }
          }
      }
      

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              mnovak1@redhat.com Miroslav Novak
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: