Esempio n. 1
0
  /**
   * Verifies the MessageDrivenContext methods.
   *
   * @param msg message
   */
  public void onMessage(final Message msg) {
    String op = null;

    try {
      op = msg.getStringProperty(MessageProperty.OPERATION.toString());
    } catch (JMSException e) {
      logger.debug("Error getting operation type: {0}", e);
    }

    if (ctx == null) {
      logger.debug("The SessionContext reference is null.");
    } else if (isEqual(GET_CALLER_PRINCIPAL, op)) {

      // TODO: test case

    } else if (isEqual(GET_ROLLBACK_ONLY, op)) {
      try {
        ctx.getRollbackOnly();
      } catch (IllegalStateException e) {
        log(
            MDBBeanManagedContext.class,
            ON_MESSAGE,
            MDBBeanManagedContext.class,
            GET_ROLLBACK_ONLY);
      } catch (Exception e) {
        logger.debug("Unexpected error.", e);
      }

    } else if (isEqual(SET_ROLLBACK_ONLY, op)) {
      try {
        ctx.setRollbackOnly();
      } catch (IllegalStateException e) {
        log(
            MDBBeanManagedContext.class,
            ON_MESSAGE,
            MDBBeanManagedContext.class,
            SET_ROLLBACK_ONLY);
      }

    } else if (isEqual(TIMER, op)) {
      try {
        checkInstance(ctx.getTimerService());
        log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, TIMER);
      } catch (Exception e) {
        logger.debug("Unexpected error.", e);
      }

    } else if (isEqual(USER_TRANSACTION, op)) {
      try {
        checkInstance(ctx.getTimerService());
        log(MDBBeanManagedContext.class, ON_MESSAGE, MDBBeanManagedContext.class, USER_TRANSACTION);
      } catch (Exception e) {
        logger.debug("Unexpected error.", e);
      }
    }
  }
  /**
   * Verifies if the operations allowed for Message Driven listener methods are working properly.
   *
   * @param message msg
   */
  public void onMessage(final Message message) {
    String op = null;

    try {
      op = message.getStringProperty(MessageProperty.OPERATION.toString());
    } catch (JMSException e) {
      logger.debug("Error getting operation type: {0}", e);
    }

    if (isEqual(RESOURCE_MANAGER, op)) {
      DataSource ds = (DataSource) ctx.lookup("jdbc/ds01");
      checkResource(ds);
      log(
          MDBListenerMethodAccess.class,
          ON_MESSAGE,
          MDBListenerMethodAccess.class,
          RESOURCE_MANAGER);

    } else if (isEqual(ENTERPRISE_BEAN, op)) {
      ItfOneMethod01 bean = (ItfOneMethod01) ctx.lookup("ejb/bean01");
      bean.getBool();
      log(
          MDBListenerMethodAccess.class,
          ON_MESSAGE,
          MDBListenerMethodAccess.class,
          ENTERPRISE_BEAN);

    } else if (isEqual(ENTITY_MANAGER_FACTORY, op)) {
      EntityManagerFactory emf = (EntityManagerFactory) ctx.lookup("persistence/pu01");
      try {
        EMFactoryTester.checkInstance(emf, "tmpTable" + this.hashCode());
        log(
            MDBListenerMethodAccess.class,
            ON_MESSAGE,
            MDBListenerMethodAccess.class,
            ENTITY_MANAGER_FACTORY);
      } catch (Exception e) {
        logger.debug("Error in EntityManagerFactory use: {0}", e);
        e.printStackTrace();
      }

    } else if (isEqual(ENTITY_MANAGER, op)) {
      EntityManager em = (EntityManager) ctx.lookup("persistence/pctx01");
      try {
        EntityManagerTester.checkInstance(em, "tmpTable" + this.hashCode());
        log(
            MDBListenerMethodAccess.class,
            ON_MESSAGE,
            MDBListenerMethodAccess.class,
            ENTITY_MANAGER);
      } catch (Exception e) {
        logger.debug("Error in EntityManagerFactory use: {0}", e);
        e.printStackTrace();
      }

    } else if (isEqual(TIMER, op)) {
      timer.hashCode();
      log(MDBListenerMethodAccess.class, ON_MESSAGE, MDBListenerMethodAccess.class, TIMER);

    } else if (isEqual(USER_TRANSACTION, op)) {
      if (utx == null) {
        log(
            MDBListenerMethodAccess.class,
            ON_MESSAGE,
            MDBListenerMethodAccess.class,
            USER_TRANSACTION);
      }
    }
  }