Example #1
0
  private boolean checkJMSConnection(ServiceTaskManager stm) {

    Connection connection = null;
    Hashtable<String, String> jmsProperties = stm.getJmsProperties();
    try {
      ConnectionFactory jmsConFactory = null;
      try {
        jmsConFactory =
            JMSUtils.lookup(
                new InitialContext(stm.getJmsProperties()),
                ConnectionFactory.class,
                stm.getConnFactoryJNDIName());
      } catch (NamingException e) {
        log.error(
            "Error looking up connection factory : "
                + stm.getConnFactoryJNDIName()
                + "using JNDI properties : "
                + jmsProperties,
            e);
      }
      connection =
          JMSUtils.createConnection(
              jmsConFactory,
              jmsProperties.get(JMSConstants.PARAM_JMS_USERNAME),
              jmsProperties.get(JMSConstants.PARAM_JMS_PASSWORD),
              stm.isJmsSpec11(),
              null,
              false,
              "");
    } catch (JMSException ignore) {
    } // we silently ignore this as a JMSException can be expected when connection is not available

    return (connection != null);
  }
  /**
   * Get the referenced ConnectionFactory using the properties from the context
   *
   * @param context the context to use for lookup
   * @param props the properties which contains the JNDI name of the factory
   * @return the connection factory
   */
  private ConnectionFactory getConnectionFactory(Context context, Hashtable<String, String> props) {
    try {

      String conFacJndiName = props.get(JMSConstants.PARAM_CONFAC_JNDI_NAME);
      if (conFacJndiName != null) {
        return JMSUtils.lookup(context, ConnectionFactory.class, conFacJndiName);
      } else {
        handleException("Connection Factory JNDI name cannot be determined");
      }
    } catch (NamingException e) {
      handleException("Failed to look up connection factory from JNDI", e);
    }
    return null;
  }