public static boolean isRetryableException(Throwable th) {
   if (th == null) {
     Log.debug(Log.FRAMEWORK, "isRetryableException Unknown exception !");
     return false;
   } else if (th instanceof JMSException) {
     Log.debug(Log.FRAMEWORK, "isRetryableException JMSException detected.");
     return true;
   } else if (th instanceof NameNotFoundException) {
     Log.debug(Log.FRAMEWORK, "isRetryableException:  NameNotFoundException catched");
     return true;
   } else if (th instanceof NestingException) {
     NestingException nex = (NestingException) th;
     Class nextedExceptionClass = nex.getNestedExceptionClass();
     if (NameNotFoundException.class
         .getSimpleName()
         .equals(nextedExceptionClass.getSimpleName())) {
       Log.debug(
           Log.FRAMEWORK,
           "isRetryableException: GT nestedException: NameNotFoundException catched");
       return true;
     } else if (JMSException.class.getSimpleName().equals(nextedExceptionClass.getSimpleName())) {
       Log.debug(Log.FRAMEWORK, "isRetryableException: GT nestedException: JMSException catched");
       return true;
     } else {
       return false;
     }
   } else {
     Throwable ex = th.getCause();
     return isRetryableException(ex);
   }
 }
  protected void setUp() throws Exception {
    Log.log("TEST", "[" + getClassName() + ".setUp] Enter ");
    // do all your test environment initialisation here ....

    /** @todo initialise test data from test input file */
    PartnerTestHelper helper = (PartnerTestHelper) getEntityTestHelper();

    // prepare dependent embedded entity
    PartnerType partnerType = new PartnerType();
    partnerType.setName(PARTNER_TYPE);
    partnerType.setDescription(PARTNER_TYPE_DESCR);
    partnerType = helper.createPartnerType(partnerType);

    PartnerGroup partnerGroup = new PartnerGroup();
    partnerGroup.setName(PARTNER_GROUP);
    partnerGroup.setDescription(PARTNER_GROUP_DESCR);
    partnerGroup.setPartnerType(partnerType);
    partnerGroup = helper.createPartnerGroup(partnerGroup);

    // initialise default test data in test data set
    Partner entity = null;
    entity = new Partner();
    entity.setPartnerID(PARTNER_ID);
    entity.setName(NAME);
    entity.setDescription(DESCRIPTION);
    entity.setPartnerType(partnerType);
    entity.setPartnerGroup(partnerGroup);
    entity.setState(STATE);
    putTestData(DEFAULT_TESTDATA, entity);
    Log.log("TEST", "[" + getClassName() + ".setUp] Exit");
  }
  /**
   * Send the JMS message (under new transaction) with Retry mechanism enable when encounter JMS
   * related error
   *
   * @param destName
   * @param msgObj
   * @param msgProps
   * @param jmsSendProps
   * @param isLocal
   * @throws Throwable
   */
  public static void sendMessage(
      String destName,
      Serializable msgObj,
      Hashtable msgProps,
      Hashtable<String, String> jmsSendProps,
      boolean isLocal)
      throws Throwable {
    boolean isRetryEnabled = _retryCount <= 0 ? false : true;
    int retryCount = _retryCount;
    Throwable th1 = null;

    do {
      try {
        sendJMS(isLocal, jmsSendProps, destName, msgObj, msgProps);
        retryCount = -10;
      } catch (Throwable th) {
        if (isRetryableException(th) && isRetryEnabled) {
          Log.warn(
              Log.FRAMEWORK,
              "sendMessageWithRetry: JMS exception found. Reconnect after "
                  + _sleepFor / 1000
                  + " num retry left: "
                  + retryCount,
              th);

          try {
            Thread.sleep(_sleepFor);
          } catch (Exception ex) {

          }
          Log.debug(Log.FRAMEWORK, "sendMessageWithRetry: JMS exception catched: wake up !");
          th1 = new JMSFailureException(th);

        } else {
          Log.warn(
              Log.FRAMEWORK,
              "sendMessageWithRetry: Non Retryable exception found. No retry will be performed.",
              th);
          throw th;
        }
      }
    } while (retryCount-- > 0);

    if (isRetryEnabled && retryCount == -1 && th1 != null) {
      Log.debug(
          Log.FRAMEWORK,
          "sendMessageWithRetry: JMS retry exhausted. exception is: " + th1.getMessage(),
          th1);
      throw th1;
    }
  }
  /**
   * Send the JMS message (under new transaction) with Retry mechanism enable when encounter JMS
   * related error. If the retry count has exceeded, that JMS will be stored into DB for later
   * retry.
   *
   * @param configName The JMS properties config name
   * @param destName
   * @param msgObj
   * @param msgProps
   * @throws Throwable
   */
  public static void sendMessageWithPersist(
      String configName, String destName, Serializable msgObj, Hashtable msgProps)
      throws Throwable {
    boolean isRetryEnabled = _retryCount <= 0 ? false : true;
    int retryCount = _retryCount;
    Throwable th1 = null;

    do {
      try {
        getJMSMgr().sendMessage(configName, destName, msgObj, msgProps);
        retryCount = -10;
      } catch (Throwable th) {
        if (isRetryableException(th) && isRetryEnabled) {
          Log.warn(
              Log.FRAMEWORK,
              "Send: JMS exception found. Reconnect after "
                  + _sleepFor / 1000
                  + " num retry left: "
                  + retryCount,
              th);

          try {
            Thread.sleep(_sleepFor);
          } catch (Exception ex) {

          }
          Log.debug(Log.FRAMEWORK, "Send: JMS exception catched: wake up !");
          th1 = th;

        } else {
          Log.warn(
              Log.FRAMEWORK,
              "Send: Non Retryable exception found. No retry will be performed.",
              th);
          throw th;
        }
      }
    } while (retryCount-- > 0);

    if (isRetryEnabled && retryCount == -1 && th1 != null) {
      Log.debug(Log.FRAMEWORK, "Send: JMS retry exhausted. exception is: " + th1.getMessage(), th1);
      dumpFailedJMS(
          JMS_DEST_TYPE_QUEUE, getJmsSetupPropsKey(configName), destName, msgObj, msgProps);
    }
  }
  private static void dumpFailedJMS(
      String destType,
      Hashtable<String, String> configProps,
      String destName,
      Serializable msgObj,
      Hashtable msgProps)
      throws Exception {
    JMSFailedMsg failedMsg = new JMSFailedMsg(destType, configProps, destName, msgObj, msgProps);

    // use DB
    try {
      Log.debug(Log.FRAMEWORK, "Persist failed jms to DB. Failed JMS: " + failedMsg);
      JMSFailedMsgHelper helper = JMSFailedMsgHelper.getInstance();
      helper.persistFailedJMSMsg(failedMsg);
    } catch (Exception ex) {
      Log.error("", Log.FRAMEWORK, "Failed to persist the failed jms to DB.", ex);
      throw ex;
    }
  }
  /**
   * Broadcast the JMS msg under a new transaction. It will perform retry if encoutner retryable
   * exception. If exceed the max retry, exception will be propageted up.
   *
   * @param notification
   * @throws Exception
   */
  public static void broadcastInNewTrans(INotification notification) throws Exception {
    boolean isRetryEnabled = _retryCount <= 0 ? false : true;
    int retryCount = _retryCount;
    Exception ex1 = null;

    do {
      try {
        getLocalNotifierMgr().broadCastNotification(notification);
        retryCount = -10;
      } catch (Exception ex) {

        if (isRetryEnabled && isRetryableException(ex)) {
          ex1 = new JMSFailureException(ex);
          Log.warn(
              Log.FRAMEWORK,
              "Broadcast: JMS exception found. Reconnect after "
                  + _sleepFor / 1000
                  + " num retry left: "
                  + retryCount,
              ex);
          try {
            Thread.sleep(_sleepFor);
          } catch (Exception e) {

          }
          Log.debug(Log.FRAMEWORK, "Broadcast: JMS exception catched: wake up !");
        } else {
          Log.warn(
              Log.FRAMEWORK,
              "Broadcast: Non Retryable exception found. No retry will be performed.",
              ex);
          throw ex;
        }
      }
    } while (retryCount-- > 0);

    if (isRetryEnabled && retryCount == -1 && ex1 != null) {
      Log.debug(Log.FRAMEWORK, "Broadcast: JMS retry send exhausted. Throw up ex.", ex1);

      throw ex1;
    }
  }
  private void modifyRegConnInfo() {
    try {
      RegistryConnectInfo info =
          createConnectInfo(
              "TestConn2", "sample/url/publish", "sample/url/query", "testuser", "testpassword");

    } catch (Throwable e) {
      Log.err("TEST", "Error saving RegistryConnInfo", e);
      assertTrue("Error saving RegistryConnInfo", false);
    }
  }
  public void testImport() throws Exception {
    Log.log("TEST", "[DeleteGridDocumentActionTest.testDelete] Enter ");

    createTestData();
    _event = new DeleteGridDocumentEvent(_GDOC_UID);
    //    assertNotNull("event fileType UID is null", _event.getFileTypeUID());
    try {
      _response = performEvent(_event);
    } catch (Exception ex) {
      ex.printStackTrace();
      Log.err("TEST", "[DeleteGridDocumentActionTest.testDelete] Error Exit ", ex);
      assertTrue("Event Exception", false);
    }

    // check response
    assertNotNull("response is null", _response);
    assertTrue("event is not successful", _response.isEventSuccessful());
    assertEquals("Msg code incorrect", IErrorCode.NO_ERROR, _response.getMessageCode());

    Log.log("TEST", "[DeleteGridDocumentActionTest.testDelete] Exit ");
  }
  protected void checkActionEffect(BasicEventResponse response, IEvent event, StateMachine sm) {
    Object retData = response.getReturnData();
    assertNotNull("ReturnData is null", retData);
    assertTrue("ReturnData not instanceof Collection", retData instanceof EntityListResponseData);

    try {
      checkRegConnList((EntityListResponseData) retData, getRegConnInfoList());
    } catch (Throwable t) {
      Log.err("TEST", "GetRegistryConnectInfoListActionTest.checkActionEffect]", t);
      assertTrue("checkActionEffect fail", false);
    }
  }
  /**
   * Add an EntityMetaInfo into the factory. This does not add it to the database. If there is
   * existing EntityMetaInfo cached with the same ObjectName/EntityName, it will be replaced by this
   * metaInfo.
   *
   * @param metaInfo The EntityMetaInfo to add to the factory.
   */
  public void addEntityMetaInfo(EntityMetaInfo metaInfo) {
    _entityMap.put(metaInfo.getObjectName(), metaInfo);

    Log.debug(
        Log.DB,
        "[MetaInfoFactory.addEntityMetaInfo] "
            + "Add mapping for EntityName "
            + metaInfo.getEntityName()
            + " to ObjectName "
            + metaInfo.getObjectName());
    _entityNameMap.put(metaInfo.getEntityName(), metaInfo.getObjectName());
  }
  protected IEvent createTestEvent(IEntity entity) throws Exception {
    _entity = (Partner) entity;
    boolean state = (_entity.getState() == Partner.STATE_ENABLED) ? true : false;

    Log.log("TEST", new Long((_entity.getPartnerType()).getUId()));
    return new CreatePartnerEvent(
        _entity.getPartnerID(),
        _entity.getName(),
        _entity.getDescription(),
        new Long((_entity.getPartnerType()).getUId()),
        new Long((_entity.getPartnerGroup()).getUId()),
        state);
  }
Exemplo n.º 12
0
 /**
  * Call when create() is called on Home. Overwrite to set create time.
  *
  * @param entity The entity to create.
  * @return The primary key of the created entity.
  * @exception CreateException Create failed due to data error.
  * @exception EJBException Create failed due to system service errors.
  * @since 2.0
  */
 public Long ejbCreate(IEntity entity) throws CreateException {
   _entity = entity;
   try {
     checkDuplicate(_entity);
     ((Partner) _entity).setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));
     return getDAO().create(_entity);
   } catch (ApplicationException ex) {
     Log.warn(Log.DB, "[AbstractEntityBean.ejbCreate] Error Exit ", ex);
     throw new CreateException(ex.getLocalizedMessage());
   } catch (Exception ex) {
     throw new EJBException(ex);
   }
 }
  protected void setUp() throws java.lang.Exception {
    Log.log("TEST", "[DeleteGridDocumentActionTest.setUp] Enter");

    _sessionHome =
        (ISessionManagerHome)
            ServiceLookup.getInstance(ServiceLookup.CLIENT_CONTEXT)
                .getHome(ISessionManagerHome.class);
    assertNotNull("SessionHome is null", _sessionHome);
    _sessionRemote = _sessionHome.create();
    assertNotNull("SessionRemote is null", _sessionRemote);
    _sessionID = _sessionRemote.openSession();
    _sessionRemote.authSession(_sessionID, _userID);

    _home =
        (IDocumentManagerHome)
            ServiceLookup.getInstance(ServiceLookup.CLIENT_CONTEXT)
                .getHome(IDocumentManagerHome.class);
    assertNotNull("Home is null", _home);
    _remote = _home.create();
    assertNotNull("remote is null", _remote);

    Log.log("TEST", "[DeleteGridDocumentActionTest.setUp] Exit");
  }
 private static void sendJMS(
     boolean isLocal,
     Hashtable jmsSendProps,
     String destName,
     Serializable msgObj,
     Hashtable<String, String> msgProps)
     throws Exception {
   Log.debug(Log.FRAMEWORK, "sendJMS: isRemote:" + isLocal);
   if (!isLocal) {
     getRemoteJMSMgr().sendMessage(jmsSendProps, destName, msgObj, msgProps);
   } else {
     getJMSMgr().sendMessage(jmsSendProps, destName, msgObj, msgProps);
   }
 }
 private void loadConfig() {
   try {
     Configuration dbConfig =
         ConfigurationManager.getInstance().getConfig(IFrameworkConfig.FRAMEWORK_DATABASE_CONFIG);
     _useEntityBean = dbConfig.getBoolean(IFrameworkConfig.CMP_ON, true);
   } catch (Exception ex) {
     Log.error(
         ILogErrorCodes.CONFIGURATION_LOAD,
         Log.DB,
         "[MetaInfoFactory.loadConfig] Unable to load config. Setting cmp.on to true. Unexpected error: "
             + ex.getMessage(),
         ex);
   }
 }
  static {
    Configuration config = ConfigurationManager.getInstance().getConfig(FRAMEWORK_JMS_CONFIG);

    _retryCount = config.getInt(JMS_NUM_RETRY, 10);
    _sleepFor =
        config.getLong(JMS_RETRY_INTERVAL) == 0L ? 10000 : config.getLong(JMS_RETRY_INTERVAL);
    _isSendViaDefMode = config.getBoolean(JMS_DEF_SEND, true);

    Log.log(
        Log.FRAMEWORK,
        " Retrieve jms props from "
            + FRAMEWORK_JMS_CONFIG
            + " --> JMS Sending mode: "
            + (_isSendViaDefMode ? "Default" : "With Retry")
            + "Retry Count: "
            + _retryCount
            + " retry interval: "
            + _sleepFor
            + " ms");
  }
  private static Hashtable<String, String> getJmsSetupPropsKey(String configName)
      throws ApplicationException {
    Configuration config = ConfigurationManager.getInstance().getConfig(configName);
    Properties prop = config.getProperties();
    Log.debug(Log.FRAMEWORK, "getJmsSetupPropsKey: " + prop);

    if (prop != null && prop.size() == 0) {
      throw new ApplicationException(
          "No properties file can be found given configName: " + configName);
    }

    Hashtable<String, String> configProps = new Hashtable<String, String>();
    Enumeration keys = prop.propertyNames();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      configProps.put(key, (String) prop.get(key));
    }

    return configProps;
  }
  /**
   * Load the EntityMetaInfo from the database and cache it.
   *
   * @param objectName Full qualified class name of the Entity to load EntityMetaInfo for.
   */
  private EntityMetaInfo loadEntityMetaInfoByObjectName(String objectName) {
    EntityMetaInfo emi = null;

    try {
      if (_useEntityBean) {
        emi = getEntityMetaInfoHome().findByPrimaryKey(objectName).getData();
      } else {
        emi = getMetaInfoObj().findByObjectName(objectName);
      }

      addEntityMetaInfo(emi);
    } catch (Throwable t) {
      Log.error(
          ILogErrorCodes.ENTITY_META_INFO_READ,
          Log.DB,
          "[MetaInfoFactory.loadEntityMetaInfoByObjectName] Error ",
          t);
    }

    return emi;
  }
 /**
  * Retrieve the fieldmetainfos with the specified label
  *
  * @param label The label
  * @return Collection of FieldMetaInfo objects found.
  */
 public Collection getFieldMetaInfoByLabel(String label) {
   Collection fmi = null;
   try {
     if (_useEntityBean) {
       Collection results = getFieldMetaInfoHome().findByLabel(label);
       fmi = new ArrayList();
       for (Iterator i = results.iterator(); i.hasNext(); ) {
         fmi.add(((IFieldMetaInfoLocalObj) i.next()).getData());
       }
     } else {
       fmi = getMetaInfoObj().findFieldMetaInfoByLabel(label);
     }
   } catch (Exception ex) {
     Log.error(
         ILogErrorCodes.FIELD_META_INFO_RETRIEVE,
         Log.DB,
         "[MetaInfoFactory.getFieldMetaInfoByLabel] Error ",
         ex);
   }
   return fmi;
 }
Exemplo n.º 20
0
 /**
  * @deprecated Use error(String, Object)
  * @see Logger#error(String, Object)
  * @param msg
  */
 public static void err(Throwable ex) {
   Log.err(CATEGORY, "", ex);
 }
Exemplo n.º 21
0
 /**
  * Log an error message with the specified error code and <code>Throwable</code> object of origin
  *
  * @see com.gridnode.pdip.app.mapper.exception.ILogErrorCodes
  * @param errorCode The error code
  * @param msg The error message
  * @param t The <code>Throwable</code> object of origin
  */
 public static void error(String errorCode, String msg, Throwable t) {
   Log.error(errorCode, CATEGORY, msg, t);
 }
Exemplo n.º 22
0
 /**
  * Log an error message with the specified error code
  *
  * @see com.gridnode.pdip.app.mapper.exception.ILogErrorCodes
  * @param errorCode
  * @param msg
  */
 public static void error(String errorCode, Object msg) {
   Log.error(errorCode, CATEGORY, msg);
 }
Exemplo n.º 23
0
 /**
  * @deprecated Use error(String,String,Throwable)
  * @param msg
  * @param ex
  */
 public static void err(String msg, Throwable ex) {
   Log.err(CATEGORY, msg, ex);
 }
Exemplo n.º 24
0
 /**
  * @deprecated Use error(String, Object)
  * @see Logger#error(String, Object)
  * @param msg
  */
 public static void err(Object msg) {
   Log.err(CATEGORY, msg);
 }
Exemplo n.º 25
0
 /**
  * Log a warning message with the specified category and <code>Throwable</code> object of origin
  *
  * @param msg The warning message
  * @param ex The <code>Throwable</code> object of origin
  * @since GT 4.0 VAN
  * @version GT 4.0 VAN
  */
 public static void warn(String msg, Throwable ex) {
   Log.warn(CATEGORY, msg, ex);
 }
Exemplo n.º 26
0
 /**
  * Log a warning message with the specified category
  *
  * @param msg The warning message
  * @since GT 4.0 VAN
  * @version GT 4.0 VAN
  */
 public static void warn(Object msg) {
   Log.warn(CATEGORY, msg);
 }
Exemplo n.º 27
0
 public static void debug(String msg, Throwable ex) {
   Log.debug(CATEGORY, msg, ex);
 }
Exemplo n.º 28
0
 public static void debug(Object msg) {
   Log.debug(CATEGORY, msg);
 }
Exemplo n.º 29
0
 public static void log(Object msg) {
   Log.log(CATEGORY, msg);
 }
Exemplo n.º 30
0
 /**
  * @deprecated Use error(String, Object)
  * @see Logger#error(String, Object)
  * @param msg
  */
 public static void err(String msg) {
   Log.err(CATEGORY, msg);
 }